Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86_64.h" |
| 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | #include "intrinsics.h" |
| 25 | #include "intrinsics_x86_64.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "mirror/object_reference.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "utils/x86_64/assembler_x86_64.h" |
| 33 | #include "utils/x86_64/managed_register_x86_64.h" |
| 34 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 35 | namespace art { |
| 36 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 37 | namespace x86_64 { |
| 38 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 39 | // Some x86_64 instructions require a register to be available as temp. |
| 40 | static constexpr Register TMP = R11; |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = RDI; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 44 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 45 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 46 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 47 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 48 | static constexpr int kC2ConditionMask = 0x400; |
| 49 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 50 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 51 | #define QUICK_ENTRY_POINT(x) Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x), true) |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 53 | class NullCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 55 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 57 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 58 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 60 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 61 | instruction_, |
| 62 | instruction_->GetDexPc(), |
| 63 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 66 | bool IsFatal() const OVERRIDE { return true; } |
| 67 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 68 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 69 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 71 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 72 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 73 | }; |
| 74 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 75 | class DivZeroCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 76 | public: |
| 77 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 78 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 79 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 80 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 81 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 82 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 83 | instruction_, |
| 84 | instruction_->GetDexPc(), |
| 85 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 88 | bool IsFatal() const OVERRIDE { return true; } |
| 89 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 90 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 91 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | private: |
| 93 | HDivZeroCheck* const instruction_; |
| 94 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 95 | }; |
| 96 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 97 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCodeX86_64 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 99 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 100 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 102 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 104 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 105 | if (is_div_) { |
| 106 | __ negl(cpu_reg_); |
| 107 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 108 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 111 | } else { |
| 112 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negq(cpu_reg_); |
| 115 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 116 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 117 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 118 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | __ jmp(GetExitLabel()); |
| 120 | } |
| 121 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 122 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 123 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 126 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | const bool is_div_; |
| 128 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 131 | class SuspendCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 132 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 133 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 134 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 135 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 136 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 137 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 139 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 140 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 141 | instruction_, |
| 142 | instruction_->GetDexPc(), |
| 143 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 144 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 145 | if (successor_ == nullptr) { |
| 146 | __ jmp(GetReturnLabel()); |
| 147 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 148 | __ jmp(x64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 149 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 152 | Label* GetReturnLabel() { |
| 153 | DCHECK(successor_ == nullptr); |
| 154 | return &return_label_; |
| 155 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 156 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 157 | HBasicBlock* GetSuccessor() const { |
| 158 | return successor_; |
| 159 | } |
| 160 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 161 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 162 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | private: |
| 164 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 165 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 166 | Label return_label_; |
| 167 | |
| 168 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 169 | }; |
| 170 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 171 | class BoundsCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 172 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 173 | BoundsCheckSlowPathX86_64(HBoundsCheck* instruction, |
| 174 | Location index_location, |
| 175 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 176 | : instruction_(instruction), |
| 177 | index_location_(index_location), |
| 178 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 180 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 181 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 182 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 183 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 184 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 185 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 186 | codegen->EmitParallelMoves( |
| 187 | index_location_, |
| 188 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 189 | Primitive::kPrimInt, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 190 | length_location_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 191 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 192 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 193 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 194 | instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 195 | } |
| 196 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 197 | bool IsFatal() const OVERRIDE { return true; } |
| 198 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 199 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 200 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 201 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 202 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 203 | const Location index_location_; |
| 204 | const Location length_location_; |
| 205 | |
| 206 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 207 | }; |
| 208 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 209 | class LoadClassSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 210 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 211 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 212 | HInstruction* at, |
| 213 | uint32_t dex_pc, |
| 214 | bool do_clinit) |
| 215 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 216 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 217 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 218 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 219 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 220 | LocationSummary* locations = at_->GetLocations(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 221 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 222 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 223 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 224 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 225 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 226 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 227 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 228 | x64_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 229 | : QUICK_ENTRY_POINT(pInitializeType), |
| 230 | at_, dex_pc_, this); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 231 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 232 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 233 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 234 | if (out.IsValid()) { |
| 235 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 236 | x64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 239 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | __ jmp(GetExitLabel()); |
| 241 | } |
| 242 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 243 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 244 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 245 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 246 | // The class this slow path will load. |
| 247 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 248 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 249 | // The instruction where this slow path is happening. |
| 250 | // (Might be the load class or an initialization check). |
| 251 | HInstruction* const at_; |
| 252 | |
| 253 | // The dex PC of `at_`. |
| 254 | const uint32_t dex_pc_; |
| 255 | |
| 256 | // Whether to initialize the class. |
| 257 | const bool do_clinit_; |
| 258 | |
| 259 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 260 | }; |
| 261 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 262 | class LoadStringSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 263 | public: |
| 264 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 265 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 266 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 267 | LocationSummary* locations = instruction_->GetLocations(); |
| 268 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 269 | |
| 270 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 271 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 272 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 273 | |
| 274 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 275 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 276 | Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 277 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 278 | instruction_, |
| 279 | instruction_->GetDexPc(), |
| 280 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 281 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 282 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 283 | __ jmp(GetExitLabel()); |
| 284 | } |
| 285 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 286 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 287 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 288 | private: |
| 289 | HLoadString* const instruction_; |
| 290 | |
| 291 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 292 | }; |
| 293 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 294 | class TypeCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 295 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 296 | TypeCheckSlowPathX86_64(HInstruction* instruction, |
| 297 | Location class_to_check, |
| 298 | Location object_class, |
| 299 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 300 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 301 | class_to_check_(class_to_check), |
| 302 | object_class_(object_class), |
| 303 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 304 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 305 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 307 | DCHECK(instruction_->IsCheckCast() |
| 308 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 309 | |
| 310 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 311 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 312 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 313 | |
| 314 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 315 | // move resolver. |
| 316 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 317 | codegen->EmitParallelMoves( |
| 318 | class_to_check_, |
| 319 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 320 | Primitive::kPrimNot, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 321 | object_class_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 322 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 323 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 325 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 326 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 327 | instruction_, |
| 328 | dex_pc_, |
| 329 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | } else { |
| 331 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 332 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 333 | instruction_, |
| 334 | dex_pc_, |
| 335 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 336 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 337 | |
| 338 | if (instruction_->IsInstanceOf()) { |
| 339 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 340 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 341 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 342 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 343 | __ jmp(GetExitLabel()); |
| 344 | } |
| 345 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 346 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 347 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 348 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 349 | HInstruction* const instruction_; |
| 350 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 351 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 352 | const uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 | |
| 354 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 355 | }; |
| 356 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 357 | class DeoptimizationSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 358 | public: |
| 359 | explicit DeoptimizationSlowPathX86_64(HInstruction* instruction) |
| 360 | : instruction_(instruction) {} |
| 361 | |
| 362 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 363 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 364 | __ Bind(GetEntryLabel()); |
| 365 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 366 | DCHECK(instruction_->IsDeoptimize()); |
| 367 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 368 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 369 | deoptimize, |
| 370 | deoptimize->GetDexPc(), |
| 371 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 374 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 375 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 376 | private: |
| 377 | HInstruction* const instruction_; |
| 378 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 379 | }; |
| 380 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 381 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 382 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 383 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 384 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 385 | switch (cond) { |
| 386 | case kCondEQ: return kEqual; |
| 387 | case kCondNE: return kNotEqual; |
| 388 | case kCondLT: return kLess; |
| 389 | case kCondLE: return kLessEqual; |
| 390 | case kCondGT: return kGreater; |
| 391 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 392 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 393 | LOG(FATAL) << "Unreachable"; |
| 394 | UNREACHABLE(); |
| 395 | } |
| 396 | |
| 397 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 398 | switch (cond) { |
| 399 | case kCondEQ: return kEqual; |
| 400 | case kCondNE: return kNotEqual; |
| 401 | case kCondLT: return kBelow; |
| 402 | case kCondLE: return kBelowEqual; |
| 403 | case kCondGT: return kAbove; |
| 404 | case kCondGE: return kAboveEqual; |
| 405 | }; |
| 406 | LOG(FATAL) << "Unreachable"; |
| 407 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 410 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 411 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 412 | // All registers are assumed to be correctly set up. |
| 413 | |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 414 | switch (invoke->GetMethodLoadKind()) { |
| 415 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 416 | // temp = thread->string_init_entrypoint |
| 417 | __ gs()->movl(temp.AsRegister<CpuRegister>(), |
| 418 | Address::Absolute(invoke->GetStringInitOffset(), true)); |
| 419 | break; |
| 420 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 421 | // Nothing to do. |
| 422 | break; |
| 423 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 424 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 425 | break; |
| 426 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 427 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 428 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 429 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 430 | break; |
| 431 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 432 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 433 | invoke->GetDexCacheArrayOffset()); |
| 434 | __ movq(temp.AsRegister<CpuRegister>(), |
| 435 | Address::Absolute(kDummy32BitOffset, false /* no_rip */)); |
| 436 | // Bind the label at the end of the "movl" insn. |
| 437 | __ Bind(&pc_rel_dex_cache_patches_.back().label); |
| 438 | break; |
| 439 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 440 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 441 | Register method_reg; |
| 442 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 443 | if (current_method.IsRegister()) { |
| 444 | method_reg = current_method.AsRegister<Register>(); |
| 445 | } else { |
| 446 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 447 | DCHECK(!current_method.IsValid()); |
| 448 | method_reg = reg.AsRegister(); |
| 449 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 450 | } |
| 451 | // temp = temp->dex_cache_resolved_methods_; |
| 452 | __ movl(reg, Address(CpuRegister(method_reg), |
| 453 | ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
| 454 | // temp = temp[index_in_cache] |
| 455 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 456 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 457 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 458 | } |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 459 | } |
| 460 | |
| 461 | switch (invoke->GetCodePtrLocation()) { |
| 462 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 463 | __ call(&frame_entry_label_); |
| 464 | break; |
| 465 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 466 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 467 | Label* label = &relative_call_patches_.back().label; |
| 468 | __ call(label); // Bind to the patch label, override at link time. |
| 469 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 470 | break; |
| 471 | } |
| 472 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 473 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 474 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 475 | FALLTHROUGH_INTENDED; |
| 476 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 477 | // (temp + offset_of_quick_compiled_code)() |
| 478 | __ call(Address(temp.AsRegister<CpuRegister>(), |
| 479 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 480 | kX86_64WordSize).SizeValue())); |
| 481 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 482 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 483 | |
| 484 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 487 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 488 | DCHECK(linker_patches->empty()); |
| 489 | size_t size = |
| 490 | method_patches_.size() + relative_call_patches_.size() + pc_rel_dex_cache_patches_.size(); |
| 491 | linker_patches->reserve(size); |
| 492 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 493 | // The label points to the end of the "movl" instruction but the literal offset for method |
| 494 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 495 | uint32_t literal_offset = info.label.Position() - 4; |
| 496 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 497 | info.target_method.dex_file, |
| 498 | info.target_method.dex_method_index)); |
| 499 | } |
| 500 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 501 | // The label points to the end of the "call" instruction but the literal offset for method |
| 502 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 503 | uint32_t literal_offset = info.label.Position() - 4; |
| 504 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 505 | info.target_method.dex_file, |
| 506 | info.target_method.dex_method_index)); |
| 507 | } |
| 508 | for (const PcRelativeDexCacheAccessInfo& info : pc_rel_dex_cache_patches_) { |
| 509 | // The label points to the end of the "mov" instruction but the literal offset for method |
| 510 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 511 | uint32_t literal_offset = info.label.Position() - 4; |
| 512 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 513 | &info.target_dex_file, |
| 514 | info.label.Position(), |
| 515 | info.element_offset)); |
| 516 | } |
| 517 | } |
| 518 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 519 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 520 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 524 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 525 | } |
| 526 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 527 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 528 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 529 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 532 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 533 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 534 | return kX86_64WordSize; |
| 535 | } |
| 536 | |
| 537 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 538 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 539 | return kX86_64WordSize; |
| 540 | } |
| 541 | |
| 542 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 543 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 544 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 547 | void CodeGeneratorX86_64::InvokeRuntime(Address entry_point, |
| 548 | HInstruction* instruction, |
| 549 | uint32_t dex_pc, |
| 550 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 551 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 552 | __ gs()->call(entry_point); |
| 553 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 554 | } |
| 555 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 556 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 557 | // Use a fake return address register to mimic Quick. |
| 558 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 559 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| 560 | const X86_64InstructionSetFeatures& isa_features, |
| 561 | const CompilerOptions& compiler_options) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 562 | : CodeGenerator(graph, |
| 563 | kNumberOfCpuRegisters, |
| 564 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 565 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 566 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 567 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 568 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 569 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 570 | arraysize(kFpuCalleeSaves)), |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 571 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 572 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 573 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 574 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 575 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 576 | isa_features_(isa_features), |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 577 | constant_area_start_(0), |
| 578 | method_patches_(graph->GetArena()->Adapter()), |
| 579 | relative_call_patches_(graph->GetArena()->Adapter()), |
| 580 | pc_rel_dex_cache_patches_(graph->GetArena()->Adapter()) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 581 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 582 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 583 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 584 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 585 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 586 | : HGraphVisitor(graph), |
| 587 | assembler_(codegen->GetAssembler()), |
| 588 | codegen_(codegen) {} |
| 589 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 590 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 591 | switch (type) { |
| 592 | case Primitive::kPrimLong: |
| 593 | case Primitive::kPrimByte: |
| 594 | case Primitive::kPrimBoolean: |
| 595 | case Primitive::kPrimChar: |
| 596 | case Primitive::kPrimShort: |
| 597 | case Primitive::kPrimInt: |
| 598 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 599 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 600 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 604 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 605 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 606 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 607 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 608 | |
| 609 | case Primitive::kPrimVoid: |
| 610 | LOG(FATAL) << "Unreachable type " << type; |
| 611 | } |
| 612 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 613 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 616 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 617 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 618 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 619 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 620 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 621 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 622 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 623 | if (is_baseline) { |
| 624 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 625 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 626 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 627 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 628 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 629 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 630 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 631 | } |
| 632 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 633 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 634 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 635 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 636 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 637 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 638 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 639 | } |
| 640 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 641 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 642 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 643 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 644 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 645 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 646 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 647 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 648 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 649 | __ testq(CpuRegister(RAX), Address( |
| 650 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 651 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 652 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 653 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 654 | if (HasEmptyFrame()) { |
| 655 | return; |
| 656 | } |
| 657 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 658 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 659 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 660 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 661 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 662 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 663 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 664 | } |
| 665 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 666 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 667 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 668 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 669 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 670 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 671 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 672 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 673 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 674 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 675 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 676 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 677 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 678 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 679 | } |
| 680 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 681 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 682 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 686 | __ cfi().RememberState(); |
| 687 | if (!HasEmptyFrame()) { |
| 688 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 689 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 690 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 691 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 692 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 693 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 694 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 699 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 700 | __ cfi().AdjustCFAOffset(-adjust); |
| 701 | |
| 702 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 703 | Register reg = kCoreCalleeSaves[i]; |
| 704 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 705 | __ popq(CpuRegister(reg)); |
| 706 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 707 | __ cfi().Restore(DWARFReg(reg)); |
| 708 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 709 | } |
| 710 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 711 | __ ret(); |
| 712 | __ cfi().RestoreState(); |
| 713 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 714 | } |
| 715 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 716 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 717 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 718 | } |
| 719 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 720 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 721 | switch (load->GetType()) { |
| 722 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 723 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 724 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 725 | |
| 726 | case Primitive::kPrimInt: |
| 727 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 728 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 729 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 730 | |
| 731 | case Primitive::kPrimBoolean: |
| 732 | case Primitive::kPrimByte: |
| 733 | case Primitive::kPrimChar: |
| 734 | case Primitive::kPrimShort: |
| 735 | case Primitive::kPrimVoid: |
| 736 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 737 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 741 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 745 | if (source.Equals(destination)) { |
| 746 | return; |
| 747 | } |
| 748 | if (destination.IsRegister()) { |
| 749 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 750 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 751 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 752 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 753 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 754 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 755 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 756 | } else { |
| 757 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 758 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 759 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 760 | } |
| 761 | } else if (destination.IsFpuRegister()) { |
| 762 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 763 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 764 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 765 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 766 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 767 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 768 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 769 | } else { |
| 770 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 771 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 772 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 773 | } |
| 774 | } else if (destination.IsStackSlot()) { |
| 775 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 776 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 777 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 778 | } else if (source.IsFpuRegister()) { |
| 779 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 780 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 781 | } else if (source.IsConstant()) { |
| 782 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 783 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 784 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 785 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 786 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 787 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 788 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 789 | } |
| 790 | } else { |
| 791 | DCHECK(destination.IsDoubleStackSlot()); |
| 792 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 793 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 794 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 795 | } else if (source.IsFpuRegister()) { |
| 796 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 797 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 798 | } else if (source.IsConstant()) { |
| 799 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 800 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 801 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 802 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 803 | } else { |
| 804 | DCHECK(constant->IsLongConstant()); |
| 805 | value = constant->AsLongConstant()->GetValue(); |
| 806 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 807 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 808 | } else { |
| 809 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 810 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 811 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | } |
| 815 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 816 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 817 | Location location, |
| 818 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 819 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 820 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 821 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 822 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 823 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 824 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 825 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 826 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 827 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 828 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 829 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 830 | } else if (location.IsStackSlot()) { |
| 831 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 832 | } else { |
| 833 | DCHECK(location.IsConstant()); |
| 834 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 835 | } |
| 836 | } else if (const_to_move->IsLongConstant()) { |
| 837 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 838 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 839 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 840 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 841 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 842 | } else { |
| 843 | DCHECK(location.IsConstant()); |
| 844 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 845 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 846 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 847 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 848 | switch (instruction->GetType()) { |
| 849 | case Primitive::kPrimBoolean: |
| 850 | case Primitive::kPrimByte: |
| 851 | case Primitive::kPrimChar: |
| 852 | case Primitive::kPrimShort: |
| 853 | case Primitive::kPrimInt: |
| 854 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 855 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 856 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 857 | break; |
| 858 | |
| 859 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 860 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 861 | Move(location, |
| 862 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 863 | break; |
| 864 | |
| 865 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 866 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 867 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 868 | } else if (instruction->IsTemporary()) { |
| 869 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 870 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 871 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 872 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 873 | switch (instruction->GetType()) { |
| 874 | case Primitive::kPrimBoolean: |
| 875 | case Primitive::kPrimByte: |
| 876 | case Primitive::kPrimChar: |
| 877 | case Primitive::kPrimShort: |
| 878 | case Primitive::kPrimInt: |
| 879 | case Primitive::kPrimNot: |
| 880 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 881 | case Primitive::kPrimFloat: |
| 882 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 883 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 884 | break; |
| 885 | |
| 886 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 887 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | } |
| 891 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 892 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 893 | DCHECK(!successor->IsExitBlock()); |
| 894 | |
| 895 | HBasicBlock* block = got->GetBlock(); |
| 896 | HInstruction* previous = got->GetPrevious(); |
| 897 | |
| 898 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 899 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 900 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 901 | return; |
| 902 | } |
| 903 | |
| 904 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 905 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 906 | } |
| 907 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 908 | __ jmp(codegen_->GetLabelOf(successor)); |
| 909 | } |
| 910 | } |
| 911 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 912 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 913 | got->SetLocations(nullptr); |
| 914 | } |
| 915 | |
| 916 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 917 | HandleGoto(got, got->GetSuccessor()); |
| 918 | } |
| 919 | |
| 920 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 921 | try_boundary->SetLocations(nullptr); |
| 922 | } |
| 923 | |
| 924 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 925 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 926 | if (!successor->IsExitBlock()) { |
| 927 | HandleGoto(try_boundary, successor); |
| 928 | } |
| 929 | } |
| 930 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 931 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 932 | exit->SetLocations(nullptr); |
| 933 | } |
| 934 | |
| 935 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 936 | UNUSED(exit); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 937 | } |
| 938 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 939 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 940 | Label* true_label, |
| 941 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 942 | if (cond->IsFPConditionTrueIfNaN()) { |
| 943 | __ j(kUnordered, true_label); |
| 944 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 945 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 946 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 947 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HIf* if_instr, |
| 951 | HCondition* condition, |
| 952 | Label* true_target, |
| 953 | Label* false_target, |
| 954 | Label* always_true_target) { |
| 955 | LocationSummary* locations = condition->GetLocations(); |
| 956 | Location left = locations->InAt(0); |
| 957 | Location right = locations->InAt(1); |
| 958 | |
| 959 | // We don't want true_target as a nullptr. |
| 960 | if (true_target == nullptr) { |
| 961 | true_target = always_true_target; |
| 962 | } |
| 963 | bool falls_through = (false_target == nullptr); |
| 964 | |
| 965 | // FP compares don't like null false_targets. |
| 966 | if (false_target == nullptr) { |
| 967 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 968 | } |
| 969 | |
| 970 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 971 | switch (type) { |
| 972 | case Primitive::kPrimLong: { |
| 973 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 974 | if (right.IsConstant()) { |
| 975 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 976 | if (IsInt<32>(value)) { |
| 977 | if (value == 0) { |
| 978 | __ testq(left_reg, left_reg); |
| 979 | } else { |
| 980 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 981 | } |
| 982 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 983 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 984 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 985 | } |
| 986 | } else if (right.IsDoubleStackSlot()) { |
| 987 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 988 | } else { |
| 989 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 990 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 991 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 992 | break; |
| 993 | } |
| 994 | case Primitive::kPrimFloat: { |
| 995 | if (right.IsFpuRegister()) { |
| 996 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 997 | } else if (right.IsConstant()) { |
| 998 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 999 | codegen_->LiteralFloatAddress( |
| 1000 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1001 | } else { |
| 1002 | DCHECK(right.IsStackSlot()); |
| 1003 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1004 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1005 | } |
| 1006 | GenerateFPJumps(condition, true_target, false_target); |
| 1007 | break; |
| 1008 | } |
| 1009 | case Primitive::kPrimDouble: { |
| 1010 | if (right.IsFpuRegister()) { |
| 1011 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1012 | } else if (right.IsConstant()) { |
| 1013 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1014 | codegen_->LiteralDoubleAddress( |
| 1015 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1016 | } else { |
| 1017 | DCHECK(right.IsDoubleStackSlot()); |
| 1018 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1019 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1020 | } |
| 1021 | GenerateFPJumps(condition, true_target, false_target); |
| 1022 | break; |
| 1023 | } |
| 1024 | default: |
| 1025 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1026 | } |
| 1027 | |
| 1028 | if (!falls_through) { |
| 1029 | __ jmp(false_target); |
| 1030 | } |
| 1031 | } |
| 1032 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1033 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| 1034 | Label* true_target, |
| 1035 | Label* false_target, |
| 1036 | Label* always_true_target) { |
| 1037 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1038 | if (cond->IsIntConstant()) { |
| 1039 | // Constant condition, statically compared against 1. |
| 1040 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1041 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1042 | if (always_true_target != nullptr) { |
| 1043 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1044 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1045 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1046 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1047 | DCHECK_EQ(cond_value, 0); |
| 1048 | } |
| 1049 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1050 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1051 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1052 | // Moves do not affect the eflags register, so if the condition is |
| 1053 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1054 | // again. We can't use the eflags on FP conditions if they are |
| 1055 | // materialized due to the complex branching. |
| 1056 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1057 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1058 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
| 1059 | && !Primitive::IsFloatingPointType(type); |
| 1060 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1061 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1062 | if (!eflags_set) { |
| 1063 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1064 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1065 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1066 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1067 | } else { |
| 1068 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 1069 | Immediate(0)); |
| 1070 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1071 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1072 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1073 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1074 | } |
| 1075 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1076 | // Condition has not been materialized, use its inputs as the |
| 1077 | // comparison and its condition as the branch condition. |
| 1078 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1079 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1080 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1081 | // Generate the comparison directly. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1082 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1083 | true_target, false_target, always_true_target); |
| 1084 | return; |
| 1085 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1086 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1087 | Location lhs = cond->GetLocations()->InAt(0); |
| 1088 | Location rhs = cond->GetLocations()->InAt(1); |
| 1089 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1090 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1091 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1092 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1093 | if (constant == 0) { |
| 1094 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1095 | } else { |
| 1096 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1097 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1098 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1099 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1100 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1101 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1102 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1103 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1104 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1105 | if (false_target != nullptr) { |
| 1106 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1110 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| 1111 | LocationSummary* locations = |
| 1112 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1113 | HInstruction* cond = if_instr->InputAt(0); |
| 1114 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1115 | locations->SetInAt(0, Location::Any()); |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| 1120 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1121 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1122 | Label* always_true_target = true_target; |
| 1123 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1124 | if_instr->IfTrueSuccessor())) { |
| 1125 | always_true_target = nullptr; |
| 1126 | } |
| 1127 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1128 | if_instr->IfFalseSuccessor())) { |
| 1129 | false_target = nullptr; |
| 1130 | } |
| 1131 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1132 | } |
| 1133 | |
| 1134 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1135 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1136 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1137 | HInstruction* cond = deoptimize->InputAt(0); |
| 1138 | DCHECK(cond->IsCondition()); |
| 1139 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1140 | locations->SetInAt(0, Location::Any()); |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1145 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) |
| 1146 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1147 | codegen_->AddSlowPath(slow_path); |
| 1148 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1149 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1150 | } |
| 1151 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1152 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1153 | local->SetLocations(nullptr); |
| 1154 | } |
| 1155 | |
| 1156 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1157 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1158 | } |
| 1159 | |
| 1160 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1161 | local->SetLocations(nullptr); |
| 1162 | } |
| 1163 | |
| 1164 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 1165 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1166 | UNUSED(load); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1170 | LocationSummary* locations = |
| 1171 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1172 | switch (store->InputAt(1)->GetType()) { |
| 1173 | case Primitive::kPrimBoolean: |
| 1174 | case Primitive::kPrimByte: |
| 1175 | case Primitive::kPrimChar: |
| 1176 | case Primitive::kPrimShort: |
| 1177 | case Primitive::kPrimInt: |
| 1178 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1179 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1180 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1181 | break; |
| 1182 | |
| 1183 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1184 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1185 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1186 | break; |
| 1187 | |
| 1188 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1189 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1190 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1194 | UNUSED(store); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1195 | } |
| 1196 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1197 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1198 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1199 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1200 | // Handle the long/FP comparisons made in instruction simplification. |
| 1201 | switch (cond->InputAt(0)->GetType()) { |
| 1202 | case Primitive::kPrimLong: |
| 1203 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1204 | locations->SetInAt(1, Location::Any()); |
| 1205 | break; |
| 1206 | case Primitive::kPrimFloat: |
| 1207 | case Primitive::kPrimDouble: |
| 1208 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1209 | locations->SetInAt(1, Location::Any()); |
| 1210 | break; |
| 1211 | default: |
| 1212 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1213 | locations->SetInAt(1, Location::Any()); |
| 1214 | break; |
| 1215 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1216 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1217 | locations->SetOut(Location::RequiresRegister()); |
| 1218 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1221 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1222 | if (!cond->NeedsMaterialization()) { |
| 1223 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1224 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1225 | |
| 1226 | LocationSummary* locations = cond->GetLocations(); |
| 1227 | Location lhs = locations->InAt(0); |
| 1228 | Location rhs = locations->InAt(1); |
| 1229 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1230 | Label true_label, false_label; |
| 1231 | |
| 1232 | switch (cond->InputAt(0)->GetType()) { |
| 1233 | default: |
| 1234 | // Integer case. |
| 1235 | |
| 1236 | // Clear output register: setcc only sets the low byte. |
| 1237 | __ xorl(reg, reg); |
| 1238 | |
| 1239 | if (rhs.IsRegister()) { |
| 1240 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1241 | } else if (rhs.IsConstant()) { |
| 1242 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1243 | if (constant == 0) { |
| 1244 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1245 | } else { |
| 1246 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1247 | } |
| 1248 | } else { |
| 1249 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1250 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1251 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1252 | return; |
| 1253 | case Primitive::kPrimLong: |
| 1254 | // Clear output register: setcc only sets the low byte. |
| 1255 | __ xorl(reg, reg); |
| 1256 | |
| 1257 | if (rhs.IsRegister()) { |
| 1258 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1259 | } else if (rhs.IsConstant()) { |
| 1260 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1261 | if (IsInt<32>(value)) { |
| 1262 | if (value == 0) { |
| 1263 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1264 | } else { |
| 1265 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1266 | } |
| 1267 | } else { |
| 1268 | // Value won't fit in an int. |
| 1269 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1270 | } |
| 1271 | } else { |
| 1272 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1273 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1274 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 | return; |
| 1276 | case Primitive::kPrimFloat: { |
| 1277 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1278 | if (rhs.IsConstant()) { |
| 1279 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1280 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1281 | } else if (rhs.IsStackSlot()) { |
| 1282 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1283 | } else { |
| 1284 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1285 | } |
| 1286 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1287 | break; |
| 1288 | } |
| 1289 | case Primitive::kPrimDouble: { |
| 1290 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1291 | if (rhs.IsConstant()) { |
| 1292 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1293 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1294 | } else if (rhs.IsDoubleStackSlot()) { |
| 1295 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1296 | } else { |
| 1297 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1298 | } |
| 1299 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1300 | break; |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | // Convert the jumps into the result. |
| 1305 | Label done_label; |
| 1306 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1307 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1308 | __ Bind(&false_label); |
| 1309 | __ xorl(reg, reg); |
| 1310 | __ jmp(&done_label); |
| 1311 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1312 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1313 | __ Bind(&true_label); |
| 1314 | __ movl(reg, Immediate(1)); |
| 1315 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1319 | VisitCondition(comp); |
| 1320 | } |
| 1321 | |
| 1322 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1323 | VisitCondition(comp); |
| 1324 | } |
| 1325 | |
| 1326 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1327 | VisitCondition(comp); |
| 1328 | } |
| 1329 | |
| 1330 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1331 | VisitCondition(comp); |
| 1332 | } |
| 1333 | |
| 1334 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1335 | VisitCondition(comp); |
| 1336 | } |
| 1337 | |
| 1338 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1339 | VisitCondition(comp); |
| 1340 | } |
| 1341 | |
| 1342 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1343 | VisitCondition(comp); |
| 1344 | } |
| 1345 | |
| 1346 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1347 | VisitCondition(comp); |
| 1348 | } |
| 1349 | |
| 1350 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1351 | VisitCondition(comp); |
| 1352 | } |
| 1353 | |
| 1354 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1355 | VisitCondition(comp); |
| 1356 | } |
| 1357 | |
| 1358 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1359 | VisitCondition(comp); |
| 1360 | } |
| 1361 | |
| 1362 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1363 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1364 | } |
| 1365 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1366 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1367 | LocationSummary* locations = |
| 1368 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1369 | switch (compare->InputAt(0)->GetType()) { |
| 1370 | case Primitive::kPrimLong: { |
| 1371 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1372 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1373 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1374 | break; |
| 1375 | } |
| 1376 | case Primitive::kPrimFloat: |
| 1377 | case Primitive::kPrimDouble: { |
| 1378 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1379 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1380 | locations->SetOut(Location::RequiresRegister()); |
| 1381 | break; |
| 1382 | } |
| 1383 | default: |
| 1384 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1385 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1389 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1390 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1391 | Location left = locations->InAt(0); |
| 1392 | Location right = locations->InAt(1); |
| 1393 | |
| 1394 | Label less, greater, done; |
| 1395 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1396 | switch (type) { |
| 1397 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1398 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1399 | if (right.IsConstant()) { |
| 1400 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1401 | if (IsInt<32>(value)) { |
| 1402 | if (value == 0) { |
| 1403 | __ testq(left_reg, left_reg); |
| 1404 | } else { |
| 1405 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1406 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1407 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1408 | // Value won't fit in an int. |
| 1409 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1410 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1411 | } else if (right.IsDoubleStackSlot()) { |
| 1412 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1413 | } else { |
| 1414 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1415 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1416 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1417 | } |
| 1418 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1419 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1420 | if (right.IsConstant()) { |
| 1421 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1422 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1423 | } else if (right.IsStackSlot()) { |
| 1424 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1425 | } else { |
| 1426 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1427 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1428 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1429 | break; |
| 1430 | } |
| 1431 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1432 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1433 | if (right.IsConstant()) { |
| 1434 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1435 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1436 | } else if (right.IsDoubleStackSlot()) { |
| 1437 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1438 | } else { |
| 1439 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1440 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1441 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1442 | break; |
| 1443 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1444 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1445 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1446 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1447 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1448 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1449 | __ 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] | 1450 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1451 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1452 | __ movl(out, Immediate(1)); |
| 1453 | __ jmp(&done); |
| 1454 | |
| 1455 | __ Bind(&less); |
| 1456 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1457 | |
| 1458 | __ Bind(&done); |
| 1459 | } |
| 1460 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1461 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1462 | LocationSummary* locations = |
| 1463 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1464 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1468 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1469 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1470 | } |
| 1471 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1472 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1473 | LocationSummary* locations = |
| 1474 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1475 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1476 | } |
| 1477 | |
| 1478 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1479 | // Will be generated at use site. |
| 1480 | UNUSED(constant); |
| 1481 | } |
| 1482 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1483 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1484 | LocationSummary* locations = |
| 1485 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1486 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1490 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1491 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1492 | } |
| 1493 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1494 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1495 | LocationSummary* locations = |
| 1496 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1497 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1498 | } |
| 1499 | |
| 1500 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1501 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1502 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1506 | LocationSummary* locations = |
| 1507 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1508 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1509 | } |
| 1510 | |
| 1511 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1512 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1513 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1516 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1517 | memory_barrier->SetLocations(nullptr); |
| 1518 | } |
| 1519 | |
| 1520 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1521 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1522 | } |
| 1523 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1524 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1525 | ret->SetLocations(nullptr); |
| 1526 | } |
| 1527 | |
| 1528 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1529 | UNUSED(ret); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1530 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1534 | LocationSummary* locations = |
| 1535 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1536 | switch (ret->InputAt(0)->GetType()) { |
| 1537 | case Primitive::kPrimBoolean: |
| 1538 | case Primitive::kPrimByte: |
| 1539 | case Primitive::kPrimChar: |
| 1540 | case Primitive::kPrimShort: |
| 1541 | case Primitive::kPrimInt: |
| 1542 | case Primitive::kPrimNot: |
| 1543 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1544 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1545 | break; |
| 1546 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1547 | case Primitive::kPrimFloat: |
| 1548 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1549 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1550 | break; |
| 1551 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1552 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1553 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1554 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1558 | if (kIsDebugBuild) { |
| 1559 | switch (ret->InputAt(0)->GetType()) { |
| 1560 | case Primitive::kPrimBoolean: |
| 1561 | case Primitive::kPrimByte: |
| 1562 | case Primitive::kPrimChar: |
| 1563 | case Primitive::kPrimShort: |
| 1564 | case Primitive::kPrimInt: |
| 1565 | case Primitive::kPrimNot: |
| 1566 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1567 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1568 | break; |
| 1569 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1570 | case Primitive::kPrimFloat: |
| 1571 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1572 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1573 | XMM0); |
| 1574 | break; |
| 1575 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1576 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1577 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1578 | } |
| 1579 | } |
| 1580 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1583 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1584 | switch (type) { |
| 1585 | case Primitive::kPrimBoolean: |
| 1586 | case Primitive::kPrimByte: |
| 1587 | case Primitive::kPrimChar: |
| 1588 | case Primitive::kPrimShort: |
| 1589 | case Primitive::kPrimInt: |
| 1590 | case Primitive::kPrimNot: |
| 1591 | case Primitive::kPrimLong: |
| 1592 | return Location::RegisterLocation(RAX); |
| 1593 | |
| 1594 | case Primitive::kPrimVoid: |
| 1595 | return Location::NoLocation(); |
| 1596 | |
| 1597 | case Primitive::kPrimDouble: |
| 1598 | case Primitive::kPrimFloat: |
| 1599 | return Location::FpuRegisterLocation(XMM0); |
| 1600 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1601 | |
| 1602 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 1606 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1607 | } |
| 1608 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1609 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1610 | switch (type) { |
| 1611 | case Primitive::kPrimBoolean: |
| 1612 | case Primitive::kPrimByte: |
| 1613 | case Primitive::kPrimChar: |
| 1614 | case Primitive::kPrimShort: |
| 1615 | case Primitive::kPrimInt: |
| 1616 | case Primitive::kPrimNot: { |
| 1617 | uint32_t index = gp_index_++; |
| 1618 | stack_index_++; |
| 1619 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1620 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1621 | } else { |
| 1622 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | case Primitive::kPrimLong: { |
| 1627 | uint32_t index = gp_index_; |
| 1628 | stack_index_ += 2; |
| 1629 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1630 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1631 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1632 | } else { |
| 1633 | gp_index_ += 2; |
| 1634 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1635 | } |
| 1636 | } |
| 1637 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1638 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1639 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1640 | stack_index_++; |
| 1641 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1642 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1643 | } else { |
| 1644 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1649 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1650 | stack_index_ += 2; |
| 1651 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1652 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1653 | } else { |
| 1654 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1655 | } |
| 1656 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1657 | |
| 1658 | case Primitive::kPrimVoid: |
| 1659 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1660 | break; |
| 1661 | } |
| 1662 | return Location(); |
| 1663 | } |
| 1664 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1665 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1666 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1667 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1668 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1669 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1670 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1671 | if (intrinsic.TryDispatch(invoke)) { |
| 1672 | return; |
| 1673 | } |
| 1674 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1675 | HandleInvoke(invoke); |
| 1676 | } |
| 1677 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1678 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 1679 | if (invoke->GetLocations()->Intrinsified()) { |
| 1680 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 1681 | intrinsic.Dispatch(invoke); |
| 1682 | return true; |
| 1683 | } |
| 1684 | return false; |
| 1685 | } |
| 1686 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1687 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1688 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1689 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1690 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1691 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1692 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1693 | return; |
| 1694 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1695 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1696 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1697 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1698 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1699 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1700 | } |
| 1701 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1702 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1703 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1704 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1705 | } |
| 1706 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1707 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1708 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1709 | if (intrinsic.TryDispatch(invoke)) { |
| 1710 | return; |
| 1711 | } |
| 1712 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1713 | HandleInvoke(invoke); |
| 1714 | } |
| 1715 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1716 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1717 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1718 | return; |
| 1719 | } |
| 1720 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1721 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1722 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1723 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1724 | LocationSummary* locations = invoke->GetLocations(); |
| 1725 | Location receiver = locations->InAt(0); |
| 1726 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1727 | // temp = object->GetClass(); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1728 | DCHECK(receiver.IsRegister()); |
| 1729 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1730 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1731 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1732 | // temp = temp->GetMethodAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1733 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1734 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1735 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1736 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1737 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1738 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1739 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1740 | } |
| 1741 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1742 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1743 | HandleInvoke(invoke); |
| 1744 | // Add the hidden argument. |
| 1745 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1746 | } |
| 1747 | |
| 1748 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1749 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1750 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1751 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1752 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1753 | LocationSummary* locations = invoke->GetLocations(); |
| 1754 | Location receiver = locations->InAt(0); |
| 1755 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1756 | |
| 1757 | // Set the hidden argument. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1758 | CpuRegister hidden_reg = invoke->GetLocations()->GetTemp(1).AsRegister<CpuRegister>(); |
| 1759 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1760 | |
| 1761 | // temp = object->GetClass(); |
| 1762 | if (receiver.IsStackSlot()) { |
| 1763 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1764 | __ movl(temp, Address(temp, class_offset)); |
| 1765 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1766 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1767 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1768 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1769 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1770 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1771 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1772 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1773 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1774 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1775 | |
| 1776 | DCHECK(!codegen_->IsLeafMethod()); |
| 1777 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1778 | } |
| 1779 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1780 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1781 | LocationSummary* locations = |
| 1782 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1783 | switch (neg->GetResultType()) { |
| 1784 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1785 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1786 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1787 | locations->SetOut(Location::SameAsFirstInput()); |
| 1788 | break; |
| 1789 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1790 | case Primitive::kPrimFloat: |
| 1791 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1792 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1793 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1794 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1795 | break; |
| 1796 | |
| 1797 | default: |
| 1798 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1803 | LocationSummary* locations = neg->GetLocations(); |
| 1804 | Location out = locations->Out(); |
| 1805 | Location in = locations->InAt(0); |
| 1806 | switch (neg->GetResultType()) { |
| 1807 | case Primitive::kPrimInt: |
| 1808 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1809 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1810 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1811 | break; |
| 1812 | |
| 1813 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1814 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1815 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1816 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1817 | break; |
| 1818 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1819 | case Primitive::kPrimFloat: { |
| 1820 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1821 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1822 | // Implement float negation with an exclusive or with value |
| 1823 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1824 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1825 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1826 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1827 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1828 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1829 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1830 | case Primitive::kPrimDouble: { |
| 1831 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1832 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1833 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1834 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1835 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1836 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1837 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1838 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1839 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1840 | |
| 1841 | default: |
| 1842 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1843 | } |
| 1844 | } |
| 1845 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1846 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1847 | LocationSummary* locations = |
| 1848 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1849 | Primitive::Type result_type = conversion->GetResultType(); |
| 1850 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1851 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1852 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1853 | // The Java language does not allow treating boolean as an integral type but |
| 1854 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1855 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1856 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1857 | case Primitive::kPrimByte: |
| 1858 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1859 | case Primitive::kPrimBoolean: |
| 1860 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1861 | case Primitive::kPrimShort: |
| 1862 | case Primitive::kPrimInt: |
| 1863 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1864 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1865 | locations->SetInAt(0, Location::Any()); |
| 1866 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1867 | break; |
| 1868 | |
| 1869 | default: |
| 1870 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1871 | << " to " << result_type; |
| 1872 | } |
| 1873 | break; |
| 1874 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1875 | case Primitive::kPrimShort: |
| 1876 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1877 | case Primitive::kPrimBoolean: |
| 1878 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1879 | case Primitive::kPrimByte: |
| 1880 | case Primitive::kPrimInt: |
| 1881 | case Primitive::kPrimChar: |
| 1882 | // Processing a Dex `int-to-short' instruction. |
| 1883 | locations->SetInAt(0, Location::Any()); |
| 1884 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1885 | break; |
| 1886 | |
| 1887 | default: |
| 1888 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1889 | << " to " << result_type; |
| 1890 | } |
| 1891 | break; |
| 1892 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1893 | case Primitive::kPrimInt: |
| 1894 | switch (input_type) { |
| 1895 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1896 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1897 | locations->SetInAt(0, Location::Any()); |
| 1898 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1899 | break; |
| 1900 | |
| 1901 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1902 | // Processing a Dex `float-to-int' instruction. |
| 1903 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1904 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1905 | break; |
| 1906 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1907 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1908 | // Processing a Dex `double-to-int' instruction. |
| 1909 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1910 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1911 | break; |
| 1912 | |
| 1913 | default: |
| 1914 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1915 | << " to " << result_type; |
| 1916 | } |
| 1917 | break; |
| 1918 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1919 | case Primitive::kPrimLong: |
| 1920 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1921 | case Primitive::kPrimBoolean: |
| 1922 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1923 | case Primitive::kPrimByte: |
| 1924 | case Primitive::kPrimShort: |
| 1925 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1926 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1927 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1928 | // TODO: We would benefit from a (to-be-implemented) |
| 1929 | // Location::RegisterOrStackSlot requirement for this input. |
| 1930 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1931 | locations->SetOut(Location::RequiresRegister()); |
| 1932 | break; |
| 1933 | |
| 1934 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1935 | // Processing a Dex `float-to-long' instruction. |
| 1936 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1937 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1938 | break; |
| 1939 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1940 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1941 | // Processing a Dex `double-to-long' instruction. |
| 1942 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1943 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1944 | break; |
| 1945 | |
| 1946 | default: |
| 1947 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1948 | << " to " << result_type; |
| 1949 | } |
| 1950 | break; |
| 1951 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1952 | case Primitive::kPrimChar: |
| 1953 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1954 | case Primitive::kPrimBoolean: |
| 1955 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1956 | case Primitive::kPrimByte: |
| 1957 | case Primitive::kPrimShort: |
| 1958 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1959 | // Processing a Dex `int-to-char' instruction. |
| 1960 | locations->SetInAt(0, Location::Any()); |
| 1961 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1962 | break; |
| 1963 | |
| 1964 | default: |
| 1965 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1966 | << " to " << result_type; |
| 1967 | } |
| 1968 | break; |
| 1969 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1970 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1971 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1972 | case Primitive::kPrimBoolean: |
| 1973 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1974 | case Primitive::kPrimByte: |
| 1975 | case Primitive::kPrimShort: |
| 1976 | case Primitive::kPrimInt: |
| 1977 | case Primitive::kPrimChar: |
| 1978 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1979 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1980 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1981 | break; |
| 1982 | |
| 1983 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1984 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1985 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1986 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1987 | break; |
| 1988 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1989 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1990 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1991 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1992 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1993 | break; |
| 1994 | |
| 1995 | default: |
| 1996 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1997 | << " to " << result_type; |
| 1998 | }; |
| 1999 | break; |
| 2000 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2001 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2002 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2003 | case Primitive::kPrimBoolean: |
| 2004 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2005 | case Primitive::kPrimByte: |
| 2006 | case Primitive::kPrimShort: |
| 2007 | case Primitive::kPrimInt: |
| 2008 | case Primitive::kPrimChar: |
| 2009 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2010 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2011 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2012 | break; |
| 2013 | |
| 2014 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2015 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2016 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2017 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2018 | break; |
| 2019 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2020 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2021 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2022 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2023 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2024 | break; |
| 2025 | |
| 2026 | default: |
| 2027 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2028 | << " to " << result_type; |
| 2029 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2030 | break; |
| 2031 | |
| 2032 | default: |
| 2033 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2034 | << " to " << result_type; |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2039 | LocationSummary* locations = conversion->GetLocations(); |
| 2040 | Location out = locations->Out(); |
| 2041 | Location in = locations->InAt(0); |
| 2042 | Primitive::Type result_type = conversion->GetResultType(); |
| 2043 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2044 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2045 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2046 | case Primitive::kPrimByte: |
| 2047 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2048 | case Primitive::kPrimBoolean: |
| 2049 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2050 | case Primitive::kPrimShort: |
| 2051 | case Primitive::kPrimInt: |
| 2052 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2053 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2054 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2055 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2056 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2057 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2058 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2059 | } else { |
| 2060 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2061 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2062 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2063 | } |
| 2064 | break; |
| 2065 | |
| 2066 | default: |
| 2067 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2068 | << " to " << result_type; |
| 2069 | } |
| 2070 | break; |
| 2071 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2072 | case Primitive::kPrimShort: |
| 2073 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2074 | case Primitive::kPrimBoolean: |
| 2075 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2076 | case Primitive::kPrimByte: |
| 2077 | case Primitive::kPrimInt: |
| 2078 | case Primitive::kPrimChar: |
| 2079 | // Processing a Dex `int-to-short' instruction. |
| 2080 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2081 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2082 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2083 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2084 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2085 | } else { |
| 2086 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2087 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2088 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2089 | } |
| 2090 | break; |
| 2091 | |
| 2092 | default: |
| 2093 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2094 | << " to " << result_type; |
| 2095 | } |
| 2096 | break; |
| 2097 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2098 | case Primitive::kPrimInt: |
| 2099 | switch (input_type) { |
| 2100 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2101 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2102 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2103 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2104 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2105 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2106 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2107 | } else { |
| 2108 | DCHECK(in.IsConstant()); |
| 2109 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2110 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2111 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2112 | } |
| 2113 | break; |
| 2114 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2115 | case Primitive::kPrimFloat: { |
| 2116 | // Processing a Dex `float-to-int' instruction. |
| 2117 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2118 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2119 | Label done, nan; |
| 2120 | |
| 2121 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2122 | // if input >= (float)INT_MAX goto done |
| 2123 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2124 | __ j(kAboveEqual, &done); |
| 2125 | // if input == NaN goto nan |
| 2126 | __ j(kUnordered, &nan); |
| 2127 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2128 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2129 | __ jmp(&done); |
| 2130 | __ Bind(&nan); |
| 2131 | // output = 0 |
| 2132 | __ xorl(output, output); |
| 2133 | __ Bind(&done); |
| 2134 | break; |
| 2135 | } |
| 2136 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2137 | case Primitive::kPrimDouble: { |
| 2138 | // Processing a Dex `double-to-int' instruction. |
| 2139 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2140 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2141 | Label done, nan; |
| 2142 | |
| 2143 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2144 | // if input >= (double)INT_MAX goto done |
| 2145 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2146 | __ j(kAboveEqual, &done); |
| 2147 | // if input == NaN goto nan |
| 2148 | __ j(kUnordered, &nan); |
| 2149 | // output = double-to-int-truncate(input) |
| 2150 | __ cvttsd2si(output, input); |
| 2151 | __ jmp(&done); |
| 2152 | __ Bind(&nan); |
| 2153 | // output = 0 |
| 2154 | __ xorl(output, output); |
| 2155 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2156 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2157 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2158 | |
| 2159 | default: |
| 2160 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2161 | << " to " << result_type; |
| 2162 | } |
| 2163 | break; |
| 2164 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2165 | case Primitive::kPrimLong: |
| 2166 | switch (input_type) { |
| 2167 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2168 | case Primitive::kPrimBoolean: |
| 2169 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2170 | case Primitive::kPrimByte: |
| 2171 | case Primitive::kPrimShort: |
| 2172 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2173 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2174 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2175 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2176 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2177 | break; |
| 2178 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2179 | case Primitive::kPrimFloat: { |
| 2180 | // Processing a Dex `float-to-long' instruction. |
| 2181 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2182 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2183 | Label done, nan; |
| 2184 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2185 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2186 | // if input >= (float)LONG_MAX goto done |
| 2187 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2188 | __ j(kAboveEqual, &done); |
| 2189 | // if input == NaN goto nan |
| 2190 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2191 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2192 | __ cvttss2si(output, input, true); |
| 2193 | __ jmp(&done); |
| 2194 | __ Bind(&nan); |
| 2195 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2196 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2197 | __ Bind(&done); |
| 2198 | break; |
| 2199 | } |
| 2200 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2201 | case Primitive::kPrimDouble: { |
| 2202 | // Processing a Dex `double-to-long' instruction. |
| 2203 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2204 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2205 | Label done, nan; |
| 2206 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2207 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2208 | // if input >= (double)LONG_MAX goto done |
| 2209 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2210 | __ j(kAboveEqual, &done); |
| 2211 | // if input == NaN goto nan |
| 2212 | __ j(kUnordered, &nan); |
| 2213 | // output = double-to-long-truncate(input) |
| 2214 | __ cvttsd2si(output, input, true); |
| 2215 | __ jmp(&done); |
| 2216 | __ Bind(&nan); |
| 2217 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2218 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2219 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2220 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2221 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2222 | |
| 2223 | default: |
| 2224 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2225 | << " to " << result_type; |
| 2226 | } |
| 2227 | break; |
| 2228 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2229 | case Primitive::kPrimChar: |
| 2230 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2231 | case Primitive::kPrimBoolean: |
| 2232 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2233 | case Primitive::kPrimByte: |
| 2234 | case Primitive::kPrimShort: |
| 2235 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2236 | // Processing a Dex `int-to-char' instruction. |
| 2237 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2238 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2239 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2240 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2241 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2242 | } else { |
| 2243 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2244 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2245 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2246 | } |
| 2247 | break; |
| 2248 | |
| 2249 | default: |
| 2250 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2251 | << " to " << result_type; |
| 2252 | } |
| 2253 | break; |
| 2254 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2255 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2256 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2257 | case Primitive::kPrimBoolean: |
| 2258 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2259 | case Primitive::kPrimByte: |
| 2260 | case Primitive::kPrimShort: |
| 2261 | case Primitive::kPrimInt: |
| 2262 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2263 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2264 | if (in.IsRegister()) { |
| 2265 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2266 | } else if (in.IsConstant()) { |
| 2267 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2268 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2269 | if (v == 0) { |
| 2270 | __ xorps(dest, dest); |
| 2271 | } else { |
| 2272 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2273 | } |
| 2274 | } else { |
| 2275 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2276 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2277 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2278 | break; |
| 2279 | |
| 2280 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2281 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2282 | if (in.IsRegister()) { |
| 2283 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2284 | } else if (in.IsConstant()) { |
| 2285 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2286 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2287 | if (v == 0) { |
| 2288 | __ xorps(dest, dest); |
| 2289 | } else { |
| 2290 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2291 | } |
| 2292 | } else { |
| 2293 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2294 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2295 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2296 | break; |
| 2297 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2298 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2299 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2300 | if (in.IsFpuRegister()) { |
| 2301 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2302 | } else if (in.IsConstant()) { |
| 2303 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2304 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2305 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2306 | __ xorps(dest, dest); |
| 2307 | } else { |
| 2308 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2309 | } |
| 2310 | } else { |
| 2311 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2312 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2313 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2314 | break; |
| 2315 | |
| 2316 | default: |
| 2317 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2318 | << " to " << result_type; |
| 2319 | }; |
| 2320 | break; |
| 2321 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2322 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2323 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2324 | case Primitive::kPrimBoolean: |
| 2325 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2326 | case Primitive::kPrimByte: |
| 2327 | case Primitive::kPrimShort: |
| 2328 | case Primitive::kPrimInt: |
| 2329 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2330 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2331 | if (in.IsRegister()) { |
| 2332 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2333 | } else if (in.IsConstant()) { |
| 2334 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2335 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2336 | if (v == 0) { |
| 2337 | __ xorpd(dest, dest); |
| 2338 | } else { |
| 2339 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2340 | } |
| 2341 | } else { |
| 2342 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2343 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2344 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2345 | break; |
| 2346 | |
| 2347 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2348 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2349 | if (in.IsRegister()) { |
| 2350 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2351 | } else if (in.IsConstant()) { |
| 2352 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2353 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2354 | if (v == 0) { |
| 2355 | __ xorpd(dest, dest); |
| 2356 | } else { |
| 2357 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2358 | } |
| 2359 | } else { |
| 2360 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2361 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2362 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2363 | break; |
| 2364 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2366 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2367 | if (in.IsFpuRegister()) { |
| 2368 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2369 | } else if (in.IsConstant()) { |
| 2370 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2371 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2372 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2373 | __ xorpd(dest, dest); |
| 2374 | } else { |
| 2375 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2376 | } |
| 2377 | } else { |
| 2378 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2379 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2380 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2381 | break; |
| 2382 | |
| 2383 | default: |
| 2384 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2385 | << " to " << result_type; |
| 2386 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2387 | break; |
| 2388 | |
| 2389 | default: |
| 2390 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2391 | << " to " << result_type; |
| 2392 | } |
| 2393 | } |
| 2394 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2395 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2396 | LocationSummary* locations = |
| 2397 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2398 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2399 | case Primitive::kPrimInt: { |
| 2400 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2401 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2402 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2403 | break; |
| 2404 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2405 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2406 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2407 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2408 | // 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] | 2409 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2410 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2411 | break; |
| 2412 | } |
| 2413 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2414 | case Primitive::kPrimDouble: |
| 2415 | case Primitive::kPrimFloat: { |
| 2416 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2417 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2418 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2419 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2420 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2421 | |
| 2422 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2423 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2424 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2428 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2429 | Location first = locations->InAt(0); |
| 2430 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2431 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2432 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2433 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2434 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2435 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2436 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2437 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2438 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2439 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2440 | } else { |
| 2441 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2442 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2443 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2444 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2445 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2446 | __ addl(out.AsRegister<CpuRegister>(), |
| 2447 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2448 | } else { |
| 2449 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2450 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2451 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2452 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2453 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2454 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2455 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2456 | break; |
| 2457 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2458 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2459 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2460 | if (second.IsRegister()) { |
| 2461 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2462 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2463 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2464 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2465 | } else { |
| 2466 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2467 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2468 | } |
| 2469 | } else { |
| 2470 | DCHECK(second.IsConstant()); |
| 2471 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2472 | int32_t int32_value = Low32Bits(value); |
| 2473 | DCHECK_EQ(int32_value, value); |
| 2474 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2475 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2476 | } else { |
| 2477 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2478 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2479 | } |
| 2480 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2481 | break; |
| 2482 | } |
| 2483 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2484 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2485 | if (second.IsFpuRegister()) { |
| 2486 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2487 | } else if (second.IsConstant()) { |
| 2488 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2489 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2490 | } else { |
| 2491 | DCHECK(second.IsStackSlot()); |
| 2492 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2493 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2494 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2495 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2499 | if (second.IsFpuRegister()) { |
| 2500 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2501 | } else if (second.IsConstant()) { |
| 2502 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2503 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2504 | } else { |
| 2505 | DCHECK(second.IsDoubleStackSlot()); |
| 2506 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2507 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2508 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2509 | break; |
| 2510 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2511 | |
| 2512 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2513 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2518 | LocationSummary* locations = |
| 2519 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2520 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2521 | case Primitive::kPrimInt: { |
| 2522 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2523 | locations->SetInAt(1, Location::Any()); |
| 2524 | locations->SetOut(Location::SameAsFirstInput()); |
| 2525 | break; |
| 2526 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2527 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2528 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2529 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2530 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2531 | break; |
| 2532 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2533 | case Primitive::kPrimFloat: |
| 2534 | case Primitive::kPrimDouble: { |
| 2535 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2536 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2537 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2538 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2539 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2540 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2541 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2542 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2546 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2547 | Location first = locations->InAt(0); |
| 2548 | Location second = locations->InAt(1); |
| 2549 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2550 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2551 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2552 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2553 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2554 | } else if (second.IsConstant()) { |
| 2555 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2556 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2557 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2558 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2559 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2560 | break; |
| 2561 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2562 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2563 | if (second.IsConstant()) { |
| 2564 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2565 | DCHECK(IsInt<32>(value)); |
| 2566 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2567 | } else { |
| 2568 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2569 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2570 | break; |
| 2571 | } |
| 2572 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2573 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2574 | if (second.IsFpuRegister()) { |
| 2575 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2576 | } else if (second.IsConstant()) { |
| 2577 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2578 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2579 | } else { |
| 2580 | DCHECK(second.IsStackSlot()); |
| 2581 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2582 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2583 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2584 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2588 | if (second.IsFpuRegister()) { |
| 2589 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2590 | } else if (second.IsConstant()) { |
| 2591 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2592 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2593 | } else { |
| 2594 | DCHECK(second.IsDoubleStackSlot()); |
| 2595 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2596 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2597 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2598 | break; |
| 2599 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2600 | |
| 2601 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2602 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2603 | } |
| 2604 | } |
| 2605 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2606 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2607 | LocationSummary* locations = |
| 2608 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2609 | switch (mul->GetResultType()) { |
| 2610 | case Primitive::kPrimInt: { |
| 2611 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2612 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2613 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2614 | // Can use 3 operand multiply. |
| 2615 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2616 | } else { |
| 2617 | locations->SetOut(Location::SameAsFirstInput()); |
| 2618 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2619 | break; |
| 2620 | } |
| 2621 | case Primitive::kPrimLong: { |
| 2622 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2623 | locations->SetInAt(1, Location::Any()); |
| 2624 | if (mul->InputAt(1)->IsLongConstant() && |
| 2625 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2626 | // Can use 3 operand multiply. |
| 2627 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2628 | } else { |
| 2629 | locations->SetOut(Location::SameAsFirstInput()); |
| 2630 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2631 | break; |
| 2632 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2633 | case Primitive::kPrimFloat: |
| 2634 | case Primitive::kPrimDouble: { |
| 2635 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2636 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2637 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2638 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2639 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2640 | |
| 2641 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2642 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2647 | LocationSummary* locations = mul->GetLocations(); |
| 2648 | Location first = locations->InAt(0); |
| 2649 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2650 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2651 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2652 | case Primitive::kPrimInt: |
| 2653 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2654 | // problems where the output may not be the same as the first operand. |
| 2655 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2656 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2657 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 2658 | } else if (second.IsRegister()) { |
| 2659 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2660 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2661 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2662 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2663 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2664 | __ imull(first.AsRegister<CpuRegister>(), |
| 2665 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2666 | } |
| 2667 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2668 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2669 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2670 | // problems where the output may not be the same as the first operand. |
| 2671 | if (mul->InputAt(1)->IsLongConstant()) { |
| 2672 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 2673 | if (IsInt<32>(value)) { |
| 2674 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 2675 | Immediate(static_cast<int32_t>(value))); |
| 2676 | } else { |
| 2677 | // Have to use the constant area. |
| 2678 | DCHECK(first.Equals(out)); |
| 2679 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 2680 | } |
| 2681 | } else if (second.IsRegister()) { |
| 2682 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2683 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2684 | } else { |
| 2685 | DCHECK(second.IsDoubleStackSlot()); |
| 2686 | DCHECK(first.Equals(out)); |
| 2687 | __ imulq(first.AsRegister<CpuRegister>(), |
| 2688 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2689 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2690 | break; |
| 2691 | } |
| 2692 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2693 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2694 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2695 | if (second.IsFpuRegister()) { |
| 2696 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2697 | } else if (second.IsConstant()) { |
| 2698 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2699 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2700 | } else { |
| 2701 | DCHECK(second.IsStackSlot()); |
| 2702 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2703 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2704 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2705 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2709 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2710 | if (second.IsFpuRegister()) { |
| 2711 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2712 | } else if (second.IsConstant()) { |
| 2713 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2714 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2715 | } else { |
| 2716 | DCHECK(second.IsDoubleStackSlot()); |
| 2717 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2718 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2719 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2720 | break; |
| 2721 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2722 | |
| 2723 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2724 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2725 | } |
| 2726 | } |
| 2727 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2728 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2729 | uint32_t stack_adjustment, bool is_float) { |
| 2730 | if (source.IsStackSlot()) { |
| 2731 | DCHECK(is_float); |
| 2732 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2733 | } else if (source.IsDoubleStackSlot()) { |
| 2734 | DCHECK(!is_float); |
| 2735 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2736 | } else { |
| 2737 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2738 | if (is_float) { |
| 2739 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2740 | codegen_->Move(stack_temp, source); |
| 2741 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2742 | } else { |
| 2743 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2744 | codegen_->Move(stack_temp, source); |
| 2745 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2746 | } |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2751 | Primitive::Type type = rem->GetResultType(); |
| 2752 | bool is_float = type == Primitive::kPrimFloat; |
| 2753 | size_t elem_size = Primitive::ComponentSize(type); |
| 2754 | LocationSummary* locations = rem->GetLocations(); |
| 2755 | Location first = locations->InAt(0); |
| 2756 | Location second = locations->InAt(1); |
| 2757 | Location out = locations->Out(); |
| 2758 | |
| 2759 | // Create stack space for 2 elements. |
| 2760 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2761 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2762 | |
| 2763 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2764 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2765 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2766 | |
| 2767 | // Loop doing FPREM until we stabilize. |
| 2768 | Label retry; |
| 2769 | __ Bind(&retry); |
| 2770 | __ fprem(); |
| 2771 | |
| 2772 | // Move FP status to AX. |
| 2773 | __ fstsw(); |
| 2774 | |
| 2775 | // And see if the argument reduction is complete. This is signaled by the |
| 2776 | // C2 FPU flag bit set to 0. |
| 2777 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2778 | __ j(kNotEqual, &retry); |
| 2779 | |
| 2780 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2781 | // Store FP top of stack to real stack. |
| 2782 | if (is_float) { |
| 2783 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2784 | } else { |
| 2785 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2786 | } |
| 2787 | |
| 2788 | // Pop the 2 items from the FP stack. |
| 2789 | __ fucompp(); |
| 2790 | |
| 2791 | // Load the value from the stack into an XMM register. |
| 2792 | DCHECK(out.IsFpuRegister()) << out; |
| 2793 | if (is_float) { |
| 2794 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2795 | } else { |
| 2796 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2797 | } |
| 2798 | |
| 2799 | // And remove the temporary stack space we allocated. |
| 2800 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2801 | } |
| 2802 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2803 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2804 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2805 | |
| 2806 | LocationSummary* locations = instruction->GetLocations(); |
| 2807 | Location second = locations->InAt(1); |
| 2808 | DCHECK(second.IsConstant()); |
| 2809 | |
| 2810 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2811 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2812 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2813 | |
| 2814 | DCHECK(imm == 1 || imm == -1); |
| 2815 | |
| 2816 | switch (instruction->GetResultType()) { |
| 2817 | case Primitive::kPrimInt: { |
| 2818 | if (instruction->IsRem()) { |
| 2819 | __ xorl(output_register, output_register); |
| 2820 | } else { |
| 2821 | __ movl(output_register, input_register); |
| 2822 | if (imm == -1) { |
| 2823 | __ negl(output_register); |
| 2824 | } |
| 2825 | } |
| 2826 | break; |
| 2827 | } |
| 2828 | |
| 2829 | case Primitive::kPrimLong: { |
| 2830 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2831 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2832 | } else { |
| 2833 | __ movq(output_register, input_register); |
| 2834 | if (imm == -1) { |
| 2835 | __ negq(output_register); |
| 2836 | } |
| 2837 | } |
| 2838 | break; |
| 2839 | } |
| 2840 | |
| 2841 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2842 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2843 | } |
| 2844 | } |
| 2845 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2846 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2847 | LocationSummary* locations = instruction->GetLocations(); |
| 2848 | Location second = locations->InAt(1); |
| 2849 | |
| 2850 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2851 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2852 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2853 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2854 | |
| 2855 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 2856 | |
| 2857 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2858 | |
| 2859 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2860 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 2861 | __ testl(numerator, numerator); |
| 2862 | __ cmov(kGreaterEqual, tmp, numerator); |
| 2863 | int shift = CTZ(imm); |
| 2864 | __ sarl(tmp, Immediate(shift)); |
| 2865 | |
| 2866 | if (imm < 0) { |
| 2867 | __ negl(tmp); |
| 2868 | } |
| 2869 | |
| 2870 | __ movl(output_register, tmp); |
| 2871 | } else { |
| 2872 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2873 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2874 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2875 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2876 | __ addq(rdx, numerator); |
| 2877 | __ testq(numerator, numerator); |
| 2878 | __ cmov(kGreaterEqual, rdx, numerator); |
| 2879 | int shift = CTZ(imm); |
| 2880 | __ sarq(rdx, Immediate(shift)); |
| 2881 | |
| 2882 | if (imm < 0) { |
| 2883 | __ negq(rdx); |
| 2884 | } |
| 2885 | |
| 2886 | __ movq(output_register, rdx); |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2891 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2892 | |
| 2893 | LocationSummary* locations = instruction->GetLocations(); |
| 2894 | Location second = locations->InAt(1); |
| 2895 | |
| 2896 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 2897 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2898 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2899 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 2900 | : locations->Out().AsRegister<CpuRegister>(); |
| 2901 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 2902 | |
| 2903 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 2904 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 2905 | if (instruction->IsDiv()) { |
| 2906 | DCHECK_EQ(RAX, out.AsRegister()); |
| 2907 | } else { |
| 2908 | DCHECK_EQ(RDX, out.AsRegister()); |
| 2909 | } |
| 2910 | |
| 2911 | int64_t magic; |
| 2912 | int shift; |
| 2913 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2914 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2915 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2916 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2917 | |
| 2918 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2919 | |
| 2920 | __ movl(numerator, eax); |
| 2921 | |
| 2922 | Label no_div; |
| 2923 | Label end; |
| 2924 | __ testl(eax, eax); |
| 2925 | __ j(kNotEqual, &no_div); |
| 2926 | |
| 2927 | __ xorl(out, out); |
| 2928 | __ jmp(&end); |
| 2929 | |
| 2930 | __ Bind(&no_div); |
| 2931 | |
| 2932 | __ movl(eax, Immediate(magic)); |
| 2933 | __ imull(numerator); |
| 2934 | |
| 2935 | if (imm > 0 && magic < 0) { |
| 2936 | __ addl(edx, numerator); |
| 2937 | } else if (imm < 0 && magic > 0) { |
| 2938 | __ subl(edx, numerator); |
| 2939 | } |
| 2940 | |
| 2941 | if (shift != 0) { |
| 2942 | __ sarl(edx, Immediate(shift)); |
| 2943 | } |
| 2944 | |
| 2945 | __ movl(eax, edx); |
| 2946 | __ shrl(edx, Immediate(31)); |
| 2947 | __ addl(edx, eax); |
| 2948 | |
| 2949 | if (instruction->IsRem()) { |
| 2950 | __ movl(eax, numerator); |
| 2951 | __ imull(edx, Immediate(imm)); |
| 2952 | __ subl(eax, edx); |
| 2953 | __ movl(edx, eax); |
| 2954 | } else { |
| 2955 | __ movl(eax, edx); |
| 2956 | } |
| 2957 | __ Bind(&end); |
| 2958 | } else { |
| 2959 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2960 | |
| 2961 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2962 | |
| 2963 | CpuRegister rax = eax; |
| 2964 | CpuRegister rdx = edx; |
| 2965 | |
| 2966 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 2967 | |
| 2968 | // Save the numerator. |
| 2969 | __ movq(numerator, rax); |
| 2970 | |
| 2971 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2972 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2973 | |
| 2974 | // RDX:RAX = magic * numerator |
| 2975 | __ imulq(numerator); |
| 2976 | |
| 2977 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2978 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2979 | __ addq(rdx, numerator); |
| 2980 | } else if (imm < 0 && magic > 0) { |
| 2981 | // RDX -= numerator |
| 2982 | __ subq(rdx, numerator); |
| 2983 | } |
| 2984 | |
| 2985 | // Shift if needed. |
| 2986 | if (shift != 0) { |
| 2987 | __ sarq(rdx, Immediate(shift)); |
| 2988 | } |
| 2989 | |
| 2990 | // RDX += 1 if RDX < 0 |
| 2991 | __ movq(rax, rdx); |
| 2992 | __ shrq(rdx, Immediate(63)); |
| 2993 | __ addq(rdx, rax); |
| 2994 | |
| 2995 | if (instruction->IsRem()) { |
| 2996 | __ movq(rax, numerator); |
| 2997 | |
| 2998 | if (IsInt<32>(imm)) { |
| 2999 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3000 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3001 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | __ subq(rax, rdx); |
| 3005 | __ movq(rdx, rax); |
| 3006 | } else { |
| 3007 | __ movq(rax, rdx); |
| 3008 | } |
| 3009 | } |
| 3010 | } |
| 3011 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3012 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3013 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3014 | Primitive::Type type = instruction->GetResultType(); |
| 3015 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3016 | |
| 3017 | bool is_div = instruction->IsDiv(); |
| 3018 | LocationSummary* locations = instruction->GetLocations(); |
| 3019 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3020 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3021 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3022 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3023 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3024 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3025 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3026 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3027 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3028 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3029 | if (imm == 0) { |
| 3030 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3031 | } else if (imm == 1 || imm == -1) { |
| 3032 | DivRemOneOrMinusOne(instruction); |
| 3033 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3034 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3035 | } else { |
| 3036 | DCHECK(imm <= -2 || imm >= 2); |
| 3037 | GenerateDivRemWithAnyConstant(instruction); |
| 3038 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3039 | } else { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3040 | SlowPathCodeX86_64* slow_path = |
| 3041 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3042 | out.AsRegister(), type, is_div); |
| 3043 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3044 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3045 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3046 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3047 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3048 | // so it's safe to just use negl instead of more complex comparisons. |
| 3049 | if (type == Primitive::kPrimInt) { |
| 3050 | __ cmpl(second_reg, Immediate(-1)); |
| 3051 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3052 | // edx:eax <- sign-extended of eax |
| 3053 | __ cdq(); |
| 3054 | // eax = quotient, edx = remainder |
| 3055 | __ idivl(second_reg); |
| 3056 | } else { |
| 3057 | __ cmpq(second_reg, Immediate(-1)); |
| 3058 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3059 | // rdx:rax <- sign-extended of rax |
| 3060 | __ cqo(); |
| 3061 | // rax = quotient, rdx = remainder |
| 3062 | __ idivq(second_reg); |
| 3063 | } |
| 3064 | __ Bind(slow_path->GetExitLabel()); |
| 3065 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3068 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3069 | LocationSummary* locations = |
| 3070 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3071 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3072 | case Primitive::kPrimInt: |
| 3073 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3074 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3075 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3076 | locations->SetOut(Location::SameAsFirstInput()); |
| 3077 | // Intel uses edx:eax as the dividend. |
| 3078 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3079 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3080 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3081 | // output and request another temp. |
| 3082 | if (div->InputAt(1)->IsConstant()) { |
| 3083 | locations->AddTemp(Location::RequiresRegister()); |
| 3084 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3085 | break; |
| 3086 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3087 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3088 | case Primitive::kPrimFloat: |
| 3089 | case Primitive::kPrimDouble: { |
| 3090 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3091 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3092 | locations->SetOut(Location::SameAsFirstInput()); |
| 3093 | break; |
| 3094 | } |
| 3095 | |
| 3096 | default: |
| 3097 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3102 | LocationSummary* locations = div->GetLocations(); |
| 3103 | Location first = locations->InAt(0); |
| 3104 | Location second = locations->InAt(1); |
| 3105 | DCHECK(first.Equals(locations->Out())); |
| 3106 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3107 | Primitive::Type type = div->GetResultType(); |
| 3108 | switch (type) { |
| 3109 | case Primitive::kPrimInt: |
| 3110 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3111 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3112 | break; |
| 3113 | } |
| 3114 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3115 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3116 | if (second.IsFpuRegister()) { |
| 3117 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3118 | } else if (second.IsConstant()) { |
| 3119 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3120 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3121 | } else { |
| 3122 | DCHECK(second.IsStackSlot()); |
| 3123 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3124 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3125 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3126 | break; |
| 3127 | } |
| 3128 | |
| 3129 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3130 | if (second.IsFpuRegister()) { |
| 3131 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3132 | } else if (second.IsConstant()) { |
| 3133 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3134 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3135 | } else { |
| 3136 | DCHECK(second.IsDoubleStackSlot()); |
| 3137 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3138 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3139 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3140 | break; |
| 3141 | } |
| 3142 | |
| 3143 | default: |
| 3144 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3145 | } |
| 3146 | } |
| 3147 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3148 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3149 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3150 | LocationSummary* locations = |
| 3151 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3152 | |
| 3153 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3154 | case Primitive::kPrimInt: |
| 3155 | case Primitive::kPrimLong: { |
| 3156 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3157 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3158 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3159 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3160 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3161 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3162 | // output and request another temp. |
| 3163 | if (rem->InputAt(1)->IsConstant()) { |
| 3164 | locations->AddTemp(Location::RequiresRegister()); |
| 3165 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3166 | break; |
| 3167 | } |
| 3168 | |
| 3169 | case Primitive::kPrimFloat: |
| 3170 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3171 | locations->SetInAt(0, Location::Any()); |
| 3172 | locations->SetInAt(1, Location::Any()); |
| 3173 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3174 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3175 | break; |
| 3176 | } |
| 3177 | |
| 3178 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3179 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3184 | Primitive::Type type = rem->GetResultType(); |
| 3185 | switch (type) { |
| 3186 | case Primitive::kPrimInt: |
| 3187 | case Primitive::kPrimLong: { |
| 3188 | GenerateDivRemIntegral(rem); |
| 3189 | break; |
| 3190 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3191 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3192 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3193 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3194 | break; |
| 3195 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3196 | default: |
| 3197 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3198 | } |
| 3199 | } |
| 3200 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3201 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3202 | LocationSummary* locations = |
| 3203 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3204 | locations->SetInAt(0, Location::Any()); |
| 3205 | if (instruction->HasUses()) { |
| 3206 | locations->SetOut(Location::SameAsFirstInput()); |
| 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3211 | SlowPathCodeX86_64* slow_path = |
| 3212 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3213 | codegen_->AddSlowPath(slow_path); |
| 3214 | |
| 3215 | LocationSummary* locations = instruction->GetLocations(); |
| 3216 | Location value = locations->InAt(0); |
| 3217 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3218 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3219 | case Primitive::kPrimByte: |
| 3220 | case Primitive::kPrimChar: |
| 3221 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3222 | case Primitive::kPrimInt: { |
| 3223 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3224 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3225 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3226 | } else if (value.IsStackSlot()) { |
| 3227 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3228 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3229 | } else { |
| 3230 | DCHECK(value.IsConstant()) << value; |
| 3231 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3232 | __ jmp(slow_path->GetEntryLabel()); |
| 3233 | } |
| 3234 | } |
| 3235 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3236 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3237 | case Primitive::kPrimLong: { |
| 3238 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3239 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3240 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3241 | } else if (value.IsDoubleStackSlot()) { |
| 3242 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3243 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3244 | } else { |
| 3245 | DCHECK(value.IsConstant()) << value; |
| 3246 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3247 | __ jmp(slow_path->GetEntryLabel()); |
| 3248 | } |
| 3249 | } |
| 3250 | break; |
| 3251 | } |
| 3252 | default: |
| 3253 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3254 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3255 | } |
| 3256 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3257 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3258 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3259 | |
| 3260 | LocationSummary* locations = |
| 3261 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3262 | |
| 3263 | switch (op->GetResultType()) { |
| 3264 | case Primitive::kPrimInt: |
| 3265 | case Primitive::kPrimLong: { |
| 3266 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3267 | // The shift count needs to be in CL. |
| 3268 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3269 | locations->SetOut(Location::SameAsFirstInput()); |
| 3270 | break; |
| 3271 | } |
| 3272 | default: |
| 3273 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3274 | } |
| 3275 | } |
| 3276 | |
| 3277 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3278 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3279 | |
| 3280 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3281 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3282 | Location second = locations->InAt(1); |
| 3283 | |
| 3284 | switch (op->GetResultType()) { |
| 3285 | case Primitive::kPrimInt: { |
| 3286 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3287 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3288 | if (op->IsShl()) { |
| 3289 | __ shll(first_reg, second_reg); |
| 3290 | } else if (op->IsShr()) { |
| 3291 | __ sarl(first_reg, second_reg); |
| 3292 | } else { |
| 3293 | __ shrl(first_reg, second_reg); |
| 3294 | } |
| 3295 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3296 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3297 | if (op->IsShl()) { |
| 3298 | __ shll(first_reg, imm); |
| 3299 | } else if (op->IsShr()) { |
| 3300 | __ sarl(first_reg, imm); |
| 3301 | } else { |
| 3302 | __ shrl(first_reg, imm); |
| 3303 | } |
| 3304 | } |
| 3305 | break; |
| 3306 | } |
| 3307 | case Primitive::kPrimLong: { |
| 3308 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3309 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3310 | if (op->IsShl()) { |
| 3311 | __ shlq(first_reg, second_reg); |
| 3312 | } else if (op->IsShr()) { |
| 3313 | __ sarq(first_reg, second_reg); |
| 3314 | } else { |
| 3315 | __ shrq(first_reg, second_reg); |
| 3316 | } |
| 3317 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3318 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3319 | if (op->IsShl()) { |
| 3320 | __ shlq(first_reg, imm); |
| 3321 | } else if (op->IsShr()) { |
| 3322 | __ sarq(first_reg, imm); |
| 3323 | } else { |
| 3324 | __ shrq(first_reg, imm); |
| 3325 | } |
| 3326 | } |
| 3327 | break; |
| 3328 | } |
| 3329 | default: |
| 3330 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3331 | } |
| 3332 | } |
| 3333 | |
| 3334 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3335 | HandleShift(shl); |
| 3336 | } |
| 3337 | |
| 3338 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3339 | HandleShift(shl); |
| 3340 | } |
| 3341 | |
| 3342 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3343 | HandleShift(shr); |
| 3344 | } |
| 3345 | |
| 3346 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3347 | HandleShift(shr); |
| 3348 | } |
| 3349 | |
| 3350 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3351 | HandleShift(ushr); |
| 3352 | } |
| 3353 | |
| 3354 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3355 | HandleShift(ushr); |
| 3356 | } |
| 3357 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3358 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3359 | LocationSummary* locations = |
| 3360 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3361 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3362 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3363 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3364 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3368 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3369 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3370 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3371 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3372 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3373 | |
| 3374 | codegen_->InvokeRuntime( |
| 3375 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true), |
| 3376 | instruction, |
| 3377 | instruction->GetDexPc(), |
| 3378 | nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3379 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3380 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3381 | } |
| 3382 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3383 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3384 | LocationSummary* locations = |
| 3385 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3386 | InvokeRuntimeCallingConvention calling_convention; |
| 3387 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3388 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3389 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3390 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3394 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3395 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3396 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3397 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3398 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3399 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3400 | codegen_->InvokeRuntime( |
| 3401 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true), |
| 3402 | instruction, |
| 3403 | instruction->GetDexPc(), |
| 3404 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3405 | |
| 3406 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3407 | } |
| 3408 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3409 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3410 | LocationSummary* locations = |
| 3411 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3412 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3413 | if (location.IsStackSlot()) { |
| 3414 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3415 | } else if (location.IsDoubleStackSlot()) { |
| 3416 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3417 | } |
| 3418 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3419 | } |
| 3420 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3421 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3422 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3423 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3427 | LocationSummary* locations = |
| 3428 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3429 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3430 | } |
| 3431 | |
| 3432 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3433 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3434 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3435 | } |
| 3436 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3437 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3438 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3439 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3440 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3441 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3442 | } |
| 3443 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3444 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3445 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3446 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3447 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3448 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3449 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3450 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3451 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3452 | break; |
| 3453 | |
| 3454 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3455 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3456 | break; |
| 3457 | |
| 3458 | default: |
| 3459 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3460 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3461 | } |
| 3462 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3463 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3464 | LocationSummary* locations = |
| 3465 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3466 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3467 | locations->SetOut(Location::SameAsFirstInput()); |
| 3468 | } |
| 3469 | |
| 3470 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3471 | LocationSummary* locations = bool_not->GetLocations(); |
| 3472 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3473 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3474 | Location out = locations->Out(); |
| 3475 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3476 | } |
| 3477 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3478 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3479 | LocationSummary* locations = |
| 3480 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3481 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3482 | locations->SetInAt(i, Location::Any()); |
| 3483 | } |
| 3484 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3488 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3489 | LOG(FATAL) << "Unimplemented"; |
| 3490 | } |
| 3491 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3492 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3493 | /* |
| 3494 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3495 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3496 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3497 | */ |
| 3498 | switch (kind) { |
| 3499 | case MemBarrierKind::kAnyAny: { |
| 3500 | __ mfence(); |
| 3501 | break; |
| 3502 | } |
| 3503 | case MemBarrierKind::kAnyStore: |
| 3504 | case MemBarrierKind::kLoadAny: |
| 3505 | case MemBarrierKind::kStoreStore: { |
| 3506 | // nop |
| 3507 | break; |
| 3508 | } |
| 3509 | default: |
| 3510 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3511 | } |
| 3512 | } |
| 3513 | |
| 3514 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3515 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3516 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3517 | LocationSummary* locations = |
| 3518 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3519 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3520 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3521 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3522 | } else { |
| 3523 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3524 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3528 | const FieldInfo& field_info) { |
| 3529 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3530 | |
| 3531 | LocationSummary* locations = instruction->GetLocations(); |
| 3532 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3533 | Location out = locations->Out(); |
| 3534 | bool is_volatile = field_info.IsVolatile(); |
| 3535 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3536 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3537 | |
| 3538 | switch (field_type) { |
| 3539 | case Primitive::kPrimBoolean: { |
| 3540 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3541 | break; |
| 3542 | } |
| 3543 | |
| 3544 | case Primitive::kPrimByte: { |
| 3545 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3546 | break; |
| 3547 | } |
| 3548 | |
| 3549 | case Primitive::kPrimShort: { |
| 3550 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3551 | break; |
| 3552 | } |
| 3553 | |
| 3554 | case Primitive::kPrimChar: { |
| 3555 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3556 | break; |
| 3557 | } |
| 3558 | |
| 3559 | case Primitive::kPrimInt: |
| 3560 | case Primitive::kPrimNot: { |
| 3561 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3562 | break; |
| 3563 | } |
| 3564 | |
| 3565 | case Primitive::kPrimLong: { |
| 3566 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3567 | break; |
| 3568 | } |
| 3569 | |
| 3570 | case Primitive::kPrimFloat: { |
| 3571 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3572 | break; |
| 3573 | } |
| 3574 | |
| 3575 | case Primitive::kPrimDouble: { |
| 3576 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3577 | break; |
| 3578 | } |
| 3579 | |
| 3580 | case Primitive::kPrimVoid: |
| 3581 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3582 | UNREACHABLE(); |
| 3583 | } |
| 3584 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3585 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3586 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3587 | if (is_volatile) { |
| 3588 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3589 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3590 | |
| 3591 | if (field_type == Primitive::kPrimNot) { |
| 3592 | __ MaybeUnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 3593 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 3597 | const FieldInfo& field_info) { |
| 3598 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3599 | |
| 3600 | LocationSummary* locations = |
| 3601 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3602 | Primitive::Type field_type = field_info.GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3603 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3604 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3605 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3606 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3607 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 3608 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3609 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3610 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3611 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3612 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3613 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3614 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3615 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3616 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3617 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3618 | locations->AddTemp(Location::RequiresRegister()); |
| 3619 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3620 | } |
| 3621 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3622 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3623 | const FieldInfo& field_info, |
| 3624 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3625 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3626 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3627 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3628 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3629 | Location value = locations->InAt(1); |
| 3630 | bool is_volatile = field_info.IsVolatile(); |
| 3631 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3632 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3633 | |
| 3634 | if (is_volatile) { |
| 3635 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3636 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3637 | |
| 3638 | switch (field_type) { |
| 3639 | case Primitive::kPrimBoolean: |
| 3640 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3641 | if (value.IsConstant()) { |
| 3642 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3643 | __ movb(Address(base, offset), Immediate(v)); |
| 3644 | } else { |
| 3645 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3646 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | case Primitive::kPrimShort: |
| 3651 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3652 | if (value.IsConstant()) { |
| 3653 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3654 | __ movw(Address(base, offset), Immediate(v)); |
| 3655 | } else { |
| 3656 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3657 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3658 | break; |
| 3659 | } |
| 3660 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3661 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3662 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3663 | if (value.IsConstant()) { |
| 3664 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3665 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 3666 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 3667 | // Note: if heap poisoning is enabled, no need to poison |
| 3668 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 3669 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3670 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3671 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3672 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3673 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3674 | __ PoisonHeapReference(temp); |
| 3675 | __ movl(Address(base, offset), temp); |
| 3676 | } else { |
| 3677 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3678 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3679 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3680 | break; |
| 3681 | } |
| 3682 | |
| 3683 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3684 | if (value.IsConstant()) { |
| 3685 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3686 | DCHECK(IsInt<32>(v)); |
| 3687 | int32_t v_32 = v; |
| 3688 | __ movq(Address(base, offset), Immediate(v_32)); |
| 3689 | } else { |
| 3690 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3691 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3692 | break; |
| 3693 | } |
| 3694 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3695 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3696 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3697 | break; |
| 3698 | } |
| 3699 | |
| 3700 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3701 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3702 | break; |
| 3703 | } |
| 3704 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3705 | case Primitive::kPrimVoid: |
| 3706 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3707 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3708 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3709 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3710 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3711 | |
| 3712 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3713 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3714 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3715 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3716 | } |
| 3717 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3718 | if (is_volatile) { |
| 3719 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3720 | } |
| 3721 | } |
| 3722 | |
| 3723 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3724 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3725 | } |
| 3726 | |
| 3727 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3728 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3732 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3736 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3737 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3738 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3739 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3740 | HandleFieldGet(instruction); |
| 3741 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3742 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3743 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3744 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3745 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3746 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3747 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3748 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3749 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3750 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3751 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3752 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3756 | LocationSummary* locations = |
| 3757 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3758 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3759 | ? Location::RequiresRegister() |
| 3760 | : Location::Any(); |
| 3761 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3762 | if (instruction->HasUses()) { |
| 3763 | locations->SetOut(Location::SameAsFirstInput()); |
| 3764 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3765 | } |
| 3766 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3767 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3768 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3769 | return; |
| 3770 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3771 | LocationSummary* locations = instruction->GetLocations(); |
| 3772 | Location obj = locations->InAt(0); |
| 3773 | |
| 3774 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 3775 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3776 | } |
| 3777 | |
| 3778 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3779 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3780 | codegen_->AddSlowPath(slow_path); |
| 3781 | |
| 3782 | LocationSummary* locations = instruction->GetLocations(); |
| 3783 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3784 | |
| 3785 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3786 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3787 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3788 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3789 | } else { |
| 3790 | DCHECK(obj.IsConstant()) << obj; |
| 3791 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 3792 | __ jmp(slow_path->GetEntryLabel()); |
| 3793 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3794 | } |
| 3795 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3796 | } |
| 3797 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3798 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| 3799 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3800 | GenerateImplicitNullCheck(instruction); |
| 3801 | } else { |
| 3802 | GenerateExplicitNullCheck(instruction); |
| 3803 | } |
| 3804 | } |
| 3805 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3806 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3807 | LocationSummary* locations = |
| 3808 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3809 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3810 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3811 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3812 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3813 | } else { |
| 3814 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3815 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 3819 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3820 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3821 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3822 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3823 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3824 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3825 | case Primitive::kPrimBoolean: { |
| 3826 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3827 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3828 | if (index.IsConstant()) { |
| 3829 | __ movzxb(out, Address(obj, |
| 3830 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3831 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3832 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3833 | } |
| 3834 | break; |
| 3835 | } |
| 3836 | |
| 3837 | case Primitive::kPrimByte: { |
| 3838 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3839 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3840 | if (index.IsConstant()) { |
| 3841 | __ movsxb(out, Address(obj, |
| 3842 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3843 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3844 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3845 | } |
| 3846 | break; |
| 3847 | } |
| 3848 | |
| 3849 | case Primitive::kPrimShort: { |
| 3850 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3851 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3852 | if (index.IsConstant()) { |
| 3853 | __ movsxw(out, Address(obj, |
| 3854 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3855 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3856 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3857 | } |
| 3858 | break; |
| 3859 | } |
| 3860 | |
| 3861 | case Primitive::kPrimChar: { |
| 3862 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3863 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3864 | if (index.IsConstant()) { |
| 3865 | __ movzxw(out, Address(obj, |
| 3866 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3867 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3868 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3869 | } |
| 3870 | break; |
| 3871 | } |
| 3872 | |
| 3873 | case Primitive::kPrimInt: |
| 3874 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 3875 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 3876 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3877 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3878 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3879 | if (index.IsConstant()) { |
| 3880 | __ movl(out, Address(obj, |
| 3881 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3882 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3883 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3884 | } |
| 3885 | break; |
| 3886 | } |
| 3887 | |
| 3888 | case Primitive::kPrimLong: { |
| 3889 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3890 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3891 | if (index.IsConstant()) { |
| 3892 | __ movq(out, Address(obj, |
| 3893 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3894 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3895 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3896 | } |
| 3897 | break; |
| 3898 | } |
| 3899 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3900 | case Primitive::kPrimFloat: { |
| 3901 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3902 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3903 | if (index.IsConstant()) { |
| 3904 | __ movss(out, Address(obj, |
| 3905 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3906 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3907 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3908 | } |
| 3909 | break; |
| 3910 | } |
| 3911 | |
| 3912 | case Primitive::kPrimDouble: { |
| 3913 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3914 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3915 | if (index.IsConstant()) { |
| 3916 | __ movsd(out, Address(obj, |
| 3917 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3918 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3919 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3920 | } |
| 3921 | break; |
| 3922 | } |
| 3923 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3924 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3925 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3926 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3927 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3928 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3929 | |
| 3930 | if (type == Primitive::kPrimNot) { |
| 3931 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3932 | __ MaybeUnpoisonHeapReference(out); |
| 3933 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3937 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3938 | |
| 3939 | bool needs_write_barrier = |
| 3940 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3941 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 3942 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3943 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3944 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3945 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3946 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3947 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3948 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3949 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3950 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3951 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3952 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3953 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3954 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3955 | if (value_type == Primitive::kPrimLong) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3956 | locations->SetInAt(2, Location::RegisterOrInt32LongConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3957 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 3958 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3959 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3960 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3961 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3962 | |
| 3963 | if (needs_write_barrier) { |
| 3964 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3965 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3966 | locations->AddTemp(Location::RequiresRegister()); |
| 3967 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3968 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 3972 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3973 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3974 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3975 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3976 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3977 | bool needs_runtime_call = locations->WillCall(); |
| 3978 | bool needs_write_barrier = |
| 3979 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3980 | |
| 3981 | switch (value_type) { |
| 3982 | case Primitive::kPrimBoolean: |
| 3983 | case Primitive::kPrimByte: { |
| 3984 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3985 | if (index.IsConstant()) { |
| 3986 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3987 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3988 | __ movb(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3989 | } else { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3990 | __ movb(Address(obj, offset), |
| 3991 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3992 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3993 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3994 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3995 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
| 3996 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3997 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3998 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3999 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4000 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4001 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4002 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4003 | break; |
| 4004 | } |
| 4005 | |
| 4006 | case Primitive::kPrimShort: |
| 4007 | case Primitive::kPrimChar: { |
| 4008 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4009 | if (index.IsConstant()) { |
| 4010 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4011 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4012 | __ movw(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4013 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4014 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4015 | __ movw(Address(obj, offset), |
| 4016 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4017 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4018 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4019 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4020 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4021 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
| 4022 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4023 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4024 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4025 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4026 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4027 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4028 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4029 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4030 | break; |
| 4031 | } |
| 4032 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4033 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4034 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4035 | if (!needs_runtime_call) { |
| 4036 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4037 | if (index.IsConstant()) { |
| 4038 | size_t offset = |
| 4039 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4040 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4041 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4042 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4043 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4044 | __ PoisonHeapReference(temp); |
| 4045 | __ movl(Address(obj, offset), temp); |
| 4046 | } else { |
| 4047 | __ movl(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 4048 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4049 | } else { |
| 4050 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4051 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4052 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4053 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4054 | // Note: if heap poisoning is enabled, no need to poison |
| 4055 | // (negate) `v` if it is a reference, as it would be null. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4056 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4057 | } |
| 4058 | } else { |
| 4059 | DCHECK(index.IsRegister()) << index; |
| 4060 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4061 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4062 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4063 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4064 | __ PoisonHeapReference(temp); |
| 4065 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), temp); |
| 4066 | } else { |
| 4067 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 4068 | value.AsRegister<CpuRegister>()); |
| 4069 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4070 | } else { |
| 4071 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4072 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4073 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4074 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4075 | // Note: if heap poisoning is enabled, no need to poison |
| 4076 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4077 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4078 | Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4079 | } |
| 4080 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4081 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4082 | if (needs_write_barrier) { |
| 4083 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4084 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4085 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4086 | codegen_->MarkGCCard( |
| 4087 | temp, card, obj, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4088 | } |
| 4089 | } else { |
| 4090 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4091 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4092 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4093 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4094 | instruction, |
| 4095 | instruction->GetDexPc(), |
| 4096 | nullptr); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4097 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4098 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4099 | break; |
| 4100 | } |
| 4101 | |
| 4102 | case Primitive::kPrimLong: { |
| 4103 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4104 | if (index.IsConstant()) { |
| 4105 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4106 | if (value.IsRegister()) { |
| 4107 | __ movq(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 4108 | } else { |
| 4109 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4110 | DCHECK(IsInt<32>(v)); |
| 4111 | int32_t v_32 = v; |
| 4112 | __ movq(Address(obj, offset), Immediate(v_32)); |
| 4113 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4114 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4115 | if (value.IsRegister()) { |
| 4116 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4117 | value.AsRegister<CpuRegister>()); |
| 4118 | } else { |
| 4119 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4120 | DCHECK(IsInt<32>(v)); |
| 4121 | int32_t v_32 = v; |
| 4122 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4123 | Immediate(v_32)); |
| 4124 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4125 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4126 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4127 | break; |
| 4128 | } |
| 4129 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4130 | case Primitive::kPrimFloat: { |
| 4131 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4132 | if (index.IsConstant()) { |
| 4133 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4134 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4135 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4136 | } else { |
| 4137 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4138 | __ movss(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 4139 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4140 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4141 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4142 | break; |
| 4143 | } |
| 4144 | |
| 4145 | case Primitive::kPrimDouble: { |
| 4146 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4147 | if (index.IsConstant()) { |
| 4148 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4149 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4150 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4151 | } else { |
| 4152 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4153 | __ movsd(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4154 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4155 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4156 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4157 | break; |
| 4158 | } |
| 4159 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4160 | case Primitive::kPrimVoid: |
| 4161 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4162 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4167 | LocationSummary* locations = |
| 4168 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4169 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4170 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4174 | LocationSummary* locations = instruction->GetLocations(); |
| 4175 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4176 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4177 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4178 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4179 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4183 | LocationSummary* locations = |
| 4184 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4185 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4186 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4187 | if (instruction->HasUses()) { |
| 4188 | locations->SetOut(Location::SameAsFirstInput()); |
| 4189 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4193 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4194 | Location index_loc = locations->InAt(0); |
| 4195 | Location length_loc = locations->InAt(1); |
| 4196 | SlowPathCodeX86_64* slow_path = |
| 4197 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction, index_loc, length_loc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4198 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4199 | if (length_loc.IsConstant()) { |
| 4200 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4201 | if (index_loc.IsConstant()) { |
| 4202 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4203 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4204 | if (index < 0 || index >= length) { |
| 4205 | codegen_->AddSlowPath(slow_path); |
| 4206 | __ jmp(slow_path->GetEntryLabel()); |
| 4207 | } else { |
| 4208 | // Some optimization after BCE may have generated this, and we should not |
| 4209 | // generate a bounds check if it is a valid range. |
| 4210 | } |
| 4211 | return; |
| 4212 | } |
| 4213 | |
| 4214 | // We have to reverse the jump condition because the length is the constant. |
| 4215 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4216 | __ cmpl(index_reg, Immediate(length)); |
| 4217 | codegen_->AddSlowPath(slow_path); |
| 4218 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4219 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4220 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4221 | if (index_loc.IsConstant()) { |
| 4222 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4223 | __ cmpl(length, Immediate(value)); |
| 4224 | } else { |
| 4225 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4226 | } |
| 4227 | codegen_->AddSlowPath(slow_path); |
| 4228 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4229 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4233 | CpuRegister card, |
| 4234 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4235 | CpuRegister value, |
| 4236 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4237 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4238 | if (value_can_be_null) { |
| 4239 | __ testl(value, value); |
| 4240 | __ j(kEqual, &is_null); |
| 4241 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4242 | __ gs()->movq(card, Address::Absolute( |
| 4243 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4244 | __ movq(temp, object); |
| 4245 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4246 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4247 | if (value_can_be_null) { |
| 4248 | __ Bind(&is_null); |
| 4249 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4250 | } |
| 4251 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4252 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4253 | temp->SetLocations(nullptr); |
| 4254 | } |
| 4255 | |
| 4256 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 4257 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4258 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4259 | } |
| 4260 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4261 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4262 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4263 | LOG(FATAL) << "Unimplemented"; |
| 4264 | } |
| 4265 | |
| 4266 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4267 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4268 | } |
| 4269 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4270 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4271 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4272 | } |
| 4273 | |
| 4274 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4275 | HBasicBlock* block = instruction->GetBlock(); |
| 4276 | if (block->GetLoopInformation() != nullptr) { |
| 4277 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4278 | // The back edge will generate the suspend check. |
| 4279 | return; |
| 4280 | } |
| 4281 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4282 | // The goto will generate the suspend check. |
| 4283 | return; |
| 4284 | } |
| 4285 | GenerateSuspendCheck(instruction, nullptr); |
| 4286 | } |
| 4287 | |
| 4288 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4289 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4290 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4291 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4292 | if (slow_path == nullptr) { |
| 4293 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4294 | instruction->SetSlowPath(slow_path); |
| 4295 | codegen_->AddSlowPath(slow_path); |
| 4296 | if (successor != nullptr) { |
| 4297 | DCHECK(successor->IsLoopHeader()); |
| 4298 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4299 | } |
| 4300 | } else { |
| 4301 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4302 | } |
| 4303 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4304 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4305 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4306 | if (successor == nullptr) { |
| 4307 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4308 | __ Bind(slow_path->GetReturnLabel()); |
| 4309 | } else { |
| 4310 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4311 | __ jmp(slow_path->GetEntryLabel()); |
| 4312 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4315 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4316 | return codegen_->GetAssembler(); |
| 4317 | } |
| 4318 | |
| 4319 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 4320 | MoveOperands* move = moves_.Get(index); |
| 4321 | Location source = move->GetSource(); |
| 4322 | Location destination = move->GetDestination(); |
| 4323 | |
| 4324 | if (source.IsRegister()) { |
| 4325 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4326 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4327 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4328 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4329 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4330 | } else { |
| 4331 | DCHECK(destination.IsDoubleStackSlot()); |
| 4332 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4333 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4334 | } |
| 4335 | } else if (source.IsStackSlot()) { |
| 4336 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4337 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4338 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4339 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4340 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4341 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4342 | } else { |
| 4343 | DCHECK(destination.IsStackSlot()); |
| 4344 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4345 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4346 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4347 | } else if (source.IsDoubleStackSlot()) { |
| 4348 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4349 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4350 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4351 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4352 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4353 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4354 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4355 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4356 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4357 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4358 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4359 | } else if (source.IsConstant()) { |
| 4360 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4361 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4362 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4363 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4364 | if (value == 0) { |
| 4365 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4366 | } else { |
| 4367 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4368 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4369 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4370 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4371 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4372 | } |
| 4373 | } else if (constant->IsLongConstant()) { |
| 4374 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4375 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4376 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4377 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4378 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4379 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4380 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4381 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4382 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4383 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4384 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4385 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4386 | if (value == 0) { |
| 4387 | // easy FP 0.0. |
| 4388 | __ xorps(dest, dest); |
| 4389 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4390 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4391 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4392 | } else { |
| 4393 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4394 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4395 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4396 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4397 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4398 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4399 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4400 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4401 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4402 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4403 | if (value == 0) { |
| 4404 | __ xorpd(dest, dest); |
| 4405 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4406 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4407 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4408 | } else { |
| 4409 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4410 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4411 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4412 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4413 | } else if (source.IsFpuRegister()) { |
| 4414 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4415 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4416 | } else if (destination.IsStackSlot()) { |
| 4417 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4418 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4419 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 4420 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4421 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4422 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4423 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4424 | } |
| 4425 | } |
| 4426 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4427 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4428 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4429 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 4430 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4433 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4434 | ScratchRegisterScope ensure_scratch( |
| 4435 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 4436 | |
| 4437 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4438 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4439 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 4440 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4441 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4442 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4443 | CpuRegister(ensure_scratch.GetRegister())); |
| 4444 | } |
| 4445 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4446 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 4447 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4448 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 4449 | __ movq(reg, CpuRegister(TMP)); |
| 4450 | } |
| 4451 | |
| 4452 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 4453 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4454 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4455 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4456 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4457 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4458 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 4459 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4460 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4461 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4462 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4463 | } |
| 4464 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4465 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 4466 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4467 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 4468 | __ movd(reg, CpuRegister(TMP)); |
| 4469 | } |
| 4470 | |
| 4471 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 4472 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4473 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 4474 | __ movd(reg, CpuRegister(TMP)); |
| 4475 | } |
| 4476 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4477 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 4478 | MoveOperands* move = moves_.Get(index); |
| 4479 | Location source = move->GetSource(); |
| 4480 | Location destination = move->GetDestination(); |
| 4481 | |
| 4482 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4483 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4484 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4485 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4486 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4487 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4488 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4489 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4490 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4491 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4492 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4493 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4494 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 4495 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4496 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4497 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 4498 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4499 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4500 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4501 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4502 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4503 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4504 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4505 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4506 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4507 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4508 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4509 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | |
| 4514 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 4515 | __ pushq(CpuRegister(reg)); |
| 4516 | } |
| 4517 | |
| 4518 | |
| 4519 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 4520 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4521 | } |
| 4522 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4523 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| 4524 | SlowPathCodeX86_64* slow_path, CpuRegister class_reg) { |
| 4525 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4526 | Immediate(mirror::Class::kStatusInitialized)); |
| 4527 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4528 | __ Bind(slow_path->GetExitLabel()); |
| 4529 | // No need for memory fence, thanks to the X86_64 memory model. |
| 4530 | } |
| 4531 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4532 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4533 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4534 | ? LocationSummary::kCallOnSlowPath |
| 4535 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4536 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4537 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4538 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4539 | locations->SetOut(Location::RequiresRegister()); |
| 4540 | } |
| 4541 | |
| 4542 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4543 | LocationSummary* locations = cls->GetLocations(); |
| 4544 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4545 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4546 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4547 | DCHECK(!cls->CanCallRuntime()); |
| 4548 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4549 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4550 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4551 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4552 | __ movl(out, Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4553 | current_method, ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4554 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4555 | __ MaybeUnpoisonHeapReference(out); |
| 4556 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4557 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4558 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4559 | codegen_->AddSlowPath(slow_path); |
| 4560 | __ testl(out, out); |
| 4561 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4562 | if (cls->MustGenerateClinitCheck()) { |
| 4563 | GenerateClassInitializationCheck(slow_path, out); |
| 4564 | } else { |
| 4565 | __ Bind(slow_path->GetExitLabel()); |
| 4566 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4567 | } |
| 4568 | } |
| 4569 | |
| 4570 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 4571 | LocationSummary* locations = |
| 4572 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4573 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4574 | if (check->HasUses()) { |
| 4575 | locations->SetOut(Location::SameAsFirstInput()); |
| 4576 | } |
| 4577 | } |
| 4578 | |
| 4579 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4580 | // We assume the class to not be null. |
| 4581 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4582 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4583 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4584 | GenerateClassInitializationCheck(slow_path, |
| 4585 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4586 | } |
| 4587 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4588 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 4589 | LocationSummary* locations = |
| 4590 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4591 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4592 | locations->SetOut(Location::RequiresRegister()); |
| 4593 | } |
| 4594 | |
| 4595 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
| 4596 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 4597 | codegen_->AddSlowPath(slow_path); |
| 4598 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4599 | LocationSummary* locations = load->GetLocations(); |
| 4600 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4601 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4602 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4603 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4604 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4605 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4606 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4607 | __ testl(out, out); |
| 4608 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4609 | __ Bind(slow_path->GetExitLabel()); |
| 4610 | } |
| 4611 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4612 | static Address GetExceptionTlsAddress() { |
| 4613 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 4614 | } |
| 4615 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4616 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 4617 | LocationSummary* locations = |
| 4618 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4619 | locations->SetOut(Location::RequiresRegister()); |
| 4620 | } |
| 4621 | |
| 4622 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4623 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 4624 | } |
| 4625 | |
| 4626 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 4627 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4628 | } |
| 4629 | |
| 4630 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4631 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 4635 | LocationSummary* locations = |
| 4636 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4637 | InvokeRuntimeCallingConvention calling_convention; |
| 4638 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4639 | } |
| 4640 | |
| 4641 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4642 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4643 | instruction, |
| 4644 | instruction->GetDexPc(), |
| 4645 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4648 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4649 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4650 | ? LocationSummary::kNoCall |
| 4651 | : LocationSummary::kCallOnSlowPath; |
| 4652 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4653 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4654 | locations->SetInAt(1, Location::Any()); |
| 4655 | locations->SetOut(Location::RequiresRegister()); |
| 4656 | } |
| 4657 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4658 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4659 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4660 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4661 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4662 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4663 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4664 | Label done, zero; |
| 4665 | SlowPathCodeX86_64* slow_path = nullptr; |
| 4666 | |
| 4667 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4668 | // Avoid null check if we know obj is not null. |
| 4669 | if (instruction->MustDoNullCheck()) { |
| 4670 | __ testl(obj, obj); |
| 4671 | __ j(kEqual, &zero); |
| 4672 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4673 | // Compare the class of `obj` with `cls`. |
| 4674 | __ movl(out, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4675 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4676 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4677 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4678 | } else { |
| 4679 | DCHECK(cls.IsStackSlot()) << cls; |
| 4680 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4681 | } |
| 4682 | if (instruction->IsClassFinal()) { |
| 4683 | // Classes must be equal for the instanceof to succeed. |
| 4684 | __ j(kNotEqual, &zero); |
| 4685 | __ movl(out, Immediate(1)); |
| 4686 | __ jmp(&done); |
| 4687 | } else { |
| 4688 | // If the classes are not equal, we go into a slow path. |
| 4689 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4690 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4691 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4692 | codegen_->AddSlowPath(slow_path); |
| 4693 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4694 | __ movl(out, Immediate(1)); |
| 4695 | __ jmp(&done); |
| 4696 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4697 | |
| 4698 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4699 | __ Bind(&zero); |
| 4700 | __ movl(out, Immediate(0)); |
| 4701 | } |
| 4702 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4703 | if (slow_path != nullptr) { |
| 4704 | __ Bind(slow_path->GetExitLabel()); |
| 4705 | } |
| 4706 | __ Bind(&done); |
| 4707 | } |
| 4708 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4709 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4710 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4711 | instruction, LocationSummary::kCallOnSlowPath); |
| 4712 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4713 | locations->SetInAt(1, Location::Any()); |
| 4714 | locations->AddTemp(Location::RequiresRegister()); |
| 4715 | } |
| 4716 | |
| 4717 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4718 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4719 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4720 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4721 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4722 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4723 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 4724 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 4725 | codegen_->AddSlowPath(slow_path); |
| 4726 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4727 | // Avoid null check if we know obj is not null. |
| 4728 | if (instruction->MustDoNullCheck()) { |
| 4729 | __ testl(obj, obj); |
| 4730 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4731 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4732 | // Compare the class of `obj` with `cls`. |
| 4733 | __ movl(temp, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4734 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4735 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4736 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4737 | } else { |
| 4738 | DCHECK(cls.IsStackSlot()) << cls; |
| 4739 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4740 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4741 | // The checkcast succeeds if the classes are equal (fast path). |
| 4742 | // 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] | 4743 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4744 | __ Bind(slow_path->GetExitLabel()); |
| 4745 | } |
| 4746 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4747 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4748 | LocationSummary* locations = |
| 4749 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4750 | InvokeRuntimeCallingConvention calling_convention; |
| 4751 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4752 | } |
| 4753 | |
| 4754 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4755 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 4756 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 4757 | instruction, |
| 4758 | instruction->GetDexPc(), |
| 4759 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4760 | } |
| 4761 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4762 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4763 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4764 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4765 | |
| 4766 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4767 | LocationSummary* locations = |
| 4768 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4769 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4770 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4771 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4772 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4773 | locations->SetOut(Location::SameAsFirstInput()); |
| 4774 | } |
| 4775 | |
| 4776 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 4777 | HandleBitwiseOperation(instruction); |
| 4778 | } |
| 4779 | |
| 4780 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 4781 | HandleBitwiseOperation(instruction); |
| 4782 | } |
| 4783 | |
| 4784 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 4785 | HandleBitwiseOperation(instruction); |
| 4786 | } |
| 4787 | |
| 4788 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4789 | LocationSummary* locations = instruction->GetLocations(); |
| 4790 | Location first = locations->InAt(0); |
| 4791 | Location second = locations->InAt(1); |
| 4792 | DCHECK(first.Equals(locations->Out())); |
| 4793 | |
| 4794 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 4795 | if (second.IsRegister()) { |
| 4796 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4797 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4798 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4799 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4800 | } else { |
| 4801 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4802 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4803 | } |
| 4804 | } else if (second.IsConstant()) { |
| 4805 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 4806 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4807 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4808 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4809 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4810 | } else { |
| 4811 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4812 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4813 | } |
| 4814 | } else { |
| 4815 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 4816 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4817 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4818 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4819 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4820 | } else { |
| 4821 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4822 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4823 | } |
| 4824 | } |
| 4825 | } else { |
| 4826 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4827 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 4828 | bool second_is_constant = false; |
| 4829 | int64_t value = 0; |
| 4830 | if (second.IsConstant()) { |
| 4831 | second_is_constant = true; |
| 4832 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4833 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4834 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4835 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4836 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4837 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4838 | if (is_int32_value) { |
| 4839 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4840 | } else { |
| 4841 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4842 | } |
| 4843 | } else if (second.IsDoubleStackSlot()) { |
| 4844 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4845 | } else { |
| 4846 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 4847 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4848 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4849 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4850 | if (is_int32_value) { |
| 4851 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4852 | } else { |
| 4853 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4854 | } |
| 4855 | } else if (second.IsDoubleStackSlot()) { |
| 4856 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4857 | } else { |
| 4858 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 4859 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4860 | } else { |
| 4861 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4862 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4863 | if (is_int32_value) { |
| 4864 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4865 | } else { |
| 4866 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4867 | } |
| 4868 | } else if (second.IsDoubleStackSlot()) { |
| 4869 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4870 | } else { |
| 4871 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 4872 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4873 | } |
| 4874 | } |
| 4875 | } |
| 4876 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4877 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction) { |
| 4878 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4879 | UNUSED(instruction); |
| 4880 | LOG(FATAL) << "Unreachable"; |
| 4881 | } |
| 4882 | |
| 4883 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction) { |
| 4884 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4885 | UNUSED(instruction); |
| 4886 | LOG(FATAL) << "Unreachable"; |
| 4887 | } |
| 4888 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4889 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 4890 | DCHECK(codegen_->IsBaseline()); |
| 4891 | LocationSummary* locations = |
| 4892 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4893 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 4894 | } |
| 4895 | |
| 4896 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 4897 | DCHECK(codegen_->IsBaseline()); |
| 4898 | // Will be generated at use site. |
| 4899 | } |
| 4900 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4901 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 4902 | if (value == 0) { |
| 4903 | __ xorl(dest, dest); |
| 4904 | } else if (value > 0 && IsInt<32>(value)) { |
| 4905 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 4906 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 4907 | } else { |
| 4908 | __ movq(dest, Immediate(value)); |
| 4909 | } |
| 4910 | } |
| 4911 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4912 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 4913 | DCHECK(dest.IsDoubleStackSlot()); |
| 4914 | if (IsInt<32>(value)) { |
| 4915 | // Can move directly as an int32 constant. |
| 4916 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 4917 | Immediate(static_cast<int32_t>(value))); |
| 4918 | } else { |
| 4919 | Load64BitValue(CpuRegister(TMP), value); |
| 4920 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 4921 | } |
| 4922 | } |
| 4923 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4924 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 4925 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4926 | X86_64Assembler* assembler = GetAssembler(); |
| 4927 | if (!assembler->IsConstantAreaEmpty()) { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4928 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 4929 | // byte values. If used for vectors at a later time, this will need to be |
| 4930 | // updated to 16 bytes with the appropriate offset. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4931 | assembler->Align(4, 0); |
| 4932 | constant_area_start_ = assembler->CodeSize(); |
| 4933 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | // And finish up. |
| 4937 | CodeGenerator::Finalize(allocator); |
| 4938 | } |
| 4939 | |
| 4940 | /** |
| 4941 | * Class to handle late fixup of offsets into constant area. |
| 4942 | */ |
| 4943 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 4944 | public: |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4945 | RIPFixup(const CodeGeneratorX86_64& codegen, int offset) |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4946 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 4947 | |
| 4948 | private: |
| 4949 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 4950 | // Patch the correct offset for the instruction. We use the address of the |
| 4951 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 4952 | int constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 4953 | int relative_position = constant_offset - pos; |
| 4954 | |
| 4955 | // Patch in the right value. |
| 4956 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 4957 | } |
| 4958 | |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4959 | const CodeGeneratorX86_64& codegen_; |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4960 | |
| 4961 | // Location in constant area that the fixup refers to. |
| 4962 | int offset_into_constant_area_; |
| 4963 | }; |
| 4964 | |
| 4965 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 4966 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 4967 | return Address::RIP(fixup); |
| 4968 | } |
| 4969 | |
| 4970 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 4971 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 4972 | return Address::RIP(fixup); |
| 4973 | } |
| 4974 | |
| 4975 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 4976 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 4977 | return Address::RIP(fixup); |
| 4978 | } |
| 4979 | |
| 4980 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 4981 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 4982 | return Address::RIP(fixup); |
| 4983 | } |
| 4984 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4985 | #undef __ |
| 4986 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4987 | } // namespace x86_64 |
| 4988 | } // namespace art |