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" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 21 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 22 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 23 | #include "intrinsics.h" |
| 24 | #include "intrinsics_x86_64.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 25 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 26 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 27 | #include "mirror/object_reference.h" |
| 28 | #include "thread.h" |
| 29 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 30 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 31 | #include "utils/x86_64/assembler_x86_64.h" |
| 32 | #include "utils/x86_64/managed_register_x86_64.h" |
| 33 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 34 | namespace art { |
| 35 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 36 | namespace x86_64 { |
| 37 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 38 | // Some x86_64 instructions require a register to be available as temp. |
| 39 | static constexpr Register TMP = R11; |
| 40 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 41 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 42 | static constexpr Register kMethodRegisterArgument = RDI; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 43 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 44 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 45 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 46 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 47 | static constexpr int kC2ConditionMask = 0x400; |
| 48 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 49 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 50 | #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] | 51 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 52 | class NullCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 54 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 56 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 57 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 59 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 60 | instruction_, |
| 61 | instruction_->GetDexPc(), |
| 62 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 65 | bool IsFatal() const OVERRIDE { return true; } |
| 66 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 67 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 68 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 70 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 72 | }; |
| 73 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 74 | class DivZeroCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 75 | public: |
| 76 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 77 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 78 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 79 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 80 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 82 | instruction_, |
| 83 | instruction_->GetDexPc(), |
| 84 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 87 | bool IsFatal() const OVERRIDE { return true; } |
| 88 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 89 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 90 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | private: |
| 92 | HDivZeroCheck* const instruction_; |
| 93 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 94 | }; |
| 95 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 96 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCodeX86_64 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame^] | 98 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 99 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 101 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 103 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 104 | if (is_div_) { |
| 105 | __ negl(cpu_reg_); |
| 106 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 107 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 110 | } else { |
| 111 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 112 | if (is_div_) { |
| 113 | __ negq(cpu_reg_); |
| 114 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 115 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 116 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 117 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | __ jmp(GetExitLabel()); |
| 119 | } |
| 120 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 121 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 122 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 124 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 125 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 126 | const bool is_div_; |
| 127 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 130 | class SuspendCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 131 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame^] | 132 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 133 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 134 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 135 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 136 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 137 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 138 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 139 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 140 | instruction_, |
| 141 | instruction_->GetDexPc(), |
| 142 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 143 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 144 | if (successor_ == nullptr) { |
| 145 | __ jmp(GetReturnLabel()); |
| 146 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 147 | __ jmp(x64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 148 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 151 | Label* GetReturnLabel() { |
| 152 | DCHECK(successor_ == nullptr); |
| 153 | return &return_label_; |
| 154 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 155 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 156 | HBasicBlock* GetSuccessor() const { |
| 157 | return successor_; |
| 158 | } |
| 159 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 160 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 161 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 162 | private: |
| 163 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 164 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 165 | Label return_label_; |
| 166 | |
| 167 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 168 | }; |
| 169 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 170 | class BoundsCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 171 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 172 | BoundsCheckSlowPathX86_64(HBoundsCheck* instruction, |
| 173 | Location index_location, |
| 174 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 175 | : instruction_(instruction), |
| 176 | index_location_(index_location), |
| 177 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 178 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 179 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 180 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 181 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 182 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 183 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 185 | codegen->EmitParallelMoves( |
| 186 | index_location_, |
| 187 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 188 | Primitive::kPrimInt, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 189 | length_location_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 190 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 191 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 192 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 193 | instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 194 | } |
| 195 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 196 | bool IsFatal() const OVERRIDE { return true; } |
| 197 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 198 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 199 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 200 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 201 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 202 | const Location index_location_; |
| 203 | const Location length_location_; |
| 204 | |
| 205 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 206 | }; |
| 207 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 208 | class LoadClassSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 209 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 210 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 211 | HInstruction* at, |
| 212 | uint32_t dex_pc, |
| 213 | bool do_clinit) |
| 214 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 215 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 216 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 217 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 218 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 219 | LocationSummary* locations = at_->GetLocations(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 220 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 221 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 222 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 223 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 225 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 226 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 227 | x64_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 228 | : QUICK_ENTRY_POINT(pInitializeType), |
| 229 | at_, dex_pc_, this); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 230 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 231 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 232 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 233 | if (out.IsValid()) { |
| 234 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 235 | x64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 238 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 239 | __ jmp(GetExitLabel()); |
| 240 | } |
| 241 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 242 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 243 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 244 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 245 | // The class this slow path will load. |
| 246 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 247 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 248 | // The instruction where this slow path is happening. |
| 249 | // (Might be the load class or an initialization check). |
| 250 | HInstruction* const at_; |
| 251 | |
| 252 | // The dex PC of `at_`. |
| 253 | const uint32_t dex_pc_; |
| 254 | |
| 255 | // Whether to initialize the class. |
| 256 | const bool do_clinit_; |
| 257 | |
| 258 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 259 | }; |
| 260 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 261 | class LoadStringSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 262 | public: |
| 263 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 264 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 265 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 266 | LocationSummary* locations = instruction_->GetLocations(); |
| 267 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 268 | |
| 269 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 270 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 271 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 272 | |
| 273 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 274 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 275 | Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 276 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 277 | instruction_, |
| 278 | instruction_->GetDexPc(), |
| 279 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 280 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 281 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 282 | __ jmp(GetExitLabel()); |
| 283 | } |
| 284 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 285 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 286 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 287 | private: |
| 288 | HLoadString* const instruction_; |
| 289 | |
| 290 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 291 | }; |
| 292 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 293 | class TypeCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 294 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 295 | TypeCheckSlowPathX86_64(HInstruction* instruction, |
| 296 | Location class_to_check, |
| 297 | Location object_class, |
| 298 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 300 | class_to_check_(class_to_check), |
| 301 | object_class_(object_class), |
| 302 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 303 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 304 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 306 | DCHECK(instruction_->IsCheckCast() |
| 307 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 308 | |
| 309 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 310 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 311 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | |
| 313 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 314 | // move resolver. |
| 315 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 316 | codegen->EmitParallelMoves( |
| 317 | class_to_check_, |
| 318 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 319 | Primitive::kPrimNot, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 320 | object_class_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 321 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 322 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 323 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 324 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 325 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 326 | instruction_, |
| 327 | dex_pc_, |
| 328 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 329 | } else { |
| 330 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 331 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 332 | instruction_, |
| 333 | dex_pc_, |
| 334 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 335 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 336 | |
| 337 | if (instruction_->IsInstanceOf()) { |
| 338 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 339 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 341 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | __ jmp(GetExitLabel()); |
| 343 | } |
| 344 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 345 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 346 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 347 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 348 | HInstruction* const instruction_; |
| 349 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 350 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 351 | const uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 352 | |
| 353 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 354 | }; |
| 355 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 356 | class DeoptimizationSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 357 | public: |
| 358 | explicit DeoptimizationSlowPathX86_64(HInstruction* instruction) |
| 359 | : instruction_(instruction) {} |
| 360 | |
| 361 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 362 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 363 | __ Bind(GetEntryLabel()); |
| 364 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 365 | DCHECK(instruction_->IsDeoptimize()); |
| 366 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 367 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 368 | deoptimize, |
| 369 | deoptimize->GetDexPc(), |
| 370 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 373 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 374 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 375 | private: |
| 376 | HInstruction* const instruction_; |
| 377 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 378 | }; |
| 379 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 380 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 381 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 382 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 383 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 384 | switch (cond) { |
| 385 | case kCondEQ: return kEqual; |
| 386 | case kCondNE: return kNotEqual; |
| 387 | case kCondLT: return kLess; |
| 388 | case kCondLE: return kLessEqual; |
| 389 | case kCondGT: return kGreater; |
| 390 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 391 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 392 | LOG(FATAL) << "Unreachable"; |
| 393 | UNREACHABLE(); |
| 394 | } |
| 395 | |
| 396 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 397 | switch (cond) { |
| 398 | case kCondEQ: return kEqual; |
| 399 | case kCondNE: return kNotEqual; |
| 400 | case kCondLT: return kBelow; |
| 401 | case kCondLE: return kBelowEqual; |
| 402 | case kCondGT: return kAbove; |
| 403 | case kCondGE: return kAboveEqual; |
| 404 | }; |
| 405 | LOG(FATAL) << "Unreachable"; |
| 406 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 409 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 410 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 411 | // All registers are assumed to be correctly set up. |
| 412 | |
| 413 | // TODO: Implement all kinds of calls: |
| 414 | // 1) boot -> boot |
| 415 | // 2) app -> boot |
| 416 | // 3) app -> app |
| 417 | // |
| 418 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 419 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 420 | if (invoke->IsStringInit()) { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 421 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 422 | // temp = thread->string_init_entrypoint |
Jeff Hao | cad6542 | 2015-06-18 21:16:08 -0700 | [diff] [blame] | 423 | __ gs()->movq(reg, Address::Absolute(invoke->GetStringInitOffset(), true)); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 424 | // (temp + offset_of_quick_compiled_code)() |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 425 | __ call(Address(reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 426 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 427 | } else if (invoke->IsRecursive()) { |
| 428 | __ call(&frame_entry_label_); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 429 | } else { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 430 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 431 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 432 | Register method_reg; |
| 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 | } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 441 | // temp = temp->dex_cache_resolved_methods_; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 442 | __ movl(reg, Address(CpuRegister(method_reg), |
| 443 | ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 444 | // temp = temp[index_in_cache] |
| 445 | __ movq(reg, Address( |
| 446 | reg, CodeGenerator::GetCachePointerOffset(invoke->GetDexMethodIndex()))); |
| 447 | // (temp + offset_of_quick_compiled_code)() |
| 448 | __ call(Address(reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 449 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 450 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 451 | |
| 452 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 455 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 456 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 460 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 463 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 464 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 465 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 466 | } |
| 467 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 468 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 469 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 470 | return kX86_64WordSize; |
| 471 | } |
| 472 | |
| 473 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 474 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 475 | return kX86_64WordSize; |
| 476 | } |
| 477 | |
| 478 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 479 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 480 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 483 | void CodeGeneratorX86_64::InvokeRuntime(Address entry_point, |
| 484 | HInstruction* instruction, |
| 485 | uint32_t dex_pc, |
| 486 | SlowPathCode* slow_path) { |
| 487 | // Ensure that the call kind indication given to the register allocator is |
| 488 | // coherent with the runtime call generated. |
| 489 | if (slow_path == nullptr) { |
| 490 | DCHECK(instruction->GetLocations()->WillCall()); |
| 491 | } else { |
| 492 | DCHECK(instruction->GetLocations()->OnlyCallsOnSlowPath() || slow_path->IsFatal()); |
| 493 | } |
| 494 | |
| 495 | __ gs()->call(entry_point); |
| 496 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 497 | DCHECK(instruction->IsSuspendCheck() |
| 498 | || instruction->IsBoundsCheck() |
| 499 | || instruction->IsNullCheck() |
| 500 | || instruction->IsDivZeroCheck() |
| 501 | || !IsLeafMethod()); |
| 502 | } |
| 503 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 504 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 505 | // Use a fake return address register to mimic Quick. |
| 506 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 507 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| 508 | const X86_64InstructionSetFeatures& isa_features, |
| 509 | const CompilerOptions& compiler_options) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 510 | : CodeGenerator(graph, |
| 511 | kNumberOfCpuRegisters, |
| 512 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 513 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 514 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 515 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 516 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 517 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 518 | arraysize(kFpuCalleeSaves)), |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 519 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 520 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 521 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 522 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 523 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 524 | isa_features_(isa_features), |
| 525 | constant_area_start_(0) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 526 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 527 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 528 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 529 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 530 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 531 | : HGraphVisitor(graph), |
| 532 | assembler_(codegen->GetAssembler()), |
| 533 | codegen_(codegen) {} |
| 534 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 535 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 536 | switch (type) { |
| 537 | case Primitive::kPrimLong: |
| 538 | case Primitive::kPrimByte: |
| 539 | case Primitive::kPrimBoolean: |
| 540 | case Primitive::kPrimChar: |
| 541 | case Primitive::kPrimShort: |
| 542 | case Primitive::kPrimInt: |
| 543 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 544 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 545 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 549 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 550 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 551 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 552 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 553 | |
| 554 | case Primitive::kPrimVoid: |
| 555 | LOG(FATAL) << "Unreachable type " << type; |
| 556 | } |
| 557 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 558 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 559 | } |
| 560 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 561 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 562 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 563 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 564 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 565 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 566 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 567 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 568 | if (is_baseline) { |
| 569 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 570 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 571 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 572 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 573 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 574 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 575 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 576 | } |
| 577 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 578 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 579 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 580 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 581 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 582 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 583 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 584 | } |
| 585 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 586 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 587 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 588 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 589 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 590 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 591 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 592 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 593 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 594 | __ testq(CpuRegister(RAX), Address( |
| 595 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 596 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 597 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 598 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 599 | if (HasEmptyFrame()) { |
| 600 | return; |
| 601 | } |
| 602 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 603 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 604 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 605 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 606 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 607 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 608 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 609 | } |
| 610 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 611 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 612 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 613 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 614 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 615 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 616 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 617 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 618 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 619 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 620 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 621 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 622 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 623 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 624 | } |
| 625 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 626 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 627 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 631 | __ cfi().RememberState(); |
| 632 | if (!HasEmptyFrame()) { |
| 633 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 634 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 635 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 636 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 637 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 638 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 639 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 644 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 645 | __ cfi().AdjustCFAOffset(-adjust); |
| 646 | |
| 647 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 648 | Register reg = kCoreCalleeSaves[i]; |
| 649 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 650 | __ popq(CpuRegister(reg)); |
| 651 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 652 | __ cfi().Restore(DWARFReg(reg)); |
| 653 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 654 | } |
| 655 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 656 | __ ret(); |
| 657 | __ cfi().RestoreState(); |
| 658 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 659 | } |
| 660 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 661 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 662 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 663 | } |
| 664 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 665 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 666 | switch (load->GetType()) { |
| 667 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 668 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 669 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 670 | |
| 671 | case Primitive::kPrimInt: |
| 672 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 673 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 674 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 675 | |
| 676 | case Primitive::kPrimBoolean: |
| 677 | case Primitive::kPrimByte: |
| 678 | case Primitive::kPrimChar: |
| 679 | case Primitive::kPrimShort: |
| 680 | case Primitive::kPrimVoid: |
| 681 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 682 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 686 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 690 | if (source.Equals(destination)) { |
| 691 | return; |
| 692 | } |
| 693 | if (destination.IsRegister()) { |
| 694 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 695 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 696 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 697 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 698 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 699 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 700 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 701 | } else { |
| 702 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 703 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 704 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 705 | } |
| 706 | } else if (destination.IsFpuRegister()) { |
| 707 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 708 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 709 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 710 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 711 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 712 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 713 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 714 | } else { |
| 715 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 716 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 717 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 718 | } |
| 719 | } else if (destination.IsStackSlot()) { |
| 720 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 721 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 722 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 723 | } else if (source.IsFpuRegister()) { |
| 724 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 725 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 726 | } else if (source.IsConstant()) { |
| 727 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 728 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 729 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 730 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 731 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 732 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 733 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 734 | } |
| 735 | } else { |
| 736 | DCHECK(destination.IsDoubleStackSlot()); |
| 737 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 738 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 739 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 740 | } else if (source.IsFpuRegister()) { |
| 741 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 742 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 743 | } else if (source.IsConstant()) { |
| 744 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 745 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 746 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 747 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 748 | } else { |
| 749 | DCHECK(constant->IsLongConstant()); |
| 750 | value = constant->AsLongConstant()->GetValue(); |
| 751 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 752 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 753 | } else { |
| 754 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 755 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 756 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 761 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 762 | Location location, |
| 763 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 764 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 765 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 766 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 767 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 768 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 769 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 770 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 771 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 772 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 773 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 774 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 775 | } else if (location.IsStackSlot()) { |
| 776 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 777 | } else { |
| 778 | DCHECK(location.IsConstant()); |
| 779 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 780 | } |
| 781 | } else if (const_to_move->IsLongConstant()) { |
| 782 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 783 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 784 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 785 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 786 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 787 | } else { |
| 788 | DCHECK(location.IsConstant()); |
| 789 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 790 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 791 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 792 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 793 | switch (instruction->GetType()) { |
| 794 | case Primitive::kPrimBoolean: |
| 795 | case Primitive::kPrimByte: |
| 796 | case Primitive::kPrimChar: |
| 797 | case Primitive::kPrimShort: |
| 798 | case Primitive::kPrimInt: |
| 799 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 800 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 801 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 802 | break; |
| 803 | |
| 804 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 805 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 806 | Move(location, |
| 807 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 808 | break; |
| 809 | |
| 810 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 811 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 812 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 813 | } else if (instruction->IsTemporary()) { |
| 814 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 815 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 816 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 817 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 818 | switch (instruction->GetType()) { |
| 819 | case Primitive::kPrimBoolean: |
| 820 | case Primitive::kPrimByte: |
| 821 | case Primitive::kPrimChar: |
| 822 | case Primitive::kPrimShort: |
| 823 | case Primitive::kPrimInt: |
| 824 | case Primitive::kPrimNot: |
| 825 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 826 | case Primitive::kPrimFloat: |
| 827 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 828 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 829 | break; |
| 830 | |
| 831 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 832 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 837 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 838 | DCHECK(!successor->IsExitBlock()); |
| 839 | |
| 840 | HBasicBlock* block = got->GetBlock(); |
| 841 | HInstruction* previous = got->GetPrevious(); |
| 842 | |
| 843 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 844 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 845 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 846 | return; |
| 847 | } |
| 848 | |
| 849 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 850 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 851 | } |
| 852 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 853 | __ jmp(codegen_->GetLabelOf(successor)); |
| 854 | } |
| 855 | } |
| 856 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 857 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 858 | got->SetLocations(nullptr); |
| 859 | } |
| 860 | |
| 861 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 862 | HandleGoto(got, got->GetSuccessor()); |
| 863 | } |
| 864 | |
| 865 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 866 | try_boundary->SetLocations(nullptr); |
| 867 | } |
| 868 | |
| 869 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 870 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 871 | if (!successor->IsExitBlock()) { |
| 872 | HandleGoto(try_boundary, successor); |
| 873 | } |
| 874 | } |
| 875 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 876 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 877 | exit->SetLocations(nullptr); |
| 878 | } |
| 879 | |
| 880 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 881 | UNUSED(exit); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 882 | } |
| 883 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 884 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 885 | Label* true_label, |
| 886 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 887 | if (cond->IsFPConditionTrueIfNaN()) { |
| 888 | __ j(kUnordered, true_label); |
| 889 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 890 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 891 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 892 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HIf* if_instr, |
| 896 | HCondition* condition, |
| 897 | Label* true_target, |
| 898 | Label* false_target, |
| 899 | Label* always_true_target) { |
| 900 | LocationSummary* locations = condition->GetLocations(); |
| 901 | Location left = locations->InAt(0); |
| 902 | Location right = locations->InAt(1); |
| 903 | |
| 904 | // We don't want true_target as a nullptr. |
| 905 | if (true_target == nullptr) { |
| 906 | true_target = always_true_target; |
| 907 | } |
| 908 | bool falls_through = (false_target == nullptr); |
| 909 | |
| 910 | // FP compares don't like null false_targets. |
| 911 | if (false_target == nullptr) { |
| 912 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 913 | } |
| 914 | |
| 915 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 916 | switch (type) { |
| 917 | case Primitive::kPrimLong: { |
| 918 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 919 | if (right.IsConstant()) { |
| 920 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 921 | if (IsInt<32>(value)) { |
| 922 | if (value == 0) { |
| 923 | __ testq(left_reg, left_reg); |
| 924 | } else { |
| 925 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 926 | } |
| 927 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 928 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 929 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 930 | } |
| 931 | } else if (right.IsDoubleStackSlot()) { |
| 932 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 933 | } else { |
| 934 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 935 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 936 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 937 | break; |
| 938 | } |
| 939 | case Primitive::kPrimFloat: { |
| 940 | if (right.IsFpuRegister()) { |
| 941 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 942 | } else if (right.IsConstant()) { |
| 943 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 944 | codegen_->LiteralFloatAddress( |
| 945 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 946 | } else { |
| 947 | DCHECK(right.IsStackSlot()); |
| 948 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 949 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 950 | } |
| 951 | GenerateFPJumps(condition, true_target, false_target); |
| 952 | break; |
| 953 | } |
| 954 | case Primitive::kPrimDouble: { |
| 955 | if (right.IsFpuRegister()) { |
| 956 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 957 | } else if (right.IsConstant()) { |
| 958 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 959 | codegen_->LiteralDoubleAddress( |
| 960 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 961 | } else { |
| 962 | DCHECK(right.IsDoubleStackSlot()); |
| 963 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 964 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 965 | } |
| 966 | GenerateFPJumps(condition, true_target, false_target); |
| 967 | break; |
| 968 | } |
| 969 | default: |
| 970 | LOG(FATAL) << "Unexpected condition type " << type; |
| 971 | } |
| 972 | |
| 973 | if (!falls_through) { |
| 974 | __ jmp(false_target); |
| 975 | } |
| 976 | } |
| 977 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 978 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| 979 | Label* true_target, |
| 980 | Label* false_target, |
| 981 | Label* always_true_target) { |
| 982 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 983 | if (cond->IsIntConstant()) { |
| 984 | // Constant condition, statically compared against 1. |
| 985 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 986 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 987 | if (always_true_target != nullptr) { |
| 988 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 989 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 990 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 991 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 992 | DCHECK_EQ(cond_value, 0); |
| 993 | } |
| 994 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 995 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 996 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 997 | // Moves do not affect the eflags register, so if the condition is |
| 998 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 999 | // again. We can't use the eflags on FP conditions if they are |
| 1000 | // materialized due to the complex branching. |
| 1001 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1002 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1003 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
| 1004 | && !Primitive::IsFloatingPointType(type); |
| 1005 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1006 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1007 | if (!eflags_set) { |
| 1008 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1009 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1010 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1011 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1012 | } else { |
| 1013 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 1014 | Immediate(0)); |
| 1015 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1016 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1017 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1018 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1019 | } |
| 1020 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1021 | // Condition has not been materialized, use its inputs as the |
| 1022 | // comparison and its condition as the branch condition. |
| 1023 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1024 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1025 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1026 | // Generate the comparison directly. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1027 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1028 | true_target, false_target, always_true_target); |
| 1029 | return; |
| 1030 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1031 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1032 | Location lhs = cond->GetLocations()->InAt(0); |
| 1033 | Location rhs = cond->GetLocations()->InAt(1); |
| 1034 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1035 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1036 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1037 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1038 | if (constant == 0) { |
| 1039 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1040 | } else { |
| 1041 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1042 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1043 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1044 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1045 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1046 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1047 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1048 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1049 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1050 | if (false_target != nullptr) { |
| 1051 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1055 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| 1056 | LocationSummary* locations = |
| 1057 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1058 | HInstruction* cond = if_instr->InputAt(0); |
| 1059 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1060 | locations->SetInAt(0, Location::Any()); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| 1065 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1066 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1067 | Label* always_true_target = true_target; |
| 1068 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1069 | if_instr->IfTrueSuccessor())) { |
| 1070 | always_true_target = nullptr; |
| 1071 | } |
| 1072 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1073 | if_instr->IfFalseSuccessor())) { |
| 1074 | false_target = nullptr; |
| 1075 | } |
| 1076 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1077 | } |
| 1078 | |
| 1079 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1080 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1081 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1082 | HInstruction* cond = deoptimize->InputAt(0); |
| 1083 | DCHECK(cond->IsCondition()); |
| 1084 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1085 | locations->SetInAt(0, Location::Any()); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1090 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) |
| 1091 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1092 | codegen_->AddSlowPath(slow_path); |
| 1093 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1094 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1095 | } |
| 1096 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1097 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1098 | local->SetLocations(nullptr); |
| 1099 | } |
| 1100 | |
| 1101 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1102 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1103 | } |
| 1104 | |
| 1105 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1106 | local->SetLocations(nullptr); |
| 1107 | } |
| 1108 | |
| 1109 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 1110 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1111 | UNUSED(load); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1115 | LocationSummary* locations = |
| 1116 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1117 | switch (store->InputAt(1)->GetType()) { |
| 1118 | case Primitive::kPrimBoolean: |
| 1119 | case Primitive::kPrimByte: |
| 1120 | case Primitive::kPrimChar: |
| 1121 | case Primitive::kPrimShort: |
| 1122 | case Primitive::kPrimInt: |
| 1123 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1124 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1125 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1126 | break; |
| 1127 | |
| 1128 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1129 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1130 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1131 | break; |
| 1132 | |
| 1133 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1134 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1135 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1139 | UNUSED(store); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1140 | } |
| 1141 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1142 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1143 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1144 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1145 | // Handle the long/FP comparisons made in instruction simplification. |
| 1146 | switch (cond->InputAt(0)->GetType()) { |
| 1147 | case Primitive::kPrimLong: |
| 1148 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1149 | locations->SetInAt(1, Location::Any()); |
| 1150 | break; |
| 1151 | case Primitive::kPrimFloat: |
| 1152 | case Primitive::kPrimDouble: |
| 1153 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1154 | locations->SetInAt(1, Location::Any()); |
| 1155 | break; |
| 1156 | default: |
| 1157 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1158 | locations->SetInAt(1, Location::Any()); |
| 1159 | break; |
| 1160 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1161 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1162 | locations->SetOut(Location::RequiresRegister()); |
| 1163 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1164 | } |
| 1165 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1166 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1167 | if (!cond->NeedsMaterialization()) { |
| 1168 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1169 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1170 | |
| 1171 | LocationSummary* locations = cond->GetLocations(); |
| 1172 | Location lhs = locations->InAt(0); |
| 1173 | Location rhs = locations->InAt(1); |
| 1174 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1175 | Label true_label, false_label; |
| 1176 | |
| 1177 | switch (cond->InputAt(0)->GetType()) { |
| 1178 | default: |
| 1179 | // Integer case. |
| 1180 | |
| 1181 | // Clear output register: setcc only sets the low byte. |
| 1182 | __ xorl(reg, reg); |
| 1183 | |
| 1184 | if (rhs.IsRegister()) { |
| 1185 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1186 | } else if (rhs.IsConstant()) { |
| 1187 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1188 | if (constant == 0) { |
| 1189 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1190 | } else { |
| 1191 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1192 | } |
| 1193 | } else { |
| 1194 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1195 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1196 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1197 | return; |
| 1198 | case Primitive::kPrimLong: |
| 1199 | // Clear output register: setcc only sets the low byte. |
| 1200 | __ xorl(reg, reg); |
| 1201 | |
| 1202 | if (rhs.IsRegister()) { |
| 1203 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1204 | } else if (rhs.IsConstant()) { |
| 1205 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1206 | if (IsInt<32>(value)) { |
| 1207 | if (value == 0) { |
| 1208 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1209 | } else { |
| 1210 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1211 | } |
| 1212 | } else { |
| 1213 | // Value won't fit in an int. |
| 1214 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1215 | } |
| 1216 | } else { |
| 1217 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1218 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1219 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1220 | return; |
| 1221 | case Primitive::kPrimFloat: { |
| 1222 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1223 | if (rhs.IsConstant()) { |
| 1224 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1225 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1226 | } else if (rhs.IsStackSlot()) { |
| 1227 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1228 | } else { |
| 1229 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1230 | } |
| 1231 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1232 | break; |
| 1233 | } |
| 1234 | case Primitive::kPrimDouble: { |
| 1235 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1236 | if (rhs.IsConstant()) { |
| 1237 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1238 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1239 | } else if (rhs.IsDoubleStackSlot()) { |
| 1240 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1241 | } else { |
| 1242 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1243 | } |
| 1244 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1245 | break; |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | // Convert the jumps into the result. |
| 1250 | Label done_label; |
| 1251 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1252 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1253 | __ Bind(&false_label); |
| 1254 | __ xorl(reg, reg); |
| 1255 | __ jmp(&done_label); |
| 1256 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1257 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1258 | __ Bind(&true_label); |
| 1259 | __ movl(reg, Immediate(1)); |
| 1260 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1264 | VisitCondition(comp); |
| 1265 | } |
| 1266 | |
| 1267 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1268 | VisitCondition(comp); |
| 1269 | } |
| 1270 | |
| 1271 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1272 | VisitCondition(comp); |
| 1273 | } |
| 1274 | |
| 1275 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1276 | VisitCondition(comp); |
| 1277 | } |
| 1278 | |
| 1279 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1280 | VisitCondition(comp); |
| 1281 | } |
| 1282 | |
| 1283 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1284 | VisitCondition(comp); |
| 1285 | } |
| 1286 | |
| 1287 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1288 | VisitCondition(comp); |
| 1289 | } |
| 1290 | |
| 1291 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1292 | VisitCondition(comp); |
| 1293 | } |
| 1294 | |
| 1295 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1296 | VisitCondition(comp); |
| 1297 | } |
| 1298 | |
| 1299 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1300 | VisitCondition(comp); |
| 1301 | } |
| 1302 | |
| 1303 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1304 | VisitCondition(comp); |
| 1305 | } |
| 1306 | |
| 1307 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1308 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1309 | } |
| 1310 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1311 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1312 | LocationSummary* locations = |
| 1313 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1314 | switch (compare->InputAt(0)->GetType()) { |
| 1315 | case Primitive::kPrimLong: { |
| 1316 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1317 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1318 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1319 | break; |
| 1320 | } |
| 1321 | case Primitive::kPrimFloat: |
| 1322 | case Primitive::kPrimDouble: { |
| 1323 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1324 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1325 | locations->SetOut(Location::RequiresRegister()); |
| 1326 | break; |
| 1327 | } |
| 1328 | default: |
| 1329 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1330 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1334 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1335 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1336 | Location left = locations->InAt(0); |
| 1337 | Location right = locations->InAt(1); |
| 1338 | |
| 1339 | Label less, greater, done; |
| 1340 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1341 | switch (type) { |
| 1342 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1343 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1344 | if (right.IsConstant()) { |
| 1345 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1346 | if (IsInt<32>(value)) { |
| 1347 | if (value == 0) { |
| 1348 | __ testq(left_reg, left_reg); |
| 1349 | } else { |
| 1350 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1351 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1352 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1353 | // Value won't fit in an int. |
| 1354 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1355 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1356 | } else if (right.IsDoubleStackSlot()) { |
| 1357 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1358 | } else { |
| 1359 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1360 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1361 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1362 | } |
| 1363 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1364 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1365 | if (right.IsConstant()) { |
| 1366 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1367 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1368 | } else if (right.IsStackSlot()) { |
| 1369 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1370 | } else { |
| 1371 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1372 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1373 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1374 | break; |
| 1375 | } |
| 1376 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1377 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1378 | if (right.IsConstant()) { |
| 1379 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1380 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1381 | } else if (right.IsDoubleStackSlot()) { |
| 1382 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1383 | } else { |
| 1384 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1385 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1386 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1387 | break; |
| 1388 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1389 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1390 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1391 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1392 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1393 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1394 | __ 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] | 1395 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1396 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1397 | __ movl(out, Immediate(1)); |
| 1398 | __ jmp(&done); |
| 1399 | |
| 1400 | __ Bind(&less); |
| 1401 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1402 | |
| 1403 | __ Bind(&done); |
| 1404 | } |
| 1405 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1406 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1407 | LocationSummary* locations = |
| 1408 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1409 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1413 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1414 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1415 | } |
| 1416 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1417 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1418 | LocationSummary* locations = |
| 1419 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1420 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1421 | } |
| 1422 | |
| 1423 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1424 | // Will be generated at use site. |
| 1425 | UNUSED(constant); |
| 1426 | } |
| 1427 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1428 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1429 | LocationSummary* locations = |
| 1430 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1431 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1435 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1436 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1437 | } |
| 1438 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1439 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1440 | LocationSummary* locations = |
| 1441 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1442 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1443 | } |
| 1444 | |
| 1445 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1446 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1447 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1451 | LocationSummary* locations = |
| 1452 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1453 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1454 | } |
| 1455 | |
| 1456 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1457 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1458 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1459 | } |
| 1460 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1461 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1462 | memory_barrier->SetLocations(nullptr); |
| 1463 | } |
| 1464 | |
| 1465 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1466 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1467 | } |
| 1468 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1469 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1470 | ret->SetLocations(nullptr); |
| 1471 | } |
| 1472 | |
| 1473 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1474 | UNUSED(ret); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1475 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1479 | LocationSummary* locations = |
| 1480 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1481 | switch (ret->InputAt(0)->GetType()) { |
| 1482 | case Primitive::kPrimBoolean: |
| 1483 | case Primitive::kPrimByte: |
| 1484 | case Primitive::kPrimChar: |
| 1485 | case Primitive::kPrimShort: |
| 1486 | case Primitive::kPrimInt: |
| 1487 | case Primitive::kPrimNot: |
| 1488 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1489 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1490 | break; |
| 1491 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1492 | case Primitive::kPrimFloat: |
| 1493 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1494 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1495 | break; |
| 1496 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1497 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1498 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1499 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1503 | if (kIsDebugBuild) { |
| 1504 | switch (ret->InputAt(0)->GetType()) { |
| 1505 | case Primitive::kPrimBoolean: |
| 1506 | case Primitive::kPrimByte: |
| 1507 | case Primitive::kPrimChar: |
| 1508 | case Primitive::kPrimShort: |
| 1509 | case Primitive::kPrimInt: |
| 1510 | case Primitive::kPrimNot: |
| 1511 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1512 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1513 | break; |
| 1514 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1515 | case Primitive::kPrimFloat: |
| 1516 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1517 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1518 | XMM0); |
| 1519 | break; |
| 1520 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1521 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1522 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1526 | } |
| 1527 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1528 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1529 | switch (type) { |
| 1530 | case Primitive::kPrimBoolean: |
| 1531 | case Primitive::kPrimByte: |
| 1532 | case Primitive::kPrimChar: |
| 1533 | case Primitive::kPrimShort: |
| 1534 | case Primitive::kPrimInt: |
| 1535 | case Primitive::kPrimNot: |
| 1536 | case Primitive::kPrimLong: |
| 1537 | return Location::RegisterLocation(RAX); |
| 1538 | |
| 1539 | case Primitive::kPrimVoid: |
| 1540 | return Location::NoLocation(); |
| 1541 | |
| 1542 | case Primitive::kPrimDouble: |
| 1543 | case Primitive::kPrimFloat: |
| 1544 | return Location::FpuRegisterLocation(XMM0); |
| 1545 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1546 | |
| 1547 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 1551 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1552 | } |
| 1553 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1554 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1555 | switch (type) { |
| 1556 | case Primitive::kPrimBoolean: |
| 1557 | case Primitive::kPrimByte: |
| 1558 | case Primitive::kPrimChar: |
| 1559 | case Primitive::kPrimShort: |
| 1560 | case Primitive::kPrimInt: |
| 1561 | case Primitive::kPrimNot: { |
| 1562 | uint32_t index = gp_index_++; |
| 1563 | stack_index_++; |
| 1564 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1565 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1566 | } else { |
| 1567 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | case Primitive::kPrimLong: { |
| 1572 | uint32_t index = gp_index_; |
| 1573 | stack_index_ += 2; |
| 1574 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1575 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1576 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1577 | } else { |
| 1578 | gp_index_ += 2; |
| 1579 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1580 | } |
| 1581 | } |
| 1582 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1583 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1584 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1585 | stack_index_++; |
| 1586 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1587 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1588 | } else { |
| 1589 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1594 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1595 | stack_index_ += 2; |
| 1596 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1597 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1598 | } else { |
| 1599 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1600 | } |
| 1601 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1602 | |
| 1603 | case Primitive::kPrimVoid: |
| 1604 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1605 | break; |
| 1606 | } |
| 1607 | return Location(); |
| 1608 | } |
| 1609 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1610 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1611 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1612 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1613 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1614 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1615 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1616 | if (intrinsic.TryDispatch(invoke)) { |
| 1617 | return; |
| 1618 | } |
| 1619 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1620 | HandleInvoke(invoke); |
| 1621 | } |
| 1622 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1623 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 1624 | if (invoke->GetLocations()->Intrinsified()) { |
| 1625 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 1626 | intrinsic.Dispatch(invoke); |
| 1627 | return true; |
| 1628 | } |
| 1629 | return false; |
| 1630 | } |
| 1631 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1632 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1633 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1634 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1635 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1636 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1637 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1638 | return; |
| 1639 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1640 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1641 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1642 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1643 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1644 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1645 | } |
| 1646 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1647 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1648 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1649 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1650 | } |
| 1651 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1652 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1653 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1654 | if (intrinsic.TryDispatch(invoke)) { |
| 1655 | return; |
| 1656 | } |
| 1657 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1658 | HandleInvoke(invoke); |
| 1659 | } |
| 1660 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1661 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1662 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1663 | return; |
| 1664 | } |
| 1665 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1666 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1667 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1668 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1669 | LocationSummary* locations = invoke->GetLocations(); |
| 1670 | Location receiver = locations->InAt(0); |
| 1671 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1672 | // temp = object->GetClass(); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1673 | DCHECK(receiver.IsRegister()); |
| 1674 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1675 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1676 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1677 | // temp = temp->GetMethodAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1678 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1679 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1680 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1681 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1682 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1683 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1684 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1685 | } |
| 1686 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1687 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1688 | HandleInvoke(invoke); |
| 1689 | // Add the hidden argument. |
| 1690 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1691 | } |
| 1692 | |
| 1693 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1694 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1695 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1696 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1697 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1698 | LocationSummary* locations = invoke->GetLocations(); |
| 1699 | Location receiver = locations->InAt(0); |
| 1700 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1701 | |
| 1702 | // Set the hidden argument. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1703 | CpuRegister hidden_reg = invoke->GetLocations()->GetTemp(1).AsRegister<CpuRegister>(); |
| 1704 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1705 | |
| 1706 | // temp = object->GetClass(); |
| 1707 | if (receiver.IsStackSlot()) { |
| 1708 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1709 | __ movl(temp, Address(temp, class_offset)); |
| 1710 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1711 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1712 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1713 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1714 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1715 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1716 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1717 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1718 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1719 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1720 | |
| 1721 | DCHECK(!codegen_->IsLeafMethod()); |
| 1722 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1723 | } |
| 1724 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1725 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1726 | LocationSummary* locations = |
| 1727 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1728 | switch (neg->GetResultType()) { |
| 1729 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1730 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1731 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1732 | locations->SetOut(Location::SameAsFirstInput()); |
| 1733 | break; |
| 1734 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1735 | case Primitive::kPrimFloat: |
| 1736 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1737 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1738 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1739 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1740 | break; |
| 1741 | |
| 1742 | default: |
| 1743 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1748 | LocationSummary* locations = neg->GetLocations(); |
| 1749 | Location out = locations->Out(); |
| 1750 | Location in = locations->InAt(0); |
| 1751 | switch (neg->GetResultType()) { |
| 1752 | case Primitive::kPrimInt: |
| 1753 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1754 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1755 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1756 | break; |
| 1757 | |
| 1758 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1759 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1760 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1761 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1762 | break; |
| 1763 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1764 | case Primitive::kPrimFloat: { |
| 1765 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1766 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1767 | // Implement float negation with an exclusive or with value |
| 1768 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1769 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1770 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1771 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1772 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1773 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1774 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1775 | case Primitive::kPrimDouble: { |
| 1776 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1777 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1778 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1779 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1780 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1781 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1782 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1783 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1784 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1785 | |
| 1786 | default: |
| 1787 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1788 | } |
| 1789 | } |
| 1790 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1791 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1792 | LocationSummary* locations = |
| 1793 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1794 | Primitive::Type result_type = conversion->GetResultType(); |
| 1795 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1796 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1797 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1798 | // The Java language does not allow treating boolean as an integral type but |
| 1799 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1800 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1801 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1802 | case Primitive::kPrimByte: |
| 1803 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1804 | case Primitive::kPrimBoolean: |
| 1805 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1806 | case Primitive::kPrimShort: |
| 1807 | case Primitive::kPrimInt: |
| 1808 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1809 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1810 | locations->SetInAt(0, Location::Any()); |
| 1811 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1812 | break; |
| 1813 | |
| 1814 | default: |
| 1815 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1816 | << " to " << result_type; |
| 1817 | } |
| 1818 | break; |
| 1819 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1820 | case Primitive::kPrimShort: |
| 1821 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1822 | case Primitive::kPrimBoolean: |
| 1823 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1824 | case Primitive::kPrimByte: |
| 1825 | case Primitive::kPrimInt: |
| 1826 | case Primitive::kPrimChar: |
| 1827 | // Processing a Dex `int-to-short' instruction. |
| 1828 | locations->SetInAt(0, Location::Any()); |
| 1829 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1830 | break; |
| 1831 | |
| 1832 | default: |
| 1833 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1834 | << " to " << result_type; |
| 1835 | } |
| 1836 | break; |
| 1837 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1838 | case Primitive::kPrimInt: |
| 1839 | switch (input_type) { |
| 1840 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1841 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1842 | locations->SetInAt(0, Location::Any()); |
| 1843 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1844 | break; |
| 1845 | |
| 1846 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1847 | // Processing a Dex `float-to-int' instruction. |
| 1848 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1849 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1850 | break; |
| 1851 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1852 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1853 | // Processing a Dex `double-to-int' instruction. |
| 1854 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1855 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1856 | break; |
| 1857 | |
| 1858 | default: |
| 1859 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1860 | << " to " << result_type; |
| 1861 | } |
| 1862 | break; |
| 1863 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1864 | case Primitive::kPrimLong: |
| 1865 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1866 | case Primitive::kPrimBoolean: |
| 1867 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1868 | case Primitive::kPrimByte: |
| 1869 | case Primitive::kPrimShort: |
| 1870 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1871 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1872 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1873 | // TODO: We would benefit from a (to-be-implemented) |
| 1874 | // Location::RegisterOrStackSlot requirement for this input. |
| 1875 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1876 | locations->SetOut(Location::RequiresRegister()); |
| 1877 | break; |
| 1878 | |
| 1879 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1880 | // Processing a Dex `float-to-long' instruction. |
| 1881 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1882 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1883 | break; |
| 1884 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1885 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1886 | // Processing a Dex `double-to-long' instruction. |
| 1887 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1888 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1889 | break; |
| 1890 | |
| 1891 | default: |
| 1892 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1893 | << " to " << result_type; |
| 1894 | } |
| 1895 | break; |
| 1896 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1897 | case Primitive::kPrimChar: |
| 1898 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1899 | case Primitive::kPrimBoolean: |
| 1900 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1901 | case Primitive::kPrimByte: |
| 1902 | case Primitive::kPrimShort: |
| 1903 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1904 | // Processing a Dex `int-to-char' instruction. |
| 1905 | locations->SetInAt(0, Location::Any()); |
| 1906 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1907 | break; |
| 1908 | |
| 1909 | default: |
| 1910 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1911 | << " to " << result_type; |
| 1912 | } |
| 1913 | break; |
| 1914 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1915 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1916 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1917 | case Primitive::kPrimBoolean: |
| 1918 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1919 | case Primitive::kPrimByte: |
| 1920 | case Primitive::kPrimShort: |
| 1921 | case Primitive::kPrimInt: |
| 1922 | case Primitive::kPrimChar: |
| 1923 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1924 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1925 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1926 | break; |
| 1927 | |
| 1928 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1929 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1930 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1931 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1932 | break; |
| 1933 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1934 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1935 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1936 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1937 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1938 | break; |
| 1939 | |
| 1940 | default: |
| 1941 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1942 | << " to " << result_type; |
| 1943 | }; |
| 1944 | break; |
| 1945 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1946 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1947 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1948 | case Primitive::kPrimBoolean: |
| 1949 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1950 | case Primitive::kPrimByte: |
| 1951 | case Primitive::kPrimShort: |
| 1952 | case Primitive::kPrimInt: |
| 1953 | case Primitive::kPrimChar: |
| 1954 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1955 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1956 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1957 | break; |
| 1958 | |
| 1959 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1960 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1961 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1962 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1963 | break; |
| 1964 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1965 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1966 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1967 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1968 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1969 | break; |
| 1970 | |
| 1971 | default: |
| 1972 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1973 | << " to " << result_type; |
| 1974 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1975 | break; |
| 1976 | |
| 1977 | default: |
| 1978 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1979 | << " to " << result_type; |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1984 | LocationSummary* locations = conversion->GetLocations(); |
| 1985 | Location out = locations->Out(); |
| 1986 | Location in = locations->InAt(0); |
| 1987 | Primitive::Type result_type = conversion->GetResultType(); |
| 1988 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1989 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1990 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1991 | case Primitive::kPrimByte: |
| 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 | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1995 | case Primitive::kPrimShort: |
| 1996 | case Primitive::kPrimInt: |
| 1997 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1998 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1999 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2000 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2001 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2002 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2003 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2004 | } else { |
| 2005 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2006 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2007 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2008 | } |
| 2009 | break; |
| 2010 | |
| 2011 | default: |
| 2012 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2013 | << " to " << result_type; |
| 2014 | } |
| 2015 | break; |
| 2016 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2017 | case Primitive::kPrimShort: |
| 2018 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2019 | case Primitive::kPrimBoolean: |
| 2020 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2021 | case Primitive::kPrimByte: |
| 2022 | case Primitive::kPrimInt: |
| 2023 | case Primitive::kPrimChar: |
| 2024 | // Processing a Dex `int-to-short' instruction. |
| 2025 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2026 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2027 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2028 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2029 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2030 | } else { |
| 2031 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2032 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2033 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2034 | } |
| 2035 | break; |
| 2036 | |
| 2037 | default: |
| 2038 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2039 | << " to " << result_type; |
| 2040 | } |
| 2041 | break; |
| 2042 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2043 | case Primitive::kPrimInt: |
| 2044 | switch (input_type) { |
| 2045 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2046 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2047 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2048 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2049 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2050 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2051 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2052 | } else { |
| 2053 | DCHECK(in.IsConstant()); |
| 2054 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2055 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2056 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2057 | } |
| 2058 | break; |
| 2059 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2060 | case Primitive::kPrimFloat: { |
| 2061 | // Processing a Dex `float-to-int' instruction. |
| 2062 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2063 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2064 | Label done, nan; |
| 2065 | |
| 2066 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2067 | // if input >= (float)INT_MAX goto done |
| 2068 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2069 | __ j(kAboveEqual, &done); |
| 2070 | // if input == NaN goto nan |
| 2071 | __ j(kUnordered, &nan); |
| 2072 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2073 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2074 | __ jmp(&done); |
| 2075 | __ Bind(&nan); |
| 2076 | // output = 0 |
| 2077 | __ xorl(output, output); |
| 2078 | __ Bind(&done); |
| 2079 | break; |
| 2080 | } |
| 2081 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2082 | case Primitive::kPrimDouble: { |
| 2083 | // Processing a Dex `double-to-int' instruction. |
| 2084 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2085 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2086 | Label done, nan; |
| 2087 | |
| 2088 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2089 | // if input >= (double)INT_MAX goto done |
| 2090 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2091 | __ j(kAboveEqual, &done); |
| 2092 | // if input == NaN goto nan |
| 2093 | __ j(kUnordered, &nan); |
| 2094 | // output = double-to-int-truncate(input) |
| 2095 | __ cvttsd2si(output, input); |
| 2096 | __ jmp(&done); |
| 2097 | __ Bind(&nan); |
| 2098 | // output = 0 |
| 2099 | __ xorl(output, output); |
| 2100 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2101 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2102 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2103 | |
| 2104 | default: |
| 2105 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2106 | << " to " << result_type; |
| 2107 | } |
| 2108 | break; |
| 2109 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2110 | case Primitive::kPrimLong: |
| 2111 | switch (input_type) { |
| 2112 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2113 | case Primitive::kPrimBoolean: |
| 2114 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2115 | case Primitive::kPrimByte: |
| 2116 | case Primitive::kPrimShort: |
| 2117 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2118 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2119 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2120 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2121 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2122 | break; |
| 2123 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2124 | case Primitive::kPrimFloat: { |
| 2125 | // Processing a Dex `float-to-long' instruction. |
| 2126 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2127 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2128 | Label done, nan; |
| 2129 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2130 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2131 | // if input >= (float)LONG_MAX goto done |
| 2132 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2133 | __ j(kAboveEqual, &done); |
| 2134 | // if input == NaN goto nan |
| 2135 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2136 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2137 | __ cvttss2si(output, input, true); |
| 2138 | __ jmp(&done); |
| 2139 | __ Bind(&nan); |
| 2140 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2141 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2142 | __ Bind(&done); |
| 2143 | break; |
| 2144 | } |
| 2145 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2146 | case Primitive::kPrimDouble: { |
| 2147 | // Processing a Dex `double-to-long' instruction. |
| 2148 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2149 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2150 | Label done, nan; |
| 2151 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2152 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2153 | // if input >= (double)LONG_MAX goto done |
| 2154 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2155 | __ j(kAboveEqual, &done); |
| 2156 | // if input == NaN goto nan |
| 2157 | __ j(kUnordered, &nan); |
| 2158 | // output = double-to-long-truncate(input) |
| 2159 | __ cvttsd2si(output, input, true); |
| 2160 | __ jmp(&done); |
| 2161 | __ Bind(&nan); |
| 2162 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2163 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2164 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2165 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2166 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2167 | |
| 2168 | default: |
| 2169 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2170 | << " to " << result_type; |
| 2171 | } |
| 2172 | break; |
| 2173 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2174 | case Primitive::kPrimChar: |
| 2175 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2176 | case Primitive::kPrimBoolean: |
| 2177 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2178 | case Primitive::kPrimByte: |
| 2179 | case Primitive::kPrimShort: |
| 2180 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2181 | // Processing a Dex `int-to-char' instruction. |
| 2182 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2183 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2184 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2185 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2186 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2187 | } else { |
| 2188 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2189 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2190 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2191 | } |
| 2192 | break; |
| 2193 | |
| 2194 | default: |
| 2195 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2196 | << " to " << result_type; |
| 2197 | } |
| 2198 | break; |
| 2199 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2200 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2201 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2202 | case Primitive::kPrimBoolean: |
| 2203 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2204 | case Primitive::kPrimByte: |
| 2205 | case Primitive::kPrimShort: |
| 2206 | case Primitive::kPrimInt: |
| 2207 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2208 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2209 | if (in.IsRegister()) { |
| 2210 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2211 | } else if (in.IsConstant()) { |
| 2212 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2213 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2214 | if (v == 0) { |
| 2215 | __ xorps(dest, dest); |
| 2216 | } else { |
| 2217 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2218 | } |
| 2219 | } else { |
| 2220 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2221 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2222 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2223 | break; |
| 2224 | |
| 2225 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2226 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2227 | if (in.IsRegister()) { |
| 2228 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2229 | } else if (in.IsConstant()) { |
| 2230 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2231 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2232 | if (v == 0) { |
| 2233 | __ xorps(dest, dest); |
| 2234 | } else { |
| 2235 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2236 | } |
| 2237 | } else { |
| 2238 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2239 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2240 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2241 | break; |
| 2242 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2243 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2244 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2245 | if (in.IsFpuRegister()) { |
| 2246 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2247 | } else if (in.IsConstant()) { |
| 2248 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2249 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2250 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2251 | __ xorps(dest, dest); |
| 2252 | } else { |
| 2253 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2254 | } |
| 2255 | } else { |
| 2256 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2257 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2258 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2259 | break; |
| 2260 | |
| 2261 | default: |
| 2262 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2263 | << " to " << result_type; |
| 2264 | }; |
| 2265 | break; |
| 2266 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2267 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2268 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2269 | case Primitive::kPrimBoolean: |
| 2270 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2271 | case Primitive::kPrimByte: |
| 2272 | case Primitive::kPrimShort: |
| 2273 | case Primitive::kPrimInt: |
| 2274 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2275 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2276 | if (in.IsRegister()) { |
| 2277 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2278 | } else if (in.IsConstant()) { |
| 2279 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2280 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2281 | if (v == 0) { |
| 2282 | __ xorpd(dest, dest); |
| 2283 | } else { |
| 2284 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2285 | } |
| 2286 | } else { |
| 2287 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2288 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2289 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2290 | break; |
| 2291 | |
| 2292 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2293 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2294 | if (in.IsRegister()) { |
| 2295 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2296 | } else if (in.IsConstant()) { |
| 2297 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2298 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2299 | if (v == 0) { |
| 2300 | __ xorpd(dest, dest); |
| 2301 | } else { |
| 2302 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2303 | } |
| 2304 | } else { |
| 2305 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2306 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2307 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2308 | break; |
| 2309 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2310 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2311 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2312 | if (in.IsFpuRegister()) { |
| 2313 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2314 | } else if (in.IsConstant()) { |
| 2315 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2316 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2317 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2318 | __ xorpd(dest, dest); |
| 2319 | } else { |
| 2320 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2321 | } |
| 2322 | } else { |
| 2323 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2324 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2325 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2326 | break; |
| 2327 | |
| 2328 | default: |
| 2329 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2330 | << " to " << result_type; |
| 2331 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2332 | break; |
| 2333 | |
| 2334 | default: |
| 2335 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2336 | << " to " << result_type; |
| 2337 | } |
| 2338 | } |
| 2339 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2340 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2341 | LocationSummary* locations = |
| 2342 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2343 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2344 | case Primitive::kPrimInt: { |
| 2345 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2346 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2347 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2348 | break; |
| 2349 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2350 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2351 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2352 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2353 | // 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] | 2354 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2355 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2356 | break; |
| 2357 | } |
| 2358 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2359 | case Primitive::kPrimDouble: |
| 2360 | case Primitive::kPrimFloat: { |
| 2361 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2362 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2363 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2364 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2365 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2366 | |
| 2367 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2368 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2369 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2370 | } |
| 2371 | |
| 2372 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2373 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2374 | Location first = locations->InAt(0); |
| 2375 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2376 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2377 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2378 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2379 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2380 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2381 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2382 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2383 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2384 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2385 | } else { |
| 2386 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2387 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2388 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2389 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2390 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2391 | __ addl(out.AsRegister<CpuRegister>(), |
| 2392 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2393 | } else { |
| 2394 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2395 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2396 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2397 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2398 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2399 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2400 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2403 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2404 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2405 | if (second.IsRegister()) { |
| 2406 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2407 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2408 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2409 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2410 | } else { |
| 2411 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2412 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2413 | } |
| 2414 | } else { |
| 2415 | DCHECK(second.IsConstant()); |
| 2416 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2417 | int32_t int32_value = Low32Bits(value); |
| 2418 | DCHECK_EQ(int32_value, value); |
| 2419 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2420 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2421 | } else { |
| 2422 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2423 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2424 | } |
| 2425 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2426 | break; |
| 2427 | } |
| 2428 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2429 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2430 | if (second.IsFpuRegister()) { |
| 2431 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2432 | } else if (second.IsConstant()) { |
| 2433 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2434 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2435 | } else { |
| 2436 | DCHECK(second.IsStackSlot()); |
| 2437 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2438 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2439 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2440 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2444 | if (second.IsFpuRegister()) { |
| 2445 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2446 | } else if (second.IsConstant()) { |
| 2447 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2448 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2449 | } else { |
| 2450 | DCHECK(second.IsDoubleStackSlot()); |
| 2451 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2452 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2453 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2454 | break; |
| 2455 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2456 | |
| 2457 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2458 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2459 | } |
| 2460 | } |
| 2461 | |
| 2462 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2463 | LocationSummary* locations = |
| 2464 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2465 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2466 | case Primitive::kPrimInt: { |
| 2467 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2468 | locations->SetInAt(1, Location::Any()); |
| 2469 | locations->SetOut(Location::SameAsFirstInput()); |
| 2470 | break; |
| 2471 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2472 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2473 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2474 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2475 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2476 | break; |
| 2477 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2478 | case Primitive::kPrimFloat: |
| 2479 | case Primitive::kPrimDouble: { |
| 2480 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2481 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2482 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2483 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2484 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2485 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2486 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2487 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2491 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2492 | Location first = locations->InAt(0); |
| 2493 | Location second = locations->InAt(1); |
| 2494 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2495 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2496 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2497 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2498 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2499 | } else if (second.IsConstant()) { |
| 2500 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2501 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2502 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2503 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2504 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2505 | break; |
| 2506 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2507 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2508 | if (second.IsConstant()) { |
| 2509 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2510 | DCHECK(IsInt<32>(value)); |
| 2511 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2512 | } else { |
| 2513 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2514 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2515 | break; |
| 2516 | } |
| 2517 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2518 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2519 | if (second.IsFpuRegister()) { |
| 2520 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2521 | } else if (second.IsConstant()) { |
| 2522 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2523 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2524 | } else { |
| 2525 | DCHECK(second.IsStackSlot()); |
| 2526 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2527 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2528 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2529 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2533 | if (second.IsFpuRegister()) { |
| 2534 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2535 | } else if (second.IsConstant()) { |
| 2536 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2537 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2538 | } else { |
| 2539 | DCHECK(second.IsDoubleStackSlot()); |
| 2540 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2541 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2542 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2543 | break; |
| 2544 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2545 | |
| 2546 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2547 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2548 | } |
| 2549 | } |
| 2550 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2551 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2552 | LocationSummary* locations = |
| 2553 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2554 | switch (mul->GetResultType()) { |
| 2555 | case Primitive::kPrimInt: { |
| 2556 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2557 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2558 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2559 | // Can use 3 operand multiply. |
| 2560 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2561 | } else { |
| 2562 | locations->SetOut(Location::SameAsFirstInput()); |
| 2563 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2564 | break; |
| 2565 | } |
| 2566 | case Primitive::kPrimLong: { |
| 2567 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2568 | locations->SetInAt(1, Location::Any()); |
| 2569 | if (mul->InputAt(1)->IsLongConstant() && |
| 2570 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2571 | // Can use 3 operand multiply. |
| 2572 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2573 | } else { |
| 2574 | locations->SetOut(Location::SameAsFirstInput()); |
| 2575 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2576 | break; |
| 2577 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2578 | case Primitive::kPrimFloat: |
| 2579 | case Primitive::kPrimDouble: { |
| 2580 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2581 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2582 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2583 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2584 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2585 | |
| 2586 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2587 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2588 | } |
| 2589 | } |
| 2590 | |
| 2591 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2592 | LocationSummary* locations = mul->GetLocations(); |
| 2593 | Location first = locations->InAt(0); |
| 2594 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2595 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2596 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2597 | case Primitive::kPrimInt: |
| 2598 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2599 | // problems where the output may not be the same as the first operand. |
| 2600 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2601 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2602 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 2603 | } else if (second.IsRegister()) { |
| 2604 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2605 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2606 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2607 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2608 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2609 | __ imull(first.AsRegister<CpuRegister>(), |
| 2610 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2611 | } |
| 2612 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2613 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2614 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2615 | // problems where the output may not be the same as the first operand. |
| 2616 | if (mul->InputAt(1)->IsLongConstant()) { |
| 2617 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 2618 | if (IsInt<32>(value)) { |
| 2619 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 2620 | Immediate(static_cast<int32_t>(value))); |
| 2621 | } else { |
| 2622 | // Have to use the constant area. |
| 2623 | DCHECK(first.Equals(out)); |
| 2624 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 2625 | } |
| 2626 | } else if (second.IsRegister()) { |
| 2627 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2628 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2629 | } else { |
| 2630 | DCHECK(second.IsDoubleStackSlot()); |
| 2631 | DCHECK(first.Equals(out)); |
| 2632 | __ imulq(first.AsRegister<CpuRegister>(), |
| 2633 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2634 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2635 | break; |
| 2636 | } |
| 2637 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2638 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2639 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2640 | if (second.IsFpuRegister()) { |
| 2641 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2642 | } else if (second.IsConstant()) { |
| 2643 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2644 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2645 | } else { |
| 2646 | DCHECK(second.IsStackSlot()); |
| 2647 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2648 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2649 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2650 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2654 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2655 | if (second.IsFpuRegister()) { |
| 2656 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2657 | } else if (second.IsConstant()) { |
| 2658 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2659 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2660 | } else { |
| 2661 | DCHECK(second.IsDoubleStackSlot()); |
| 2662 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2663 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2664 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2665 | break; |
| 2666 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2667 | |
| 2668 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2669 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2670 | } |
| 2671 | } |
| 2672 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2673 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2674 | uint32_t stack_adjustment, bool is_float) { |
| 2675 | if (source.IsStackSlot()) { |
| 2676 | DCHECK(is_float); |
| 2677 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2678 | } else if (source.IsDoubleStackSlot()) { |
| 2679 | DCHECK(!is_float); |
| 2680 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2681 | } else { |
| 2682 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2683 | if (is_float) { |
| 2684 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2685 | codegen_->Move(stack_temp, source); |
| 2686 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2687 | } else { |
| 2688 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2689 | codegen_->Move(stack_temp, source); |
| 2690 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2691 | } |
| 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2696 | Primitive::Type type = rem->GetResultType(); |
| 2697 | bool is_float = type == Primitive::kPrimFloat; |
| 2698 | size_t elem_size = Primitive::ComponentSize(type); |
| 2699 | LocationSummary* locations = rem->GetLocations(); |
| 2700 | Location first = locations->InAt(0); |
| 2701 | Location second = locations->InAt(1); |
| 2702 | Location out = locations->Out(); |
| 2703 | |
| 2704 | // Create stack space for 2 elements. |
| 2705 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2706 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2707 | |
| 2708 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2709 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2710 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2711 | |
| 2712 | // Loop doing FPREM until we stabilize. |
| 2713 | Label retry; |
| 2714 | __ Bind(&retry); |
| 2715 | __ fprem(); |
| 2716 | |
| 2717 | // Move FP status to AX. |
| 2718 | __ fstsw(); |
| 2719 | |
| 2720 | // And see if the argument reduction is complete. This is signaled by the |
| 2721 | // C2 FPU flag bit set to 0. |
| 2722 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2723 | __ j(kNotEqual, &retry); |
| 2724 | |
| 2725 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2726 | // Store FP top of stack to real stack. |
| 2727 | if (is_float) { |
| 2728 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2729 | } else { |
| 2730 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2731 | } |
| 2732 | |
| 2733 | // Pop the 2 items from the FP stack. |
| 2734 | __ fucompp(); |
| 2735 | |
| 2736 | // Load the value from the stack into an XMM register. |
| 2737 | DCHECK(out.IsFpuRegister()) << out; |
| 2738 | if (is_float) { |
| 2739 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2740 | } else { |
| 2741 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2742 | } |
| 2743 | |
| 2744 | // And remove the temporary stack space we allocated. |
| 2745 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2746 | } |
| 2747 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2748 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2749 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2750 | |
| 2751 | LocationSummary* locations = instruction->GetLocations(); |
| 2752 | Location second = locations->InAt(1); |
| 2753 | DCHECK(second.IsConstant()); |
| 2754 | |
| 2755 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2756 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2757 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2758 | |
| 2759 | DCHECK(imm == 1 || imm == -1); |
| 2760 | |
| 2761 | switch (instruction->GetResultType()) { |
| 2762 | case Primitive::kPrimInt: { |
| 2763 | if (instruction->IsRem()) { |
| 2764 | __ xorl(output_register, output_register); |
| 2765 | } else { |
| 2766 | __ movl(output_register, input_register); |
| 2767 | if (imm == -1) { |
| 2768 | __ negl(output_register); |
| 2769 | } |
| 2770 | } |
| 2771 | break; |
| 2772 | } |
| 2773 | |
| 2774 | case Primitive::kPrimLong: { |
| 2775 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2776 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2777 | } else { |
| 2778 | __ movq(output_register, input_register); |
| 2779 | if (imm == -1) { |
| 2780 | __ negq(output_register); |
| 2781 | } |
| 2782 | } |
| 2783 | break; |
| 2784 | } |
| 2785 | |
| 2786 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2787 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2788 | } |
| 2789 | } |
| 2790 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2791 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2792 | LocationSummary* locations = instruction->GetLocations(); |
| 2793 | Location second = locations->InAt(1); |
| 2794 | |
| 2795 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2796 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2797 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2798 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2799 | |
| 2800 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 2801 | |
| 2802 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2803 | |
| 2804 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2805 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 2806 | __ testl(numerator, numerator); |
| 2807 | __ cmov(kGreaterEqual, tmp, numerator); |
| 2808 | int shift = CTZ(imm); |
| 2809 | __ sarl(tmp, Immediate(shift)); |
| 2810 | |
| 2811 | if (imm < 0) { |
| 2812 | __ negl(tmp); |
| 2813 | } |
| 2814 | |
| 2815 | __ movl(output_register, tmp); |
| 2816 | } else { |
| 2817 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2818 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2819 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2820 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2821 | __ addq(rdx, numerator); |
| 2822 | __ testq(numerator, numerator); |
| 2823 | __ cmov(kGreaterEqual, rdx, numerator); |
| 2824 | int shift = CTZ(imm); |
| 2825 | __ sarq(rdx, Immediate(shift)); |
| 2826 | |
| 2827 | if (imm < 0) { |
| 2828 | __ negq(rdx); |
| 2829 | } |
| 2830 | |
| 2831 | __ movq(output_register, rdx); |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2836 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2837 | |
| 2838 | LocationSummary* locations = instruction->GetLocations(); |
| 2839 | Location second = locations->InAt(1); |
| 2840 | |
| 2841 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 2842 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2843 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2844 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 2845 | : locations->Out().AsRegister<CpuRegister>(); |
| 2846 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 2847 | |
| 2848 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 2849 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 2850 | if (instruction->IsDiv()) { |
| 2851 | DCHECK_EQ(RAX, out.AsRegister()); |
| 2852 | } else { |
| 2853 | DCHECK_EQ(RDX, out.AsRegister()); |
| 2854 | } |
| 2855 | |
| 2856 | int64_t magic; |
| 2857 | int shift; |
| 2858 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2859 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2860 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2861 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2862 | |
| 2863 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2864 | |
| 2865 | __ movl(numerator, eax); |
| 2866 | |
| 2867 | Label no_div; |
| 2868 | Label end; |
| 2869 | __ testl(eax, eax); |
| 2870 | __ j(kNotEqual, &no_div); |
| 2871 | |
| 2872 | __ xorl(out, out); |
| 2873 | __ jmp(&end); |
| 2874 | |
| 2875 | __ Bind(&no_div); |
| 2876 | |
| 2877 | __ movl(eax, Immediate(magic)); |
| 2878 | __ imull(numerator); |
| 2879 | |
| 2880 | if (imm > 0 && magic < 0) { |
| 2881 | __ addl(edx, numerator); |
| 2882 | } else if (imm < 0 && magic > 0) { |
| 2883 | __ subl(edx, numerator); |
| 2884 | } |
| 2885 | |
| 2886 | if (shift != 0) { |
| 2887 | __ sarl(edx, Immediate(shift)); |
| 2888 | } |
| 2889 | |
| 2890 | __ movl(eax, edx); |
| 2891 | __ shrl(edx, Immediate(31)); |
| 2892 | __ addl(edx, eax); |
| 2893 | |
| 2894 | if (instruction->IsRem()) { |
| 2895 | __ movl(eax, numerator); |
| 2896 | __ imull(edx, Immediate(imm)); |
| 2897 | __ subl(eax, edx); |
| 2898 | __ movl(edx, eax); |
| 2899 | } else { |
| 2900 | __ movl(eax, edx); |
| 2901 | } |
| 2902 | __ Bind(&end); |
| 2903 | } else { |
| 2904 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2905 | |
| 2906 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2907 | |
| 2908 | CpuRegister rax = eax; |
| 2909 | CpuRegister rdx = edx; |
| 2910 | |
| 2911 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 2912 | |
| 2913 | // Save the numerator. |
| 2914 | __ movq(numerator, rax); |
| 2915 | |
| 2916 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2917 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2918 | |
| 2919 | // RDX:RAX = magic * numerator |
| 2920 | __ imulq(numerator); |
| 2921 | |
| 2922 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2923 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2924 | __ addq(rdx, numerator); |
| 2925 | } else if (imm < 0 && magic > 0) { |
| 2926 | // RDX -= numerator |
| 2927 | __ subq(rdx, numerator); |
| 2928 | } |
| 2929 | |
| 2930 | // Shift if needed. |
| 2931 | if (shift != 0) { |
| 2932 | __ sarq(rdx, Immediate(shift)); |
| 2933 | } |
| 2934 | |
| 2935 | // RDX += 1 if RDX < 0 |
| 2936 | __ movq(rax, rdx); |
| 2937 | __ shrq(rdx, Immediate(63)); |
| 2938 | __ addq(rdx, rax); |
| 2939 | |
| 2940 | if (instruction->IsRem()) { |
| 2941 | __ movq(rax, numerator); |
| 2942 | |
| 2943 | if (IsInt<32>(imm)) { |
| 2944 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 2945 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2946 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | __ subq(rax, rdx); |
| 2950 | __ movq(rdx, rax); |
| 2951 | } else { |
| 2952 | __ movq(rax, rdx); |
| 2953 | } |
| 2954 | } |
| 2955 | } |
| 2956 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2957 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2958 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2959 | Primitive::Type type = instruction->GetResultType(); |
| 2960 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2961 | |
| 2962 | bool is_div = instruction->IsDiv(); |
| 2963 | LocationSummary* locations = instruction->GetLocations(); |
| 2964 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2965 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 2966 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2967 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2968 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2969 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2970 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2971 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2972 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2973 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2974 | if (imm == 0) { |
| 2975 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2976 | } else if (imm == 1 || imm == -1) { |
| 2977 | DivRemOneOrMinusOne(instruction); |
| 2978 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2979 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2980 | } else { |
| 2981 | DCHECK(imm <= -2 || imm >= 2); |
| 2982 | GenerateDivRemWithAnyConstant(instruction); |
| 2983 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2984 | } else { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2985 | SlowPathCodeX86_64* slow_path = |
| 2986 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 2987 | out.AsRegister(), type, is_div); |
| 2988 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2989 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2990 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 2991 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 2992 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 2993 | // so it's safe to just use negl instead of more complex comparisons. |
| 2994 | if (type == Primitive::kPrimInt) { |
| 2995 | __ cmpl(second_reg, Immediate(-1)); |
| 2996 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2997 | // edx:eax <- sign-extended of eax |
| 2998 | __ cdq(); |
| 2999 | // eax = quotient, edx = remainder |
| 3000 | __ idivl(second_reg); |
| 3001 | } else { |
| 3002 | __ cmpq(second_reg, Immediate(-1)); |
| 3003 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3004 | // rdx:rax <- sign-extended of rax |
| 3005 | __ cqo(); |
| 3006 | // rax = quotient, rdx = remainder |
| 3007 | __ idivq(second_reg); |
| 3008 | } |
| 3009 | __ Bind(slow_path->GetExitLabel()); |
| 3010 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3013 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3014 | LocationSummary* locations = |
| 3015 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3016 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3017 | case Primitive::kPrimInt: |
| 3018 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3019 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3020 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3021 | locations->SetOut(Location::SameAsFirstInput()); |
| 3022 | // Intel uses edx:eax as the dividend. |
| 3023 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3024 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3025 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3026 | // output and request another temp. |
| 3027 | if (div->InputAt(1)->IsConstant()) { |
| 3028 | locations->AddTemp(Location::RequiresRegister()); |
| 3029 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3030 | break; |
| 3031 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3032 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3033 | case Primitive::kPrimFloat: |
| 3034 | case Primitive::kPrimDouble: { |
| 3035 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3036 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3037 | locations->SetOut(Location::SameAsFirstInput()); |
| 3038 | break; |
| 3039 | } |
| 3040 | |
| 3041 | default: |
| 3042 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3047 | LocationSummary* locations = div->GetLocations(); |
| 3048 | Location first = locations->InAt(0); |
| 3049 | Location second = locations->InAt(1); |
| 3050 | DCHECK(first.Equals(locations->Out())); |
| 3051 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3052 | Primitive::Type type = div->GetResultType(); |
| 3053 | switch (type) { |
| 3054 | case Primitive::kPrimInt: |
| 3055 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3056 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3057 | break; |
| 3058 | } |
| 3059 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3060 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3061 | if (second.IsFpuRegister()) { |
| 3062 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3063 | } else if (second.IsConstant()) { |
| 3064 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3065 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3066 | } else { |
| 3067 | DCHECK(second.IsStackSlot()); |
| 3068 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3069 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3070 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3071 | break; |
| 3072 | } |
| 3073 | |
| 3074 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3075 | if (second.IsFpuRegister()) { |
| 3076 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3077 | } else if (second.IsConstant()) { |
| 3078 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3079 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3080 | } else { |
| 3081 | DCHECK(second.IsDoubleStackSlot()); |
| 3082 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3083 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3084 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3085 | break; |
| 3086 | } |
| 3087 | |
| 3088 | default: |
| 3089 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3090 | } |
| 3091 | } |
| 3092 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3093 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3094 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3095 | LocationSummary* locations = |
| 3096 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3097 | |
| 3098 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3099 | case Primitive::kPrimInt: |
| 3100 | case Primitive::kPrimLong: { |
| 3101 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3102 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3103 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3104 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3105 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3106 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3107 | // output and request another temp. |
| 3108 | if (rem->InputAt(1)->IsConstant()) { |
| 3109 | locations->AddTemp(Location::RequiresRegister()); |
| 3110 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3111 | break; |
| 3112 | } |
| 3113 | |
| 3114 | case Primitive::kPrimFloat: |
| 3115 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3116 | locations->SetInAt(0, Location::Any()); |
| 3117 | locations->SetInAt(1, Location::Any()); |
| 3118 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3119 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3120 | break; |
| 3121 | } |
| 3122 | |
| 3123 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3124 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3129 | Primitive::Type type = rem->GetResultType(); |
| 3130 | switch (type) { |
| 3131 | case Primitive::kPrimInt: |
| 3132 | case Primitive::kPrimLong: { |
| 3133 | GenerateDivRemIntegral(rem); |
| 3134 | break; |
| 3135 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3136 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3137 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3138 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3139 | break; |
| 3140 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3141 | default: |
| 3142 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3143 | } |
| 3144 | } |
| 3145 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3146 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3147 | LocationSummary* locations = |
| 3148 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3149 | locations->SetInAt(0, Location::Any()); |
| 3150 | if (instruction->HasUses()) { |
| 3151 | locations->SetOut(Location::SameAsFirstInput()); |
| 3152 | } |
| 3153 | } |
| 3154 | |
| 3155 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3156 | SlowPathCodeX86_64* slow_path = |
| 3157 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3158 | codegen_->AddSlowPath(slow_path); |
| 3159 | |
| 3160 | LocationSummary* locations = instruction->GetLocations(); |
| 3161 | Location value = locations->InAt(0); |
| 3162 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3163 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3164 | case Primitive::kPrimByte: |
| 3165 | case Primitive::kPrimChar: |
| 3166 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3167 | case Primitive::kPrimInt: { |
| 3168 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3169 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3170 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3171 | } else if (value.IsStackSlot()) { |
| 3172 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3173 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3174 | } else { |
| 3175 | DCHECK(value.IsConstant()) << value; |
| 3176 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3177 | __ jmp(slow_path->GetEntryLabel()); |
| 3178 | } |
| 3179 | } |
| 3180 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3181 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3182 | case Primitive::kPrimLong: { |
| 3183 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3184 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3185 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3186 | } else if (value.IsDoubleStackSlot()) { |
| 3187 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3188 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3189 | } else { |
| 3190 | DCHECK(value.IsConstant()) << value; |
| 3191 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3192 | __ jmp(slow_path->GetEntryLabel()); |
| 3193 | } |
| 3194 | } |
| 3195 | break; |
| 3196 | } |
| 3197 | default: |
| 3198 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3199 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3202 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3203 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3204 | |
| 3205 | LocationSummary* locations = |
| 3206 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3207 | |
| 3208 | switch (op->GetResultType()) { |
| 3209 | case Primitive::kPrimInt: |
| 3210 | case Primitive::kPrimLong: { |
| 3211 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3212 | // The shift count needs to be in CL. |
| 3213 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3214 | locations->SetOut(Location::SameAsFirstInput()); |
| 3215 | break; |
| 3216 | } |
| 3217 | default: |
| 3218 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3219 | } |
| 3220 | } |
| 3221 | |
| 3222 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3223 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3224 | |
| 3225 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3226 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3227 | Location second = locations->InAt(1); |
| 3228 | |
| 3229 | switch (op->GetResultType()) { |
| 3230 | case Primitive::kPrimInt: { |
| 3231 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3232 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3233 | if (op->IsShl()) { |
| 3234 | __ shll(first_reg, second_reg); |
| 3235 | } else if (op->IsShr()) { |
| 3236 | __ sarl(first_reg, second_reg); |
| 3237 | } else { |
| 3238 | __ shrl(first_reg, second_reg); |
| 3239 | } |
| 3240 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3241 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3242 | if (op->IsShl()) { |
| 3243 | __ shll(first_reg, imm); |
| 3244 | } else if (op->IsShr()) { |
| 3245 | __ sarl(first_reg, imm); |
| 3246 | } else { |
| 3247 | __ shrl(first_reg, imm); |
| 3248 | } |
| 3249 | } |
| 3250 | break; |
| 3251 | } |
| 3252 | case Primitive::kPrimLong: { |
| 3253 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3254 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3255 | if (op->IsShl()) { |
| 3256 | __ shlq(first_reg, second_reg); |
| 3257 | } else if (op->IsShr()) { |
| 3258 | __ sarq(first_reg, second_reg); |
| 3259 | } else { |
| 3260 | __ shrq(first_reg, second_reg); |
| 3261 | } |
| 3262 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3263 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3264 | if (op->IsShl()) { |
| 3265 | __ shlq(first_reg, imm); |
| 3266 | } else if (op->IsShr()) { |
| 3267 | __ sarq(first_reg, imm); |
| 3268 | } else { |
| 3269 | __ shrq(first_reg, imm); |
| 3270 | } |
| 3271 | } |
| 3272 | break; |
| 3273 | } |
| 3274 | default: |
| 3275 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3280 | HandleShift(shl); |
| 3281 | } |
| 3282 | |
| 3283 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3284 | HandleShift(shl); |
| 3285 | } |
| 3286 | |
| 3287 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3288 | HandleShift(shr); |
| 3289 | } |
| 3290 | |
| 3291 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3292 | HandleShift(shr); |
| 3293 | } |
| 3294 | |
| 3295 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3296 | HandleShift(ushr); |
| 3297 | } |
| 3298 | |
| 3299 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3300 | HandleShift(ushr); |
| 3301 | } |
| 3302 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3303 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3304 | LocationSummary* locations = |
| 3305 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3306 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3307 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3308 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3309 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3313 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3314 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3315 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3316 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3317 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3318 | |
| 3319 | codegen_->InvokeRuntime( |
| 3320 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true), |
| 3321 | instruction, |
| 3322 | instruction->GetDexPc(), |
| 3323 | nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3324 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3325 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3326 | } |
| 3327 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3328 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3329 | LocationSummary* locations = |
| 3330 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3331 | InvokeRuntimeCallingConvention calling_convention; |
| 3332 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3333 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3334 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3335 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3339 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3340 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3341 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3342 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3343 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3344 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3345 | codegen_->InvokeRuntime( |
| 3346 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true), |
| 3347 | instruction, |
| 3348 | instruction->GetDexPc(), |
| 3349 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3350 | |
| 3351 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3352 | } |
| 3353 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3354 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3355 | LocationSummary* locations = |
| 3356 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3357 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3358 | if (location.IsStackSlot()) { |
| 3359 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3360 | } else if (location.IsDoubleStackSlot()) { |
| 3361 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3362 | } |
| 3363 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3364 | } |
| 3365 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3366 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3367 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3368 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3372 | LocationSummary* locations = |
| 3373 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3374 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3375 | } |
| 3376 | |
| 3377 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3378 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3379 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3380 | } |
| 3381 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3382 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3383 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3384 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3385 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3386 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3387 | } |
| 3388 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3389 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3390 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3391 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3392 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3393 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3394 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3395 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3396 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3397 | break; |
| 3398 | |
| 3399 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3400 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3401 | break; |
| 3402 | |
| 3403 | default: |
| 3404 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3405 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3406 | } |
| 3407 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3408 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3409 | LocationSummary* locations = |
| 3410 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3411 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3412 | locations->SetOut(Location::SameAsFirstInput()); |
| 3413 | } |
| 3414 | |
| 3415 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3416 | LocationSummary* locations = bool_not->GetLocations(); |
| 3417 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3418 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3419 | Location out = locations->Out(); |
| 3420 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3421 | } |
| 3422 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3423 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3424 | LocationSummary* locations = |
| 3425 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3426 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3427 | locations->SetInAt(i, Location::Any()); |
| 3428 | } |
| 3429 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3433 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3434 | LOG(FATAL) << "Unimplemented"; |
| 3435 | } |
| 3436 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3437 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3438 | /* |
| 3439 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3440 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3441 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3442 | */ |
| 3443 | switch (kind) { |
| 3444 | case MemBarrierKind::kAnyAny: { |
| 3445 | __ mfence(); |
| 3446 | break; |
| 3447 | } |
| 3448 | case MemBarrierKind::kAnyStore: |
| 3449 | case MemBarrierKind::kLoadAny: |
| 3450 | case MemBarrierKind::kStoreStore: { |
| 3451 | // nop |
| 3452 | break; |
| 3453 | } |
| 3454 | default: |
| 3455 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3460 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3461 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3462 | LocationSummary* locations = |
| 3463 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3464 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3465 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3466 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3467 | } else { |
| 3468 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3469 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3473 | const FieldInfo& field_info) { |
| 3474 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3475 | |
| 3476 | LocationSummary* locations = instruction->GetLocations(); |
| 3477 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3478 | Location out = locations->Out(); |
| 3479 | bool is_volatile = field_info.IsVolatile(); |
| 3480 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3481 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3482 | |
| 3483 | switch (field_type) { |
| 3484 | case Primitive::kPrimBoolean: { |
| 3485 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3486 | break; |
| 3487 | } |
| 3488 | |
| 3489 | case Primitive::kPrimByte: { |
| 3490 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3491 | break; |
| 3492 | } |
| 3493 | |
| 3494 | case Primitive::kPrimShort: { |
| 3495 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3496 | break; |
| 3497 | } |
| 3498 | |
| 3499 | case Primitive::kPrimChar: { |
| 3500 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3501 | break; |
| 3502 | } |
| 3503 | |
| 3504 | case Primitive::kPrimInt: |
| 3505 | case Primitive::kPrimNot: { |
| 3506 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3507 | break; |
| 3508 | } |
| 3509 | |
| 3510 | case Primitive::kPrimLong: { |
| 3511 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3512 | break; |
| 3513 | } |
| 3514 | |
| 3515 | case Primitive::kPrimFloat: { |
| 3516 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3517 | break; |
| 3518 | } |
| 3519 | |
| 3520 | case Primitive::kPrimDouble: { |
| 3521 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3522 | break; |
| 3523 | } |
| 3524 | |
| 3525 | case Primitive::kPrimVoid: |
| 3526 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3527 | UNREACHABLE(); |
| 3528 | } |
| 3529 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3530 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3531 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3532 | if (is_volatile) { |
| 3533 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3534 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3535 | |
| 3536 | if (field_type == Primitive::kPrimNot) { |
| 3537 | __ MaybeUnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 3538 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 3542 | const FieldInfo& field_info) { |
| 3543 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3544 | |
| 3545 | LocationSummary* locations = |
| 3546 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3547 | Primitive::Type field_type = field_info.GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3548 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3549 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3550 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3551 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3552 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 3553 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3554 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3555 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3556 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3557 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3558 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3559 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3560 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3561 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3562 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3563 | locations->AddTemp(Location::RequiresRegister()); |
| 3564 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3565 | } |
| 3566 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3567 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3568 | const FieldInfo& field_info, |
| 3569 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3570 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3571 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3572 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3573 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3574 | Location value = locations->InAt(1); |
| 3575 | bool is_volatile = field_info.IsVolatile(); |
| 3576 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3577 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3578 | |
| 3579 | if (is_volatile) { |
| 3580 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3581 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3582 | |
| 3583 | switch (field_type) { |
| 3584 | case Primitive::kPrimBoolean: |
| 3585 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3586 | if (value.IsConstant()) { |
| 3587 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3588 | __ movb(Address(base, offset), Immediate(v)); |
| 3589 | } else { |
| 3590 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3591 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3592 | break; |
| 3593 | } |
| 3594 | |
| 3595 | case Primitive::kPrimShort: |
| 3596 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3597 | if (value.IsConstant()) { |
| 3598 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3599 | __ movw(Address(base, offset), Immediate(v)); |
| 3600 | } else { |
| 3601 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3602 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3603 | break; |
| 3604 | } |
| 3605 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3606 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3607 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3608 | if (value.IsConstant()) { |
| 3609 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3610 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 3611 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 3612 | // Note: if heap poisoning is enabled, no need to poison |
| 3613 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 3614 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3615 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3616 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3617 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3618 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3619 | __ PoisonHeapReference(temp); |
| 3620 | __ movl(Address(base, offset), temp); |
| 3621 | } else { |
| 3622 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3623 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3624 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3625 | break; |
| 3626 | } |
| 3627 | |
| 3628 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3629 | if (value.IsConstant()) { |
| 3630 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3631 | DCHECK(IsInt<32>(v)); |
| 3632 | int32_t v_32 = v; |
| 3633 | __ movq(Address(base, offset), Immediate(v_32)); |
| 3634 | } else { |
| 3635 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3636 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3637 | break; |
| 3638 | } |
| 3639 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3640 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3641 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3642 | break; |
| 3643 | } |
| 3644 | |
| 3645 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3646 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3647 | break; |
| 3648 | } |
| 3649 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3650 | case Primitive::kPrimVoid: |
| 3651 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3652 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3653 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3654 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3655 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3656 | |
| 3657 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3658 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3659 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3660 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3661 | } |
| 3662 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3663 | if (is_volatile) { |
| 3664 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3669 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3670 | } |
| 3671 | |
| 3672 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3673 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3677 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3681 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3682 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3683 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3684 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3685 | HandleFieldGet(instruction); |
| 3686 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3687 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3688 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3689 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3690 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3691 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3692 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3693 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3694 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3695 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3696 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3697 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3701 | LocationSummary* locations = |
| 3702 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3703 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3704 | ? Location::RequiresRegister() |
| 3705 | : Location::Any(); |
| 3706 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3707 | if (instruction->HasUses()) { |
| 3708 | locations->SetOut(Location::SameAsFirstInput()); |
| 3709 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3710 | } |
| 3711 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3712 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3713 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3714 | return; |
| 3715 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3716 | LocationSummary* locations = instruction->GetLocations(); |
| 3717 | Location obj = locations->InAt(0); |
| 3718 | |
| 3719 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 3720 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3721 | } |
| 3722 | |
| 3723 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3724 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3725 | codegen_->AddSlowPath(slow_path); |
| 3726 | |
| 3727 | LocationSummary* locations = instruction->GetLocations(); |
| 3728 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3729 | |
| 3730 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3731 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3732 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3733 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3734 | } else { |
| 3735 | DCHECK(obj.IsConstant()) << obj; |
| 3736 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 3737 | __ jmp(slow_path->GetEntryLabel()); |
| 3738 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3739 | } |
| 3740 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3741 | } |
| 3742 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3743 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| 3744 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3745 | GenerateImplicitNullCheck(instruction); |
| 3746 | } else { |
| 3747 | GenerateExplicitNullCheck(instruction); |
| 3748 | } |
| 3749 | } |
| 3750 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3751 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3752 | LocationSummary* locations = |
| 3753 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3754 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3755 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3756 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3757 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3758 | } else { |
| 3759 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3760 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 3764 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3765 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3766 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3767 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3768 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3769 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3770 | case Primitive::kPrimBoolean: { |
| 3771 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3772 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3773 | if (index.IsConstant()) { |
| 3774 | __ movzxb(out, Address(obj, |
| 3775 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3776 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3777 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3778 | } |
| 3779 | break; |
| 3780 | } |
| 3781 | |
| 3782 | case Primitive::kPrimByte: { |
| 3783 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3784 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3785 | if (index.IsConstant()) { |
| 3786 | __ movsxb(out, Address(obj, |
| 3787 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3788 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3789 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3790 | } |
| 3791 | break; |
| 3792 | } |
| 3793 | |
| 3794 | case Primitive::kPrimShort: { |
| 3795 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3796 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3797 | if (index.IsConstant()) { |
| 3798 | __ movsxw(out, Address(obj, |
| 3799 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3800 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3801 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3802 | } |
| 3803 | break; |
| 3804 | } |
| 3805 | |
| 3806 | case Primitive::kPrimChar: { |
| 3807 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3808 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3809 | if (index.IsConstant()) { |
| 3810 | __ movzxw(out, Address(obj, |
| 3811 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3812 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3813 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3814 | } |
| 3815 | break; |
| 3816 | } |
| 3817 | |
| 3818 | case Primitive::kPrimInt: |
| 3819 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 3820 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 3821 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3822 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3823 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3824 | if (index.IsConstant()) { |
| 3825 | __ movl(out, Address(obj, |
| 3826 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3827 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3828 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3829 | } |
| 3830 | break; |
| 3831 | } |
| 3832 | |
| 3833 | case Primitive::kPrimLong: { |
| 3834 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3835 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3836 | if (index.IsConstant()) { |
| 3837 | __ movq(out, Address(obj, |
| 3838 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3839 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3840 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3841 | } |
| 3842 | break; |
| 3843 | } |
| 3844 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3845 | case Primitive::kPrimFloat: { |
| 3846 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3847 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3848 | if (index.IsConstant()) { |
| 3849 | __ movss(out, Address(obj, |
| 3850 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3851 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3852 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3853 | } |
| 3854 | break; |
| 3855 | } |
| 3856 | |
| 3857 | case Primitive::kPrimDouble: { |
| 3858 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3859 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3860 | if (index.IsConstant()) { |
| 3861 | __ movsd(out, Address(obj, |
| 3862 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3863 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3864 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3865 | } |
| 3866 | break; |
| 3867 | } |
| 3868 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3869 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3870 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3871 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3872 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3873 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3874 | |
| 3875 | if (type == Primitive::kPrimNot) { |
| 3876 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3877 | __ MaybeUnpoisonHeapReference(out); |
| 3878 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3882 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3883 | |
| 3884 | bool needs_write_barrier = |
| 3885 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3886 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 3887 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3888 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3889 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3890 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3891 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3892 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3893 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3894 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3895 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3896 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3897 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3898 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3899 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3900 | if (value_type == Primitive::kPrimLong) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3901 | locations->SetInAt(2, Location::RegisterOrInt32LongConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3902 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 3903 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3904 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3905 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3906 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3907 | |
| 3908 | if (needs_write_barrier) { |
| 3909 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3910 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3911 | locations->AddTemp(Location::RequiresRegister()); |
| 3912 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3913 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 3917 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3918 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3919 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3920 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3921 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3922 | bool needs_runtime_call = locations->WillCall(); |
| 3923 | bool needs_write_barrier = |
| 3924 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3925 | |
| 3926 | switch (value_type) { |
| 3927 | case Primitive::kPrimBoolean: |
| 3928 | case Primitive::kPrimByte: { |
| 3929 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3930 | if (index.IsConstant()) { |
| 3931 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3932 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3933 | __ movb(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3934 | } else { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3935 | __ movb(Address(obj, offset), |
| 3936 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3937 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3938 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3939 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3940 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
| 3941 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3942 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3943 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3944 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3945 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3946 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3947 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3948 | break; |
| 3949 | } |
| 3950 | |
| 3951 | case Primitive::kPrimShort: |
| 3952 | case Primitive::kPrimChar: { |
| 3953 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3954 | if (index.IsConstant()) { |
| 3955 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3956 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3957 | __ movw(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3958 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3959 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3960 | __ movw(Address(obj, offset), |
| 3961 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3962 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3963 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3964 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3965 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3966 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
| 3967 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3968 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3969 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3970 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3971 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3972 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3973 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3974 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3975 | break; |
| 3976 | } |
| 3977 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3978 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3979 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3980 | if (!needs_runtime_call) { |
| 3981 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3982 | if (index.IsConstant()) { |
| 3983 | size_t offset = |
| 3984 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3985 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3986 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 3987 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3988 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3989 | __ PoisonHeapReference(temp); |
| 3990 | __ movl(Address(obj, offset), temp); |
| 3991 | } else { |
| 3992 | __ movl(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 3993 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3994 | } else { |
| 3995 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3996 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3997 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 3998 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 3999 | // Note: if heap poisoning is enabled, no need to poison |
| 4000 | // (negate) `v` if it is a reference, as it would be null. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4001 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4002 | } |
| 4003 | } else { |
| 4004 | DCHECK(index.IsRegister()) << index; |
| 4005 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4006 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4007 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4008 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4009 | __ PoisonHeapReference(temp); |
| 4010 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), temp); |
| 4011 | } else { |
| 4012 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 4013 | value.AsRegister<CpuRegister>()); |
| 4014 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4015 | } else { |
| 4016 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4017 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4018 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4019 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4020 | // Note: if heap poisoning is enabled, no need to poison |
| 4021 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4022 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4023 | Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4024 | } |
| 4025 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4026 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4027 | if (needs_write_barrier) { |
| 4028 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4029 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4030 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4031 | codegen_->MarkGCCard( |
| 4032 | temp, card, obj, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4033 | } |
| 4034 | } else { |
| 4035 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4036 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4037 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4038 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4039 | instruction, |
| 4040 | instruction->GetDexPc(), |
| 4041 | nullptr); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4042 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4043 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4044 | break; |
| 4045 | } |
| 4046 | |
| 4047 | case Primitive::kPrimLong: { |
| 4048 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4049 | if (index.IsConstant()) { |
| 4050 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4051 | if (value.IsRegister()) { |
| 4052 | __ movq(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 4053 | } else { |
| 4054 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4055 | DCHECK(IsInt<32>(v)); |
| 4056 | int32_t v_32 = v; |
| 4057 | __ movq(Address(obj, offset), Immediate(v_32)); |
| 4058 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4059 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4060 | if (value.IsRegister()) { |
| 4061 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4062 | value.AsRegister<CpuRegister>()); |
| 4063 | } else { |
| 4064 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4065 | DCHECK(IsInt<32>(v)); |
| 4066 | int32_t v_32 = v; |
| 4067 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4068 | Immediate(v_32)); |
| 4069 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4070 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4071 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4072 | break; |
| 4073 | } |
| 4074 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4075 | case Primitive::kPrimFloat: { |
| 4076 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4077 | if (index.IsConstant()) { |
| 4078 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4079 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4080 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4081 | } else { |
| 4082 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4083 | __ movss(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 4084 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4085 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4086 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4087 | break; |
| 4088 | } |
| 4089 | |
| 4090 | case Primitive::kPrimDouble: { |
| 4091 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4092 | if (index.IsConstant()) { |
| 4093 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4094 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4095 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4096 | } else { |
| 4097 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4098 | __ movsd(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4099 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4100 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4101 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4102 | break; |
| 4103 | } |
| 4104 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4105 | case Primitive::kPrimVoid: |
| 4106 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4107 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4112 | LocationSummary* locations = |
| 4113 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4114 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4115 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4119 | LocationSummary* locations = instruction->GetLocations(); |
| 4120 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4121 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4122 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4123 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4124 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4128 | LocationSummary* locations = |
| 4129 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4130 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4131 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4132 | if (instruction->HasUses()) { |
| 4133 | locations->SetOut(Location::SameAsFirstInput()); |
| 4134 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4138 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4139 | Location index_loc = locations->InAt(0); |
| 4140 | Location length_loc = locations->InAt(1); |
| 4141 | SlowPathCodeX86_64* slow_path = |
| 4142 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction, index_loc, length_loc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4143 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4144 | if (length_loc.IsConstant()) { |
| 4145 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4146 | if (index_loc.IsConstant()) { |
| 4147 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4148 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4149 | if (index < 0 || index >= length) { |
| 4150 | codegen_->AddSlowPath(slow_path); |
| 4151 | __ jmp(slow_path->GetEntryLabel()); |
| 4152 | } else { |
| 4153 | // Some optimization after BCE may have generated this, and we should not |
| 4154 | // generate a bounds check if it is a valid range. |
| 4155 | } |
| 4156 | return; |
| 4157 | } |
| 4158 | |
| 4159 | // We have to reverse the jump condition because the length is the constant. |
| 4160 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4161 | __ cmpl(index_reg, Immediate(length)); |
| 4162 | codegen_->AddSlowPath(slow_path); |
| 4163 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4164 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4165 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4166 | if (index_loc.IsConstant()) { |
| 4167 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4168 | __ cmpl(length, Immediate(value)); |
| 4169 | } else { |
| 4170 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4171 | } |
| 4172 | codegen_->AddSlowPath(slow_path); |
| 4173 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4174 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4178 | CpuRegister card, |
| 4179 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4180 | CpuRegister value, |
| 4181 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4182 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4183 | if (value_can_be_null) { |
| 4184 | __ testl(value, value); |
| 4185 | __ j(kEqual, &is_null); |
| 4186 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4187 | __ gs()->movq(card, Address::Absolute( |
| 4188 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4189 | __ movq(temp, object); |
| 4190 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4191 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4192 | if (value_can_be_null) { |
| 4193 | __ Bind(&is_null); |
| 4194 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4195 | } |
| 4196 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4197 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4198 | temp->SetLocations(nullptr); |
| 4199 | } |
| 4200 | |
| 4201 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 4202 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4203 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4204 | } |
| 4205 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4206 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4207 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4208 | LOG(FATAL) << "Unimplemented"; |
| 4209 | } |
| 4210 | |
| 4211 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4212 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4213 | } |
| 4214 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4215 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4216 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4217 | } |
| 4218 | |
| 4219 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4220 | HBasicBlock* block = instruction->GetBlock(); |
| 4221 | if (block->GetLoopInformation() != nullptr) { |
| 4222 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4223 | // The back edge will generate the suspend check. |
| 4224 | return; |
| 4225 | } |
| 4226 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4227 | // The goto will generate the suspend check. |
| 4228 | return; |
| 4229 | } |
| 4230 | GenerateSuspendCheck(instruction, nullptr); |
| 4231 | } |
| 4232 | |
| 4233 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4234 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4235 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4236 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4237 | if (slow_path == nullptr) { |
| 4238 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4239 | instruction->SetSlowPath(slow_path); |
| 4240 | codegen_->AddSlowPath(slow_path); |
| 4241 | if (successor != nullptr) { |
| 4242 | DCHECK(successor->IsLoopHeader()); |
| 4243 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4244 | } |
| 4245 | } else { |
| 4246 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4247 | } |
| 4248 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4249 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4250 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4251 | if (successor == nullptr) { |
| 4252 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4253 | __ Bind(slow_path->GetReturnLabel()); |
| 4254 | } else { |
| 4255 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4256 | __ jmp(slow_path->GetEntryLabel()); |
| 4257 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4258 | } |
| 4259 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4260 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4261 | return codegen_->GetAssembler(); |
| 4262 | } |
| 4263 | |
| 4264 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 4265 | MoveOperands* move = moves_.Get(index); |
| 4266 | Location source = move->GetSource(); |
| 4267 | Location destination = move->GetDestination(); |
| 4268 | |
| 4269 | if (source.IsRegister()) { |
| 4270 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4271 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4272 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4273 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4274 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4275 | } else { |
| 4276 | DCHECK(destination.IsDoubleStackSlot()); |
| 4277 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4278 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4279 | } |
| 4280 | } else if (source.IsStackSlot()) { |
| 4281 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4282 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4283 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4284 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4285 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4286 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4287 | } else { |
| 4288 | DCHECK(destination.IsStackSlot()); |
| 4289 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4290 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4291 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4292 | } else if (source.IsDoubleStackSlot()) { |
| 4293 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4294 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4295 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4296 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4297 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4298 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4299 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4300 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4301 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4302 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4303 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4304 | } else if (source.IsConstant()) { |
| 4305 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4306 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4307 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4308 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4309 | if (value == 0) { |
| 4310 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4311 | } else { |
| 4312 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4313 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4314 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4315 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4316 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4317 | } |
| 4318 | } else if (constant->IsLongConstant()) { |
| 4319 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4320 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4321 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4322 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4323 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4324 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4325 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4326 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4327 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4328 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4329 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4330 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4331 | if (value == 0) { |
| 4332 | // easy FP 0.0. |
| 4333 | __ xorps(dest, dest); |
| 4334 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4335 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4336 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4337 | } else { |
| 4338 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4339 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4340 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4341 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4342 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4343 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4344 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4345 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4346 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4347 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4348 | if (value == 0) { |
| 4349 | __ xorpd(dest, dest); |
| 4350 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4351 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4352 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4353 | } else { |
| 4354 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4355 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4356 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4357 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4358 | } else if (source.IsFpuRegister()) { |
| 4359 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4360 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4361 | } else if (destination.IsStackSlot()) { |
| 4362 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4363 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4364 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 4365 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4366 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4367 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4368 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4369 | } |
| 4370 | } |
| 4371 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4372 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4373 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4374 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 4375 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4378 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4379 | ScratchRegisterScope ensure_scratch( |
| 4380 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 4381 | |
| 4382 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4383 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4384 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 4385 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4386 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4387 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4388 | CpuRegister(ensure_scratch.GetRegister())); |
| 4389 | } |
| 4390 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4391 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 4392 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4393 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 4394 | __ movq(reg, CpuRegister(TMP)); |
| 4395 | } |
| 4396 | |
| 4397 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 4398 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4399 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4400 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4401 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4402 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4403 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 4404 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4405 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4406 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4407 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4408 | } |
| 4409 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4410 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 4411 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4412 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 4413 | __ movd(reg, CpuRegister(TMP)); |
| 4414 | } |
| 4415 | |
| 4416 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 4417 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4418 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 4419 | __ movd(reg, CpuRegister(TMP)); |
| 4420 | } |
| 4421 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4422 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 4423 | MoveOperands* move = moves_.Get(index); |
| 4424 | Location source = move->GetSource(); |
| 4425 | Location destination = move->GetDestination(); |
| 4426 | |
| 4427 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4428 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4429 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4430 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4431 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4432 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4433 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4434 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4435 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4436 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4437 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4438 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4439 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 4440 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4441 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4442 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 4443 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4444 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4445 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4446 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4447 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4448 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4449 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4450 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4451 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4452 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4453 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4454 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4455 | } |
| 4456 | } |
| 4457 | |
| 4458 | |
| 4459 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 4460 | __ pushq(CpuRegister(reg)); |
| 4461 | } |
| 4462 | |
| 4463 | |
| 4464 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 4465 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4466 | } |
| 4467 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4468 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| 4469 | SlowPathCodeX86_64* slow_path, CpuRegister class_reg) { |
| 4470 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4471 | Immediate(mirror::Class::kStatusInitialized)); |
| 4472 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4473 | __ Bind(slow_path->GetExitLabel()); |
| 4474 | // No need for memory fence, thanks to the X86_64 memory model. |
| 4475 | } |
| 4476 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4477 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4478 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4479 | ? LocationSummary::kCallOnSlowPath |
| 4480 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4481 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4482 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4483 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4484 | locations->SetOut(Location::RequiresRegister()); |
| 4485 | } |
| 4486 | |
| 4487 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4488 | LocationSummary* locations = cls->GetLocations(); |
| 4489 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4490 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4491 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4492 | DCHECK(!cls->CanCallRuntime()); |
| 4493 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4494 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4495 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4496 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4497 | __ movl(out, Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4498 | current_method, ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4499 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4500 | __ MaybeUnpoisonHeapReference(out); |
| 4501 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4502 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4503 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4504 | codegen_->AddSlowPath(slow_path); |
| 4505 | __ testl(out, out); |
| 4506 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4507 | if (cls->MustGenerateClinitCheck()) { |
| 4508 | GenerateClassInitializationCheck(slow_path, out); |
| 4509 | } else { |
| 4510 | __ Bind(slow_path->GetExitLabel()); |
| 4511 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4512 | } |
| 4513 | } |
| 4514 | |
| 4515 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 4516 | LocationSummary* locations = |
| 4517 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4518 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4519 | if (check->HasUses()) { |
| 4520 | locations->SetOut(Location::SameAsFirstInput()); |
| 4521 | } |
| 4522 | } |
| 4523 | |
| 4524 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4525 | // We assume the class to not be null. |
| 4526 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4527 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4528 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4529 | GenerateClassInitializationCheck(slow_path, |
| 4530 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4531 | } |
| 4532 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4533 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 4534 | LocationSummary* locations = |
| 4535 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4536 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4537 | locations->SetOut(Location::RequiresRegister()); |
| 4538 | } |
| 4539 | |
| 4540 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
| 4541 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 4542 | codegen_->AddSlowPath(slow_path); |
| 4543 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4544 | LocationSummary* locations = load->GetLocations(); |
| 4545 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4546 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4547 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4548 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4549 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4550 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4551 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4552 | __ testl(out, out); |
| 4553 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4554 | __ Bind(slow_path->GetExitLabel()); |
| 4555 | } |
| 4556 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4557 | static Address GetExceptionTlsAddress() { |
| 4558 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 4559 | } |
| 4560 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4561 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 4562 | LocationSummary* locations = |
| 4563 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4564 | locations->SetOut(Location::RequiresRegister()); |
| 4565 | } |
| 4566 | |
| 4567 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4568 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 4569 | } |
| 4570 | |
| 4571 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 4572 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4573 | } |
| 4574 | |
| 4575 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4576 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 4580 | LocationSummary* locations = |
| 4581 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4582 | InvokeRuntimeCallingConvention calling_convention; |
| 4583 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4584 | } |
| 4585 | |
| 4586 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4587 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4588 | instruction, |
| 4589 | instruction->GetDexPc(), |
| 4590 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4593 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4594 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4595 | ? LocationSummary::kNoCall |
| 4596 | : LocationSummary::kCallOnSlowPath; |
| 4597 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4598 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4599 | locations->SetInAt(1, Location::Any()); |
| 4600 | locations->SetOut(Location::RequiresRegister()); |
| 4601 | } |
| 4602 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4603 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4604 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4605 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4606 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4607 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4608 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4609 | Label done, zero; |
| 4610 | SlowPathCodeX86_64* slow_path = nullptr; |
| 4611 | |
| 4612 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4613 | // Avoid null check if we know obj is not null. |
| 4614 | if (instruction->MustDoNullCheck()) { |
| 4615 | __ testl(obj, obj); |
| 4616 | __ j(kEqual, &zero); |
| 4617 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4618 | // Compare the class of `obj` with `cls`. |
| 4619 | __ movl(out, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4620 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4621 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4622 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4623 | } else { |
| 4624 | DCHECK(cls.IsStackSlot()) << cls; |
| 4625 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4626 | } |
| 4627 | if (instruction->IsClassFinal()) { |
| 4628 | // Classes must be equal for the instanceof to succeed. |
| 4629 | __ j(kNotEqual, &zero); |
| 4630 | __ movl(out, Immediate(1)); |
| 4631 | __ jmp(&done); |
| 4632 | } else { |
| 4633 | // If the classes are not equal, we go into a slow path. |
| 4634 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4635 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4636 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4637 | codegen_->AddSlowPath(slow_path); |
| 4638 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4639 | __ movl(out, Immediate(1)); |
| 4640 | __ jmp(&done); |
| 4641 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4642 | |
| 4643 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4644 | __ Bind(&zero); |
| 4645 | __ movl(out, Immediate(0)); |
| 4646 | } |
| 4647 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4648 | if (slow_path != nullptr) { |
| 4649 | __ Bind(slow_path->GetExitLabel()); |
| 4650 | } |
| 4651 | __ Bind(&done); |
| 4652 | } |
| 4653 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4654 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4655 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4656 | instruction, LocationSummary::kCallOnSlowPath); |
| 4657 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4658 | locations->SetInAt(1, Location::Any()); |
| 4659 | locations->AddTemp(Location::RequiresRegister()); |
| 4660 | } |
| 4661 | |
| 4662 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4663 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4664 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4665 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4666 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4667 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4668 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 4669 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 4670 | codegen_->AddSlowPath(slow_path); |
| 4671 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4672 | // Avoid null check if we know obj is not null. |
| 4673 | if (instruction->MustDoNullCheck()) { |
| 4674 | __ testl(obj, obj); |
| 4675 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4676 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4677 | // Compare the class of `obj` with `cls`. |
| 4678 | __ movl(temp, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4679 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4680 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4681 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4682 | } else { |
| 4683 | DCHECK(cls.IsStackSlot()) << cls; |
| 4684 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4685 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4686 | // The checkcast succeeds if the classes are equal (fast path). |
| 4687 | // 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] | 4688 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4689 | __ Bind(slow_path->GetExitLabel()); |
| 4690 | } |
| 4691 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4692 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4693 | LocationSummary* locations = |
| 4694 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4695 | InvokeRuntimeCallingConvention calling_convention; |
| 4696 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4697 | } |
| 4698 | |
| 4699 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4700 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 4701 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 4702 | instruction, |
| 4703 | instruction->GetDexPc(), |
| 4704 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4705 | } |
| 4706 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4707 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4708 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4709 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4710 | |
| 4711 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4712 | LocationSummary* locations = |
| 4713 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4714 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4715 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4716 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4717 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4718 | locations->SetOut(Location::SameAsFirstInput()); |
| 4719 | } |
| 4720 | |
| 4721 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 4722 | HandleBitwiseOperation(instruction); |
| 4723 | } |
| 4724 | |
| 4725 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 4726 | HandleBitwiseOperation(instruction); |
| 4727 | } |
| 4728 | |
| 4729 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 4730 | HandleBitwiseOperation(instruction); |
| 4731 | } |
| 4732 | |
| 4733 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4734 | LocationSummary* locations = instruction->GetLocations(); |
| 4735 | Location first = locations->InAt(0); |
| 4736 | Location second = locations->InAt(1); |
| 4737 | DCHECK(first.Equals(locations->Out())); |
| 4738 | |
| 4739 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 4740 | if (second.IsRegister()) { |
| 4741 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4742 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4743 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4744 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4745 | } else { |
| 4746 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4747 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4748 | } |
| 4749 | } else if (second.IsConstant()) { |
| 4750 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 4751 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4752 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4753 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4754 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4755 | } else { |
| 4756 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4757 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4758 | } |
| 4759 | } else { |
| 4760 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 4761 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4762 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4763 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4764 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4765 | } else { |
| 4766 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4767 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4768 | } |
| 4769 | } |
| 4770 | } else { |
| 4771 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4772 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 4773 | bool second_is_constant = false; |
| 4774 | int64_t value = 0; |
| 4775 | if (second.IsConstant()) { |
| 4776 | second_is_constant = true; |
| 4777 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4778 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4779 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4780 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4781 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4782 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4783 | if (is_int32_value) { |
| 4784 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4785 | } else { |
| 4786 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4787 | } |
| 4788 | } else if (second.IsDoubleStackSlot()) { |
| 4789 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4790 | } else { |
| 4791 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 4792 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4793 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4794 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4795 | if (is_int32_value) { |
| 4796 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4797 | } else { |
| 4798 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4799 | } |
| 4800 | } else if (second.IsDoubleStackSlot()) { |
| 4801 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4802 | } else { |
| 4803 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 4804 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4805 | } else { |
| 4806 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4807 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4808 | if (is_int32_value) { |
| 4809 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4810 | } else { |
| 4811 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4812 | } |
| 4813 | } else if (second.IsDoubleStackSlot()) { |
| 4814 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4815 | } else { |
| 4816 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 4817 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4818 | } |
| 4819 | } |
| 4820 | } |
| 4821 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4822 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction) { |
| 4823 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4824 | UNUSED(instruction); |
| 4825 | LOG(FATAL) << "Unreachable"; |
| 4826 | } |
| 4827 | |
| 4828 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction) { |
| 4829 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4830 | UNUSED(instruction); |
| 4831 | LOG(FATAL) << "Unreachable"; |
| 4832 | } |
| 4833 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4834 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 4835 | DCHECK(codegen_->IsBaseline()); |
| 4836 | LocationSummary* locations = |
| 4837 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4838 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 4839 | } |
| 4840 | |
| 4841 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 4842 | DCHECK(codegen_->IsBaseline()); |
| 4843 | // Will be generated at use site. |
| 4844 | } |
| 4845 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4846 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 4847 | if (value == 0) { |
| 4848 | __ xorl(dest, dest); |
| 4849 | } else if (value > 0 && IsInt<32>(value)) { |
| 4850 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 4851 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 4852 | } else { |
| 4853 | __ movq(dest, Immediate(value)); |
| 4854 | } |
| 4855 | } |
| 4856 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4857 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 4858 | DCHECK(dest.IsDoubleStackSlot()); |
| 4859 | if (IsInt<32>(value)) { |
| 4860 | // Can move directly as an int32 constant. |
| 4861 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 4862 | Immediate(static_cast<int32_t>(value))); |
| 4863 | } else { |
| 4864 | Load64BitValue(CpuRegister(TMP), value); |
| 4865 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 4866 | } |
| 4867 | } |
| 4868 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4869 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 4870 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4871 | X86_64Assembler* assembler = GetAssembler(); |
| 4872 | if (!assembler->IsConstantAreaEmpty()) { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4873 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 4874 | // byte values. If used for vectors at a later time, this will need to be |
| 4875 | // updated to 16 bytes with the appropriate offset. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4876 | assembler->Align(4, 0); |
| 4877 | constant_area_start_ = assembler->CodeSize(); |
| 4878 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | // And finish up. |
| 4882 | CodeGenerator::Finalize(allocator); |
| 4883 | } |
| 4884 | |
| 4885 | /** |
| 4886 | * Class to handle late fixup of offsets into constant area. |
| 4887 | */ |
| 4888 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 4889 | public: |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4890 | RIPFixup(const CodeGeneratorX86_64& codegen, int offset) |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4891 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 4892 | |
| 4893 | private: |
| 4894 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 4895 | // Patch the correct offset for the instruction. We use the address of the |
| 4896 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 4897 | int constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 4898 | int relative_position = constant_offset - pos; |
| 4899 | |
| 4900 | // Patch in the right value. |
| 4901 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 4902 | } |
| 4903 | |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4904 | const CodeGeneratorX86_64& codegen_; |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4905 | |
| 4906 | // Location in constant area that the fixup refers to. |
| 4907 | int offset_into_constant_area_; |
| 4908 | }; |
| 4909 | |
| 4910 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 4911 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 4912 | return Address::RIP(fixup); |
| 4913 | } |
| 4914 | |
| 4915 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 4916 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 4917 | return Address::RIP(fixup); |
| 4918 | } |
| 4919 | |
| 4920 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 4921 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 4922 | return Address::RIP(fixup); |
| 4923 | } |
| 4924 | |
| 4925 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 4926 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 4927 | return Address::RIP(fixup); |
| 4928 | } |
| 4929 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4930 | #undef __ |
| 4931 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4932 | } // namespace x86_64 |
| 4933 | } // namespace art |