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