Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86_64.h" |
| 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | #include "intrinsics.h" |
| 25 | #include "intrinsics_x86_64.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "mirror/object_reference.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "utils/x86_64/assembler_x86_64.h" |
| 33 | #include "utils/x86_64/managed_register_x86_64.h" |
| 34 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 35 | namespace art { |
| 36 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 37 | namespace x86_64 { |
| 38 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 39 | // Some x86_64 instructions require a register to be available as temp. |
| 40 | static constexpr Register TMP = R11; |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = RDI; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 44 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 45 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 46 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 47 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 48 | static constexpr int kC2ConditionMask = 0x400; |
| 49 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 50 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 51 | #define QUICK_ENTRY_POINT(x) Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x), true) |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 53 | class NullCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 55 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 57 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 58 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 60 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 61 | instruction_, |
| 62 | instruction_->GetDexPc(), |
| 63 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 66 | bool IsFatal() const OVERRIDE { return true; } |
| 67 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 68 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 69 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 71 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 72 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 73 | }; |
| 74 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 75 | class DivZeroCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 76 | public: |
| 77 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 78 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 79 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 80 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 81 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 82 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 83 | instruction_, |
| 84 | instruction_->GetDexPc(), |
| 85 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 88 | bool IsFatal() const OVERRIDE { return true; } |
| 89 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 90 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 91 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | private: |
| 93 | HDivZeroCheck* const instruction_; |
| 94 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 95 | }; |
| 96 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 97 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCodeX86_64 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 99 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 100 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 102 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 104 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 105 | if (is_div_) { |
| 106 | __ negl(cpu_reg_); |
| 107 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 108 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 111 | } else { |
| 112 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negq(cpu_reg_); |
| 115 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 116 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 117 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 118 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | __ jmp(GetExitLabel()); |
| 120 | } |
| 121 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 122 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 123 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 126 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | const bool is_div_; |
| 128 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 131 | class SuspendCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 132 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 133 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 134 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 135 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 136 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 137 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 139 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 140 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 141 | instruction_, |
| 142 | instruction_->GetDexPc(), |
| 143 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 144 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 145 | if (successor_ == nullptr) { |
| 146 | __ jmp(GetReturnLabel()); |
| 147 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 148 | __ jmp(x64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 149 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 152 | Label* GetReturnLabel() { |
| 153 | DCHECK(successor_ == nullptr); |
| 154 | return &return_label_; |
| 155 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 156 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 157 | HBasicBlock* GetSuccessor() const { |
| 158 | return successor_; |
| 159 | } |
| 160 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 161 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 162 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | private: |
| 164 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 165 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 166 | Label return_label_; |
| 167 | |
| 168 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 169 | }; |
| 170 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 171 | class BoundsCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 172 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 173 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| 174 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 175 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 176 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 177 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 178 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 180 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 181 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 182 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 183 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 184 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 185 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 186 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 187 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 188 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 189 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 190 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 191 | instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 194 | bool IsFatal() const OVERRIDE { return true; } |
| 195 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 196 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 197 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 198 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 199 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 200 | |
| 201 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 202 | }; |
| 203 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 204 | class LoadClassSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 205 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 206 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 207 | HInstruction* at, |
| 208 | uint32_t dex_pc, |
| 209 | bool do_clinit) |
| 210 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 211 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 212 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 213 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 214 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 215 | LocationSummary* locations = at_->GetLocations(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 216 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 217 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 218 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 219 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 220 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 221 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 222 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 223 | x64_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 224 | : QUICK_ENTRY_POINT(pInitializeType), |
| 225 | at_, dex_pc_, this); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 226 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 227 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 229 | if (out.IsValid()) { |
| 230 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 231 | x64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 234 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | __ jmp(GetExitLabel()); |
| 236 | } |
| 237 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 238 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 239 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 241 | // The class this slow path will load. |
| 242 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 243 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | // The instruction where this slow path is happening. |
| 245 | // (Might be the load class or an initialization check). |
| 246 | HInstruction* const at_; |
| 247 | |
| 248 | // The dex PC of `at_`. |
| 249 | const uint32_t dex_pc_; |
| 250 | |
| 251 | // Whether to initialize the class. |
| 252 | const bool do_clinit_; |
| 253 | |
| 254 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 255 | }; |
| 256 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 257 | class LoadStringSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 258 | public: |
| 259 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 260 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 261 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 262 | LocationSummary* locations = instruction_->GetLocations(); |
| 263 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 264 | |
| 265 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 266 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 267 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 268 | |
| 269 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 270 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 271 | Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 272 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 273 | instruction_, |
| 274 | instruction_->GetDexPc(), |
| 275 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 276 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 277 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 278 | __ jmp(GetExitLabel()); |
| 279 | } |
| 280 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 281 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 282 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 283 | private: |
| 284 | HLoadString* const instruction_; |
| 285 | |
| 286 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 287 | }; |
| 288 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 289 | class TypeCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 290 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 291 | explicit TypeCheckSlowPathX86_64(HInstruction* instruction) |
| 292 | : instruction_(instruction) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 293 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 294 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 295 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 296 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 297 | : locations->Out(); |
| 298 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 299 | DCHECK(instruction_->IsCheckCast() |
| 300 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | |
| 302 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 303 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 304 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | |
| 306 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 307 | // move resolver. |
| 308 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 309 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 310 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 311 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 312 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 313 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 314 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 315 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 316 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 317 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 318 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 319 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 320 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 321 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 322 | } else { |
| 323 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 324 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 325 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 326 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 327 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 328 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 329 | |
| 330 | if (instruction_->IsInstanceOf()) { |
| 331 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 332 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 333 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 334 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 335 | __ jmp(GetExitLabel()); |
| 336 | } |
| 337 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 338 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 339 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 341 | HInstruction* const instruction_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | |
| 343 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 344 | }; |
| 345 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 346 | class DeoptimizationSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 347 | public: |
| 348 | explicit DeoptimizationSlowPathX86_64(HInstruction* instruction) |
| 349 | : instruction_(instruction) {} |
| 350 | |
| 351 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 352 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 353 | __ Bind(GetEntryLabel()); |
| 354 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 355 | DCHECK(instruction_->IsDeoptimize()); |
| 356 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 357 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 358 | deoptimize, |
| 359 | deoptimize->GetDexPc(), |
| 360 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 364 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 365 | private: |
| 366 | HInstruction* const instruction_; |
| 367 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 368 | }; |
| 369 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 370 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 371 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 372 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 373 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 374 | switch (cond) { |
| 375 | case kCondEQ: return kEqual; |
| 376 | case kCondNE: return kNotEqual; |
| 377 | case kCondLT: return kLess; |
| 378 | case kCondLE: return kLessEqual; |
| 379 | case kCondGT: return kGreater; |
| 380 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 381 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 382 | LOG(FATAL) << "Unreachable"; |
| 383 | UNREACHABLE(); |
| 384 | } |
| 385 | |
| 386 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 387 | switch (cond) { |
| 388 | case kCondEQ: return kEqual; |
| 389 | case kCondNE: return kNotEqual; |
| 390 | case kCondLT: return kBelow; |
| 391 | case kCondLE: return kBelowEqual; |
| 392 | case kCondGT: return kAbove; |
| 393 | case kCondGE: return kAboveEqual; |
| 394 | }; |
| 395 | LOG(FATAL) << "Unreachable"; |
| 396 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 399 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 400 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 401 | // All registers are assumed to be correctly set up. |
| 402 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 403 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 404 | switch (invoke->GetMethodLoadKind()) { |
| 405 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 406 | // temp = thread->string_init_entrypoint |
| 407 | __ gs()->movl(temp.AsRegister<CpuRegister>(), |
| 408 | Address::Absolute(invoke->GetStringInitOffset(), true)); |
| 409 | break; |
| 410 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 411 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 412 | break; |
| 413 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 414 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 415 | break; |
| 416 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 417 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 418 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 419 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 420 | break; |
| 421 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 422 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 423 | invoke->GetDexCacheArrayOffset()); |
| 424 | __ movq(temp.AsRegister<CpuRegister>(), |
| 425 | Address::Absolute(kDummy32BitOffset, false /* no_rip */)); |
| 426 | // Bind the label at the end of the "movl" insn. |
| 427 | __ Bind(&pc_rel_dex_cache_patches_.back().label); |
| 428 | break; |
| 429 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 430 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 431 | Register method_reg; |
| 432 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 433 | if (current_method.IsRegister()) { |
| 434 | method_reg = current_method.AsRegister<Register>(); |
| 435 | } else { |
| 436 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 437 | DCHECK(!current_method.IsValid()); |
| 438 | method_reg = reg.AsRegister(); |
| 439 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 440 | } |
| 441 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 442 | __ movq(reg, |
| 443 | Address(CpuRegister(method_reg), |
| 444 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 445 | // temp = temp[index_in_cache] |
| 446 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 447 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 448 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 449 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | switch (invoke->GetCodePtrLocation()) { |
| 453 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 454 | __ call(&frame_entry_label_); |
| 455 | break; |
| 456 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 457 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 458 | Label* label = &relative_call_patches_.back().label; |
| 459 | __ call(label); // Bind to the patch label, override at link time. |
| 460 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 461 | break; |
| 462 | } |
| 463 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 464 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 465 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 466 | FALLTHROUGH_INTENDED; |
| 467 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 468 | // (callee_method + offset_of_quick_compiled_code)() |
| 469 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 470 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 471 | kX86_64WordSize).SizeValue())); |
| 472 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 473 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 474 | |
| 475 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame^] | 478 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 479 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 480 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 481 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| 482 | LocationSummary* locations = invoke->GetLocations(); |
| 483 | Location receiver = locations->InAt(0); |
| 484 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 485 | // temp = object->GetClass(); |
| 486 | DCHECK(receiver.IsRegister()); |
| 487 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| 488 | MaybeRecordImplicitNullCheck(invoke); |
| 489 | __ MaybeUnpoisonHeapReference(temp); |
| 490 | // temp = temp->GetMethodAt(method_offset); |
| 491 | __ movq(temp, Address(temp, method_offset)); |
| 492 | // call temp->GetEntryPoint(); |
| 493 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 494 | kX86_64WordSize).SizeValue())); |
| 495 | } |
| 496 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 497 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 498 | DCHECK(linker_patches->empty()); |
| 499 | size_t size = |
| 500 | method_patches_.size() + relative_call_patches_.size() + pc_rel_dex_cache_patches_.size(); |
| 501 | linker_patches->reserve(size); |
| 502 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 503 | // The label points to the end of the "movl" instruction but the literal offset for method |
| 504 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 505 | uint32_t literal_offset = info.label.Position() - 4; |
| 506 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 507 | info.target_method.dex_file, |
| 508 | info.target_method.dex_method_index)); |
| 509 | } |
| 510 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 511 | // The label points to the end of the "call" instruction but the literal offset for method |
| 512 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 513 | uint32_t literal_offset = info.label.Position() - 4; |
| 514 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 515 | info.target_method.dex_file, |
| 516 | info.target_method.dex_method_index)); |
| 517 | } |
| 518 | for (const PcRelativeDexCacheAccessInfo& info : pc_rel_dex_cache_patches_) { |
| 519 | // The label points to the end of the "mov" instruction but the literal offset for method |
| 520 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 521 | uint32_t literal_offset = info.label.Position() - 4; |
| 522 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 523 | &info.target_dex_file, |
| 524 | info.label.Position(), |
| 525 | info.element_offset)); |
| 526 | } |
| 527 | } |
| 528 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 529 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 530 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 534 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 537 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 538 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 539 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 540 | } |
| 541 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 542 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 543 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 544 | return kX86_64WordSize; |
| 545 | } |
| 546 | |
| 547 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 548 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 549 | return kX86_64WordSize; |
| 550 | } |
| 551 | |
| 552 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 553 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 554 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 555 | } |
| 556 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 557 | void CodeGeneratorX86_64::InvokeRuntime(Address entry_point, |
| 558 | HInstruction* instruction, |
| 559 | uint32_t dex_pc, |
| 560 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 561 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 562 | __ gs()->call(entry_point); |
| 563 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 566 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 567 | // Use a fake return address register to mimic Quick. |
| 568 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 569 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| 570 | const X86_64InstructionSetFeatures& isa_features, |
| 571 | const CompilerOptions& compiler_options) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 572 | : CodeGenerator(graph, |
| 573 | kNumberOfCpuRegisters, |
| 574 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 575 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 576 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 577 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 578 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 579 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 580 | arraysize(kFpuCalleeSaves)), |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 581 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 582 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 583 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 584 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 585 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 586 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 587 | constant_area_start_(0), |
| 588 | method_patches_(graph->GetArena()->Adapter()), |
| 589 | relative_call_patches_(graph->GetArena()->Adapter()), |
| 590 | pc_rel_dex_cache_patches_(graph->GetArena()->Adapter()) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 591 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 592 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 593 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 594 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 595 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 596 | : HGraphVisitor(graph), |
| 597 | assembler_(codegen->GetAssembler()), |
| 598 | codegen_(codegen) {} |
| 599 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 600 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 601 | switch (type) { |
| 602 | case Primitive::kPrimLong: |
| 603 | case Primitive::kPrimByte: |
| 604 | case Primitive::kPrimBoolean: |
| 605 | case Primitive::kPrimChar: |
| 606 | case Primitive::kPrimShort: |
| 607 | case Primitive::kPrimInt: |
| 608 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 609 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 610 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 614 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 615 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 616 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 617 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 618 | |
| 619 | case Primitive::kPrimVoid: |
| 620 | LOG(FATAL) << "Unreachable type " << type; |
| 621 | } |
| 622 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 623 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 624 | } |
| 625 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 626 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 627 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 628 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 629 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 630 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 631 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 632 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 633 | if (is_baseline) { |
| 634 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 635 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 636 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 637 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 638 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 639 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 640 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 641 | } |
| 642 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 643 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 644 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 645 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 646 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 647 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 648 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 649 | } |
| 650 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 651 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 652 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 653 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 654 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 655 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 656 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 657 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 658 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 659 | __ testq(CpuRegister(RAX), Address( |
| 660 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 661 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 662 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 663 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 664 | if (HasEmptyFrame()) { |
| 665 | return; |
| 666 | } |
| 667 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 668 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 669 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 670 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 671 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 672 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 673 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 674 | } |
| 675 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 676 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 677 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 678 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 679 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 680 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 681 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 682 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 683 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 684 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 685 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 686 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 687 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 688 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 691 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 692 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 696 | __ cfi().RememberState(); |
| 697 | if (!HasEmptyFrame()) { |
| 698 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 699 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 700 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 701 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 702 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 703 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 704 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 709 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 710 | __ cfi().AdjustCFAOffset(-adjust); |
| 711 | |
| 712 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 713 | Register reg = kCoreCalleeSaves[i]; |
| 714 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 715 | __ popq(CpuRegister(reg)); |
| 716 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 717 | __ cfi().Restore(DWARFReg(reg)); |
| 718 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 719 | } |
| 720 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 721 | __ ret(); |
| 722 | __ cfi().RestoreState(); |
| 723 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 724 | } |
| 725 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 726 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 727 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 728 | } |
| 729 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 730 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 731 | switch (load->GetType()) { |
| 732 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 733 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 734 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 735 | |
| 736 | case Primitive::kPrimInt: |
| 737 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 738 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 739 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 740 | |
| 741 | case Primitive::kPrimBoolean: |
| 742 | case Primitive::kPrimByte: |
| 743 | case Primitive::kPrimChar: |
| 744 | case Primitive::kPrimShort: |
| 745 | case Primitive::kPrimVoid: |
| 746 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 747 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 751 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 755 | if (source.Equals(destination)) { |
| 756 | return; |
| 757 | } |
| 758 | if (destination.IsRegister()) { |
| 759 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 760 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 761 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 762 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 763 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 764 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 765 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 766 | } else { |
| 767 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 768 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 769 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 770 | } |
| 771 | } else if (destination.IsFpuRegister()) { |
| 772 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 773 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 774 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 775 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 776 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 777 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 778 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 779 | } else { |
| 780 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 781 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 782 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 783 | } |
| 784 | } else if (destination.IsStackSlot()) { |
| 785 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 786 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 787 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 788 | } else if (source.IsFpuRegister()) { |
| 789 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 790 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 791 | } else if (source.IsConstant()) { |
| 792 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 793 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 794 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 795 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 796 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 797 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 798 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 799 | } |
| 800 | } else { |
| 801 | DCHECK(destination.IsDoubleStackSlot()); |
| 802 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 803 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 804 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 805 | } else if (source.IsFpuRegister()) { |
| 806 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 807 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 808 | } else if (source.IsConstant()) { |
| 809 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 810 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 811 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 812 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 813 | } else { |
| 814 | DCHECK(constant->IsLongConstant()); |
| 815 | value = constant->AsLongConstant()->GetValue(); |
| 816 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 817 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 818 | } else { |
| 819 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 820 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 821 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 826 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 827 | Location location, |
| 828 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 829 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 830 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 831 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 832 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 833 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 834 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 835 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 836 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 837 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 838 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 839 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 840 | } else if (location.IsStackSlot()) { |
| 841 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 842 | } else { |
| 843 | DCHECK(location.IsConstant()); |
| 844 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 845 | } |
| 846 | } else if (const_to_move->IsLongConstant()) { |
| 847 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 848 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 849 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 850 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 851 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 852 | } else { |
| 853 | DCHECK(location.IsConstant()); |
| 854 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 855 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 856 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 857 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 858 | switch (instruction->GetType()) { |
| 859 | case Primitive::kPrimBoolean: |
| 860 | case Primitive::kPrimByte: |
| 861 | case Primitive::kPrimChar: |
| 862 | case Primitive::kPrimShort: |
| 863 | case Primitive::kPrimInt: |
| 864 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 865 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 866 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 867 | break; |
| 868 | |
| 869 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 870 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 871 | Move(location, |
| 872 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 873 | break; |
| 874 | |
| 875 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 876 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 877 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 878 | } else if (instruction->IsTemporary()) { |
| 879 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 880 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 881 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 882 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 883 | switch (instruction->GetType()) { |
| 884 | case Primitive::kPrimBoolean: |
| 885 | case Primitive::kPrimByte: |
| 886 | case Primitive::kPrimChar: |
| 887 | case Primitive::kPrimShort: |
| 888 | case Primitive::kPrimInt: |
| 889 | case Primitive::kPrimNot: |
| 890 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 891 | case Primitive::kPrimFloat: |
| 892 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 893 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 897 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 902 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 903 | DCHECK(!successor->IsExitBlock()); |
| 904 | |
| 905 | HBasicBlock* block = got->GetBlock(); |
| 906 | HInstruction* previous = got->GetPrevious(); |
| 907 | |
| 908 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 909 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 910 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 911 | return; |
| 912 | } |
| 913 | |
| 914 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 915 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 916 | } |
| 917 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 918 | __ jmp(codegen_->GetLabelOf(successor)); |
| 919 | } |
| 920 | } |
| 921 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 922 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 923 | got->SetLocations(nullptr); |
| 924 | } |
| 925 | |
| 926 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 927 | HandleGoto(got, got->GetSuccessor()); |
| 928 | } |
| 929 | |
| 930 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 931 | try_boundary->SetLocations(nullptr); |
| 932 | } |
| 933 | |
| 934 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 935 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 936 | if (!successor->IsExitBlock()) { |
| 937 | HandleGoto(try_boundary, successor); |
| 938 | } |
| 939 | } |
| 940 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 941 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 942 | exit->SetLocations(nullptr); |
| 943 | } |
| 944 | |
| 945 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 946 | UNUSED(exit); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 949 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 950 | Label* true_label, |
| 951 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 952 | if (cond->IsFPConditionTrueIfNaN()) { |
| 953 | __ j(kUnordered, true_label); |
| 954 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 955 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 956 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 957 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HIf* if_instr, |
| 961 | HCondition* condition, |
| 962 | Label* true_target, |
| 963 | Label* false_target, |
| 964 | Label* always_true_target) { |
| 965 | LocationSummary* locations = condition->GetLocations(); |
| 966 | Location left = locations->InAt(0); |
| 967 | Location right = locations->InAt(1); |
| 968 | |
| 969 | // We don't want true_target as a nullptr. |
| 970 | if (true_target == nullptr) { |
| 971 | true_target = always_true_target; |
| 972 | } |
| 973 | bool falls_through = (false_target == nullptr); |
| 974 | |
| 975 | // FP compares don't like null false_targets. |
| 976 | if (false_target == nullptr) { |
| 977 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 978 | } |
| 979 | |
| 980 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 981 | switch (type) { |
| 982 | case Primitive::kPrimLong: { |
| 983 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 984 | if (right.IsConstant()) { |
| 985 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 986 | if (IsInt<32>(value)) { |
| 987 | if (value == 0) { |
| 988 | __ testq(left_reg, left_reg); |
| 989 | } else { |
| 990 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 991 | } |
| 992 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 993 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 994 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 995 | } |
| 996 | } else if (right.IsDoubleStackSlot()) { |
| 997 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 998 | } else { |
| 999 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1000 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1001 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1002 | break; |
| 1003 | } |
| 1004 | case Primitive::kPrimFloat: { |
| 1005 | if (right.IsFpuRegister()) { |
| 1006 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1007 | } else if (right.IsConstant()) { |
| 1008 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1009 | codegen_->LiteralFloatAddress( |
| 1010 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1011 | } else { |
| 1012 | DCHECK(right.IsStackSlot()); |
| 1013 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1014 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1015 | } |
| 1016 | GenerateFPJumps(condition, true_target, false_target); |
| 1017 | break; |
| 1018 | } |
| 1019 | case Primitive::kPrimDouble: { |
| 1020 | if (right.IsFpuRegister()) { |
| 1021 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1022 | } else if (right.IsConstant()) { |
| 1023 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1024 | codegen_->LiteralDoubleAddress( |
| 1025 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1026 | } else { |
| 1027 | DCHECK(right.IsDoubleStackSlot()); |
| 1028 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1029 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1030 | } |
| 1031 | GenerateFPJumps(condition, true_target, false_target); |
| 1032 | break; |
| 1033 | } |
| 1034 | default: |
| 1035 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1036 | } |
| 1037 | |
| 1038 | if (!falls_through) { |
| 1039 | __ jmp(false_target); |
| 1040 | } |
| 1041 | } |
| 1042 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1043 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| 1044 | Label* true_target, |
| 1045 | Label* false_target, |
| 1046 | Label* always_true_target) { |
| 1047 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1048 | if (cond->IsIntConstant()) { |
| 1049 | // Constant condition, statically compared against 1. |
| 1050 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1051 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1052 | if (always_true_target != nullptr) { |
| 1053 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1054 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1055 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1056 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1057 | DCHECK_EQ(cond_value, 0); |
| 1058 | } |
| 1059 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1060 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1061 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1062 | // Moves do not affect the eflags register, so if the condition is |
| 1063 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1064 | // again. We can't use the eflags on FP conditions if they are |
| 1065 | // materialized due to the complex branching. |
| 1066 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1067 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1068 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
| 1069 | && !Primitive::IsFloatingPointType(type); |
| 1070 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1071 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1072 | if (!eflags_set) { |
| 1073 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1074 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1075 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1076 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1077 | } else { |
| 1078 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 1079 | Immediate(0)); |
| 1080 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1081 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1082 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1083 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1084 | } |
| 1085 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1086 | // Condition has not been materialized, use its inputs as the |
| 1087 | // comparison and its condition as the branch condition. |
| 1088 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1089 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1090 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1091 | // Generate the comparison directly. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1092 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1093 | true_target, false_target, always_true_target); |
| 1094 | return; |
| 1095 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1096 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1097 | Location lhs = cond->GetLocations()->InAt(0); |
| 1098 | Location rhs = cond->GetLocations()->InAt(1); |
| 1099 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1100 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1101 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1102 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1103 | if (constant == 0) { |
| 1104 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1105 | } else { |
| 1106 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1107 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1108 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1109 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1110 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1111 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1112 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1113 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1114 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1115 | if (false_target != nullptr) { |
| 1116 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1120 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| 1121 | LocationSummary* locations = |
| 1122 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1123 | HInstruction* cond = if_instr->InputAt(0); |
| 1124 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1125 | locations->SetInAt(0, Location::Any()); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| 1130 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1131 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1132 | Label* always_true_target = true_target; |
| 1133 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1134 | if_instr->IfTrueSuccessor())) { |
| 1135 | always_true_target = nullptr; |
| 1136 | } |
| 1137 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1138 | if_instr->IfFalseSuccessor())) { |
| 1139 | false_target = nullptr; |
| 1140 | } |
| 1141 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1142 | } |
| 1143 | |
| 1144 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1145 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1146 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1147 | HInstruction* cond = deoptimize->InputAt(0); |
| 1148 | DCHECK(cond->IsCondition()); |
| 1149 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1150 | locations->SetInAt(0, Location::Any()); |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1155 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) |
| 1156 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1157 | codegen_->AddSlowPath(slow_path); |
| 1158 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1159 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1160 | } |
| 1161 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1162 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1163 | local->SetLocations(nullptr); |
| 1164 | } |
| 1165 | |
| 1166 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1167 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1168 | } |
| 1169 | |
| 1170 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1171 | local->SetLocations(nullptr); |
| 1172 | } |
| 1173 | |
| 1174 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 1175 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1176 | UNUSED(load); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1180 | LocationSummary* locations = |
| 1181 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1182 | switch (store->InputAt(1)->GetType()) { |
| 1183 | case Primitive::kPrimBoolean: |
| 1184 | case Primitive::kPrimByte: |
| 1185 | case Primitive::kPrimChar: |
| 1186 | case Primitive::kPrimShort: |
| 1187 | case Primitive::kPrimInt: |
| 1188 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1189 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1190 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1191 | break; |
| 1192 | |
| 1193 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1194 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1195 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1196 | break; |
| 1197 | |
| 1198 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1199 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1200 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1204 | UNUSED(store); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1205 | } |
| 1206 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1207 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1208 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1209 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1210 | // Handle the long/FP comparisons made in instruction simplification. |
| 1211 | switch (cond->InputAt(0)->GetType()) { |
| 1212 | case Primitive::kPrimLong: |
| 1213 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1214 | locations->SetInAt(1, Location::Any()); |
| 1215 | break; |
| 1216 | case Primitive::kPrimFloat: |
| 1217 | case Primitive::kPrimDouble: |
| 1218 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1219 | locations->SetInAt(1, Location::Any()); |
| 1220 | break; |
| 1221 | default: |
| 1222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1223 | locations->SetInAt(1, Location::Any()); |
| 1224 | break; |
| 1225 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1226 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1227 | locations->SetOut(Location::RequiresRegister()); |
| 1228 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1229 | } |
| 1230 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1231 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1232 | if (!cond->NeedsMaterialization()) { |
| 1233 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1234 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1235 | |
| 1236 | LocationSummary* locations = cond->GetLocations(); |
| 1237 | Location lhs = locations->InAt(0); |
| 1238 | Location rhs = locations->InAt(1); |
| 1239 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1240 | Label true_label, false_label; |
| 1241 | |
| 1242 | switch (cond->InputAt(0)->GetType()) { |
| 1243 | default: |
| 1244 | // Integer case. |
| 1245 | |
| 1246 | // Clear output register: setcc only sets the low byte. |
| 1247 | __ xorl(reg, reg); |
| 1248 | |
| 1249 | if (rhs.IsRegister()) { |
| 1250 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1251 | } else if (rhs.IsConstant()) { |
| 1252 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1253 | if (constant == 0) { |
| 1254 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1255 | } else { |
| 1256 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1257 | } |
| 1258 | } else { |
| 1259 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1260 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1261 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1262 | return; |
| 1263 | case Primitive::kPrimLong: |
| 1264 | // Clear output register: setcc only sets the low byte. |
| 1265 | __ xorl(reg, reg); |
| 1266 | |
| 1267 | if (rhs.IsRegister()) { |
| 1268 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1269 | } else if (rhs.IsConstant()) { |
| 1270 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1271 | if (IsInt<32>(value)) { |
| 1272 | if (value == 0) { |
| 1273 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1274 | } else { |
| 1275 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1276 | } |
| 1277 | } else { |
| 1278 | // Value won't fit in an int. |
| 1279 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1280 | } |
| 1281 | } else { |
| 1282 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1283 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1284 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1285 | return; |
| 1286 | case Primitive::kPrimFloat: { |
| 1287 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1288 | if (rhs.IsConstant()) { |
| 1289 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1290 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1291 | } else if (rhs.IsStackSlot()) { |
| 1292 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1293 | } else { |
| 1294 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1295 | } |
| 1296 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1297 | break; |
| 1298 | } |
| 1299 | case Primitive::kPrimDouble: { |
| 1300 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1301 | if (rhs.IsConstant()) { |
| 1302 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1303 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1304 | } else if (rhs.IsDoubleStackSlot()) { |
| 1305 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1306 | } else { |
| 1307 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1308 | } |
| 1309 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1310 | break; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | // Convert the jumps into the result. |
| 1315 | Label done_label; |
| 1316 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1317 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1318 | __ Bind(&false_label); |
| 1319 | __ xorl(reg, reg); |
| 1320 | __ jmp(&done_label); |
| 1321 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1322 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1323 | __ Bind(&true_label); |
| 1324 | __ movl(reg, Immediate(1)); |
| 1325 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1329 | VisitCondition(comp); |
| 1330 | } |
| 1331 | |
| 1332 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1333 | VisitCondition(comp); |
| 1334 | } |
| 1335 | |
| 1336 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1337 | VisitCondition(comp); |
| 1338 | } |
| 1339 | |
| 1340 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1341 | VisitCondition(comp); |
| 1342 | } |
| 1343 | |
| 1344 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1345 | VisitCondition(comp); |
| 1346 | } |
| 1347 | |
| 1348 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1349 | VisitCondition(comp); |
| 1350 | } |
| 1351 | |
| 1352 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1353 | VisitCondition(comp); |
| 1354 | } |
| 1355 | |
| 1356 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1357 | VisitCondition(comp); |
| 1358 | } |
| 1359 | |
| 1360 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1361 | VisitCondition(comp); |
| 1362 | } |
| 1363 | |
| 1364 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1365 | VisitCondition(comp); |
| 1366 | } |
| 1367 | |
| 1368 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1369 | VisitCondition(comp); |
| 1370 | } |
| 1371 | |
| 1372 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1373 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1376 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1377 | LocationSummary* locations = |
| 1378 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1379 | switch (compare->InputAt(0)->GetType()) { |
| 1380 | case Primitive::kPrimLong: { |
| 1381 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1382 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1383 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1384 | break; |
| 1385 | } |
| 1386 | case Primitive::kPrimFloat: |
| 1387 | case Primitive::kPrimDouble: { |
| 1388 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1389 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1390 | locations->SetOut(Location::RequiresRegister()); |
| 1391 | break; |
| 1392 | } |
| 1393 | default: |
| 1394 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1395 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1399 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1400 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1401 | Location left = locations->InAt(0); |
| 1402 | Location right = locations->InAt(1); |
| 1403 | |
| 1404 | Label less, greater, done; |
| 1405 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1406 | switch (type) { |
| 1407 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1408 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1409 | if (right.IsConstant()) { |
| 1410 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1411 | if (IsInt<32>(value)) { |
| 1412 | if (value == 0) { |
| 1413 | __ testq(left_reg, left_reg); |
| 1414 | } else { |
| 1415 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1416 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1417 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1418 | // Value won't fit in an int. |
| 1419 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1420 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1421 | } else if (right.IsDoubleStackSlot()) { |
| 1422 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1423 | } else { |
| 1424 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1425 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1426 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1427 | } |
| 1428 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1429 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1430 | if (right.IsConstant()) { |
| 1431 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1432 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1433 | } else if (right.IsStackSlot()) { |
| 1434 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1435 | } else { |
| 1436 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1437 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1438 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1439 | break; |
| 1440 | } |
| 1441 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1442 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1443 | if (right.IsConstant()) { |
| 1444 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1445 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1446 | } else if (right.IsDoubleStackSlot()) { |
| 1447 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1448 | } else { |
| 1449 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1450 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1451 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1452 | break; |
| 1453 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1454 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1455 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1456 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1457 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1458 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1459 | __ 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] | 1460 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1461 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1462 | __ movl(out, Immediate(1)); |
| 1463 | __ jmp(&done); |
| 1464 | |
| 1465 | __ Bind(&less); |
| 1466 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1467 | |
| 1468 | __ Bind(&done); |
| 1469 | } |
| 1470 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1471 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1472 | LocationSummary* locations = |
| 1473 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1474 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1478 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1479 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1480 | } |
| 1481 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1482 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1483 | LocationSummary* locations = |
| 1484 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1485 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1486 | } |
| 1487 | |
| 1488 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1489 | // Will be generated at use site. |
| 1490 | UNUSED(constant); |
| 1491 | } |
| 1492 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1493 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1494 | LocationSummary* locations = |
| 1495 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1496 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1500 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1501 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1502 | } |
| 1503 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1504 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1505 | LocationSummary* locations = |
| 1506 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1507 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1508 | } |
| 1509 | |
| 1510 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1511 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1512 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1516 | LocationSummary* locations = |
| 1517 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1518 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1519 | } |
| 1520 | |
| 1521 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1522 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1523 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1524 | } |
| 1525 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1526 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1527 | memory_barrier->SetLocations(nullptr); |
| 1528 | } |
| 1529 | |
| 1530 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1531 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1532 | } |
| 1533 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1534 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1535 | ret->SetLocations(nullptr); |
| 1536 | } |
| 1537 | |
| 1538 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1539 | UNUSED(ret); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1540 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1544 | LocationSummary* locations = |
| 1545 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1546 | switch (ret->InputAt(0)->GetType()) { |
| 1547 | case Primitive::kPrimBoolean: |
| 1548 | case Primitive::kPrimByte: |
| 1549 | case Primitive::kPrimChar: |
| 1550 | case Primitive::kPrimShort: |
| 1551 | case Primitive::kPrimInt: |
| 1552 | case Primitive::kPrimNot: |
| 1553 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1554 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1555 | break; |
| 1556 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1557 | case Primitive::kPrimFloat: |
| 1558 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1559 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1560 | break; |
| 1561 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1562 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1563 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1564 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1568 | if (kIsDebugBuild) { |
| 1569 | switch (ret->InputAt(0)->GetType()) { |
| 1570 | case Primitive::kPrimBoolean: |
| 1571 | case Primitive::kPrimByte: |
| 1572 | case Primitive::kPrimChar: |
| 1573 | case Primitive::kPrimShort: |
| 1574 | case Primitive::kPrimInt: |
| 1575 | case Primitive::kPrimNot: |
| 1576 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1577 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1578 | break; |
| 1579 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1580 | case Primitive::kPrimFloat: |
| 1581 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1582 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1583 | XMM0); |
| 1584 | break; |
| 1585 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1586 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1587 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1588 | } |
| 1589 | } |
| 1590 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1591 | } |
| 1592 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1593 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1594 | switch (type) { |
| 1595 | case Primitive::kPrimBoolean: |
| 1596 | case Primitive::kPrimByte: |
| 1597 | case Primitive::kPrimChar: |
| 1598 | case Primitive::kPrimShort: |
| 1599 | case Primitive::kPrimInt: |
| 1600 | case Primitive::kPrimNot: |
| 1601 | case Primitive::kPrimLong: |
| 1602 | return Location::RegisterLocation(RAX); |
| 1603 | |
| 1604 | case Primitive::kPrimVoid: |
| 1605 | return Location::NoLocation(); |
| 1606 | |
| 1607 | case Primitive::kPrimDouble: |
| 1608 | case Primitive::kPrimFloat: |
| 1609 | return Location::FpuRegisterLocation(XMM0); |
| 1610 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1611 | |
| 1612 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 1616 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1617 | } |
| 1618 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1619 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1620 | switch (type) { |
| 1621 | case Primitive::kPrimBoolean: |
| 1622 | case Primitive::kPrimByte: |
| 1623 | case Primitive::kPrimChar: |
| 1624 | case Primitive::kPrimShort: |
| 1625 | case Primitive::kPrimInt: |
| 1626 | case Primitive::kPrimNot: { |
| 1627 | uint32_t index = gp_index_++; |
| 1628 | stack_index_++; |
| 1629 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1630 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1631 | } else { |
| 1632 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | case Primitive::kPrimLong: { |
| 1637 | uint32_t index = gp_index_; |
| 1638 | stack_index_ += 2; |
| 1639 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1640 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1641 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1642 | } else { |
| 1643 | gp_index_ += 2; |
| 1644 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1645 | } |
| 1646 | } |
| 1647 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1648 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1649 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1650 | stack_index_++; |
| 1651 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1652 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1653 | } else { |
| 1654 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1659 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1660 | stack_index_ += 2; |
| 1661 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1662 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1663 | } else { |
| 1664 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1665 | } |
| 1666 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1667 | |
| 1668 | case Primitive::kPrimVoid: |
| 1669 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1670 | break; |
| 1671 | } |
| 1672 | return Location(); |
| 1673 | } |
| 1674 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1675 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1676 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1677 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1678 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1679 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1680 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1681 | if (intrinsic.TryDispatch(invoke)) { |
| 1682 | return; |
| 1683 | } |
| 1684 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1685 | HandleInvoke(invoke); |
| 1686 | } |
| 1687 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1688 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 1689 | if (invoke->GetLocations()->Intrinsified()) { |
| 1690 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 1691 | intrinsic.Dispatch(invoke); |
| 1692 | return true; |
| 1693 | } |
| 1694 | return false; |
| 1695 | } |
| 1696 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1697 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1698 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1699 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1700 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1701 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1702 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1703 | return; |
| 1704 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1705 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1706 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1707 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1708 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1709 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1710 | } |
| 1711 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1712 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1713 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1714 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1717 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1718 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1719 | if (intrinsic.TryDispatch(invoke)) { |
| 1720 | return; |
| 1721 | } |
| 1722 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1723 | HandleInvoke(invoke); |
| 1724 | } |
| 1725 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1726 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1727 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1728 | return; |
| 1729 | } |
| 1730 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame^] | 1731 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1732 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1733 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1734 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1735 | } |
| 1736 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1737 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1738 | HandleInvoke(invoke); |
| 1739 | // Add the hidden argument. |
| 1740 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1741 | } |
| 1742 | |
| 1743 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1744 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1745 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1746 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1747 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1748 | LocationSummary* locations = invoke->GetLocations(); |
| 1749 | Location receiver = locations->InAt(0); |
| 1750 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1751 | |
| 1752 | // Set the hidden argument. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1753 | CpuRegister hidden_reg = invoke->GetLocations()->GetTemp(1).AsRegister<CpuRegister>(); |
| 1754 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1755 | |
| 1756 | // temp = object->GetClass(); |
| 1757 | if (receiver.IsStackSlot()) { |
| 1758 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1759 | __ movl(temp, Address(temp, class_offset)); |
| 1760 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1761 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1762 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1763 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1764 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1765 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1766 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1767 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1768 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1769 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1770 | |
| 1771 | DCHECK(!codegen_->IsLeafMethod()); |
| 1772 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1773 | } |
| 1774 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1775 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1776 | LocationSummary* locations = |
| 1777 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1778 | switch (neg->GetResultType()) { |
| 1779 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1780 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1781 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1782 | locations->SetOut(Location::SameAsFirstInput()); |
| 1783 | break; |
| 1784 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1785 | case Primitive::kPrimFloat: |
| 1786 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1787 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1788 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1789 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1790 | break; |
| 1791 | |
| 1792 | default: |
| 1793 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1798 | LocationSummary* locations = neg->GetLocations(); |
| 1799 | Location out = locations->Out(); |
| 1800 | Location in = locations->InAt(0); |
| 1801 | switch (neg->GetResultType()) { |
| 1802 | case Primitive::kPrimInt: |
| 1803 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1804 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1805 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1806 | break; |
| 1807 | |
| 1808 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 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 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1812 | break; |
| 1813 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1814 | case Primitive::kPrimFloat: { |
| 1815 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1816 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1817 | // Implement float negation with an exclusive or with value |
| 1818 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1819 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1820 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1821 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1822 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1823 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1824 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1825 | case Primitive::kPrimDouble: { |
| 1826 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1827 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1828 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1829 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1830 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1831 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1832 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1833 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1834 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1835 | |
| 1836 | default: |
| 1837 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1838 | } |
| 1839 | } |
| 1840 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1841 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1842 | LocationSummary* locations = |
| 1843 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1844 | Primitive::Type result_type = conversion->GetResultType(); |
| 1845 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1846 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1847 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1848 | // The Java language does not allow treating boolean as an integral type but |
| 1849 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1850 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1851 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1852 | case Primitive::kPrimByte: |
| 1853 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1854 | case Primitive::kPrimBoolean: |
| 1855 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1856 | case Primitive::kPrimShort: |
| 1857 | case Primitive::kPrimInt: |
| 1858 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1859 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1860 | locations->SetInAt(0, Location::Any()); |
| 1861 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1862 | break; |
| 1863 | |
| 1864 | default: |
| 1865 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1866 | << " to " << result_type; |
| 1867 | } |
| 1868 | break; |
| 1869 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1870 | case Primitive::kPrimShort: |
| 1871 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1872 | case Primitive::kPrimBoolean: |
| 1873 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1874 | case Primitive::kPrimByte: |
| 1875 | case Primitive::kPrimInt: |
| 1876 | case Primitive::kPrimChar: |
| 1877 | // Processing a Dex `int-to-short' instruction. |
| 1878 | locations->SetInAt(0, Location::Any()); |
| 1879 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1880 | break; |
| 1881 | |
| 1882 | default: |
| 1883 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1884 | << " to " << result_type; |
| 1885 | } |
| 1886 | break; |
| 1887 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1888 | case Primitive::kPrimInt: |
| 1889 | switch (input_type) { |
| 1890 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1891 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1892 | locations->SetInAt(0, Location::Any()); |
| 1893 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1894 | break; |
| 1895 | |
| 1896 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1897 | // Processing a Dex `float-to-int' instruction. |
| 1898 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1899 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1900 | break; |
| 1901 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1902 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1903 | // Processing a Dex `double-to-int' instruction. |
| 1904 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1905 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1906 | break; |
| 1907 | |
| 1908 | default: |
| 1909 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1910 | << " to " << result_type; |
| 1911 | } |
| 1912 | break; |
| 1913 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1914 | case Primitive::kPrimLong: |
| 1915 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1916 | case Primitive::kPrimBoolean: |
| 1917 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1918 | case Primitive::kPrimByte: |
| 1919 | case Primitive::kPrimShort: |
| 1920 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1921 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1922 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1923 | // TODO: We would benefit from a (to-be-implemented) |
| 1924 | // Location::RegisterOrStackSlot requirement for this input. |
| 1925 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1926 | locations->SetOut(Location::RequiresRegister()); |
| 1927 | break; |
| 1928 | |
| 1929 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1930 | // Processing a Dex `float-to-long' instruction. |
| 1931 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1932 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1933 | break; |
| 1934 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1935 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1936 | // Processing a Dex `double-to-long' instruction. |
| 1937 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1938 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1939 | break; |
| 1940 | |
| 1941 | default: |
| 1942 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1943 | << " to " << result_type; |
| 1944 | } |
| 1945 | break; |
| 1946 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1947 | case Primitive::kPrimChar: |
| 1948 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1949 | case Primitive::kPrimBoolean: |
| 1950 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1951 | case Primitive::kPrimByte: |
| 1952 | case Primitive::kPrimShort: |
| 1953 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1954 | // Processing a Dex `int-to-char' instruction. |
| 1955 | locations->SetInAt(0, Location::Any()); |
| 1956 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1957 | break; |
| 1958 | |
| 1959 | default: |
| 1960 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1961 | << " to " << result_type; |
| 1962 | } |
| 1963 | break; |
| 1964 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1965 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1966 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1967 | case Primitive::kPrimBoolean: |
| 1968 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1969 | case Primitive::kPrimByte: |
| 1970 | case Primitive::kPrimShort: |
| 1971 | case Primitive::kPrimInt: |
| 1972 | case Primitive::kPrimChar: |
| 1973 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1974 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1975 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1976 | break; |
| 1977 | |
| 1978 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1979 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1980 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1981 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1982 | break; |
| 1983 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1984 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1985 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1986 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1987 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1988 | break; |
| 1989 | |
| 1990 | default: |
| 1991 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1992 | << " to " << result_type; |
| 1993 | }; |
| 1994 | break; |
| 1995 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1996 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1997 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1998 | case Primitive::kPrimBoolean: |
| 1999 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2000 | case Primitive::kPrimByte: |
| 2001 | case Primitive::kPrimShort: |
| 2002 | case Primitive::kPrimInt: |
| 2003 | case Primitive::kPrimChar: |
| 2004 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2005 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2006 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2007 | break; |
| 2008 | |
| 2009 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2010 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2011 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2012 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2013 | break; |
| 2014 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2015 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2016 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2017 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2018 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2019 | break; |
| 2020 | |
| 2021 | default: |
| 2022 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2023 | << " to " << result_type; |
| 2024 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2025 | break; |
| 2026 | |
| 2027 | default: |
| 2028 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2029 | << " to " << result_type; |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2034 | LocationSummary* locations = conversion->GetLocations(); |
| 2035 | Location out = locations->Out(); |
| 2036 | Location in = locations->InAt(0); |
| 2037 | Primitive::Type result_type = conversion->GetResultType(); |
| 2038 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2039 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2040 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2041 | case Primitive::kPrimByte: |
| 2042 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2043 | case Primitive::kPrimBoolean: |
| 2044 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2045 | case Primitive::kPrimShort: |
| 2046 | case Primitive::kPrimInt: |
| 2047 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2048 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2049 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2050 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2051 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2052 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2053 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2054 | } else { |
| 2055 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2056 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2057 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2058 | } |
| 2059 | break; |
| 2060 | |
| 2061 | default: |
| 2062 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2063 | << " to " << result_type; |
| 2064 | } |
| 2065 | break; |
| 2066 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2067 | case Primitive::kPrimShort: |
| 2068 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2069 | case Primitive::kPrimBoolean: |
| 2070 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2071 | case Primitive::kPrimByte: |
| 2072 | case Primitive::kPrimInt: |
| 2073 | case Primitive::kPrimChar: |
| 2074 | // Processing a Dex `int-to-short' instruction. |
| 2075 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2076 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2077 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2078 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2079 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2080 | } else { |
| 2081 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2082 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2083 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2084 | } |
| 2085 | break; |
| 2086 | |
| 2087 | default: |
| 2088 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2089 | << " to " << result_type; |
| 2090 | } |
| 2091 | break; |
| 2092 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2093 | case Primitive::kPrimInt: |
| 2094 | switch (input_type) { |
| 2095 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2096 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2097 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2098 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2099 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2100 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2101 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2102 | } else { |
| 2103 | DCHECK(in.IsConstant()); |
| 2104 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2105 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2106 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2107 | } |
| 2108 | break; |
| 2109 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2110 | case Primitive::kPrimFloat: { |
| 2111 | // Processing a Dex `float-to-int' instruction. |
| 2112 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2113 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2114 | Label done, nan; |
| 2115 | |
| 2116 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2117 | // if input >= (float)INT_MAX goto done |
| 2118 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2119 | __ j(kAboveEqual, &done); |
| 2120 | // if input == NaN goto nan |
| 2121 | __ j(kUnordered, &nan); |
| 2122 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2123 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2124 | __ jmp(&done); |
| 2125 | __ Bind(&nan); |
| 2126 | // output = 0 |
| 2127 | __ xorl(output, output); |
| 2128 | __ Bind(&done); |
| 2129 | break; |
| 2130 | } |
| 2131 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2132 | case Primitive::kPrimDouble: { |
| 2133 | // Processing a Dex `double-to-int' instruction. |
| 2134 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2135 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2136 | Label done, nan; |
| 2137 | |
| 2138 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2139 | // if input >= (double)INT_MAX goto done |
| 2140 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2141 | __ j(kAboveEqual, &done); |
| 2142 | // if input == NaN goto nan |
| 2143 | __ j(kUnordered, &nan); |
| 2144 | // output = double-to-int-truncate(input) |
| 2145 | __ cvttsd2si(output, input); |
| 2146 | __ jmp(&done); |
| 2147 | __ Bind(&nan); |
| 2148 | // output = 0 |
| 2149 | __ xorl(output, output); |
| 2150 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2151 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2152 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2153 | |
| 2154 | default: |
| 2155 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2156 | << " to " << result_type; |
| 2157 | } |
| 2158 | break; |
| 2159 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2160 | case Primitive::kPrimLong: |
| 2161 | switch (input_type) { |
| 2162 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2163 | case Primitive::kPrimBoolean: |
| 2164 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2165 | case Primitive::kPrimByte: |
| 2166 | case Primitive::kPrimShort: |
| 2167 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2168 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2169 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2170 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2171 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2172 | break; |
| 2173 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2174 | case Primitive::kPrimFloat: { |
| 2175 | // Processing a Dex `float-to-long' instruction. |
| 2176 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2177 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2178 | Label done, nan; |
| 2179 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2180 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2181 | // if input >= (float)LONG_MAX goto done |
| 2182 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2183 | __ j(kAboveEqual, &done); |
| 2184 | // if input == NaN goto nan |
| 2185 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2186 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2187 | __ cvttss2si(output, input, true); |
| 2188 | __ jmp(&done); |
| 2189 | __ Bind(&nan); |
| 2190 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2191 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2192 | __ Bind(&done); |
| 2193 | break; |
| 2194 | } |
| 2195 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2196 | case Primitive::kPrimDouble: { |
| 2197 | // Processing a Dex `double-to-long' instruction. |
| 2198 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2199 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2200 | Label done, nan; |
| 2201 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2202 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2203 | // if input >= (double)LONG_MAX goto done |
| 2204 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2205 | __ j(kAboveEqual, &done); |
| 2206 | // if input == NaN goto nan |
| 2207 | __ j(kUnordered, &nan); |
| 2208 | // output = double-to-long-truncate(input) |
| 2209 | __ cvttsd2si(output, input, true); |
| 2210 | __ jmp(&done); |
| 2211 | __ Bind(&nan); |
| 2212 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2213 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2214 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2215 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2216 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2217 | |
| 2218 | default: |
| 2219 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2220 | << " to " << result_type; |
| 2221 | } |
| 2222 | break; |
| 2223 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2224 | case Primitive::kPrimChar: |
| 2225 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2226 | case Primitive::kPrimBoolean: |
| 2227 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2228 | case Primitive::kPrimByte: |
| 2229 | case Primitive::kPrimShort: |
| 2230 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2231 | // Processing a Dex `int-to-char' instruction. |
| 2232 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2233 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2234 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2235 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2236 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2237 | } else { |
| 2238 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2239 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2240 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2241 | } |
| 2242 | break; |
| 2243 | |
| 2244 | default: |
| 2245 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2246 | << " to " << result_type; |
| 2247 | } |
| 2248 | break; |
| 2249 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2250 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2251 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2252 | case Primitive::kPrimBoolean: |
| 2253 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2254 | case Primitive::kPrimByte: |
| 2255 | case Primitive::kPrimShort: |
| 2256 | case Primitive::kPrimInt: |
| 2257 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2258 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2259 | if (in.IsRegister()) { |
| 2260 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2261 | } else if (in.IsConstant()) { |
| 2262 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2263 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2264 | if (v == 0) { |
| 2265 | __ xorps(dest, dest); |
| 2266 | } else { |
| 2267 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2268 | } |
| 2269 | } else { |
| 2270 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2271 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2272 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2273 | break; |
| 2274 | |
| 2275 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2276 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2277 | if (in.IsRegister()) { |
| 2278 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2279 | } else if (in.IsConstant()) { |
| 2280 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2281 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2282 | if (v == 0) { |
| 2283 | __ xorps(dest, dest); |
| 2284 | } else { |
| 2285 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2286 | } |
| 2287 | } else { |
| 2288 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2289 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2290 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2293 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2294 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2295 | if (in.IsFpuRegister()) { |
| 2296 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2297 | } else if (in.IsConstant()) { |
| 2298 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2299 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2300 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2301 | __ xorps(dest, dest); |
| 2302 | } else { |
| 2303 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2304 | } |
| 2305 | } else { |
| 2306 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2307 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2308 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2309 | break; |
| 2310 | |
| 2311 | default: |
| 2312 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2313 | << " to " << result_type; |
| 2314 | }; |
| 2315 | break; |
| 2316 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2317 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2318 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2319 | case Primitive::kPrimBoolean: |
| 2320 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2321 | case Primitive::kPrimByte: |
| 2322 | case Primitive::kPrimShort: |
| 2323 | case Primitive::kPrimInt: |
| 2324 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2325 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2326 | if (in.IsRegister()) { |
| 2327 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2328 | } else if (in.IsConstant()) { |
| 2329 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2330 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2331 | if (v == 0) { |
| 2332 | __ xorpd(dest, dest); |
| 2333 | } else { |
| 2334 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2335 | } |
| 2336 | } else { |
| 2337 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2338 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2339 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2340 | break; |
| 2341 | |
| 2342 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2343 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2344 | if (in.IsRegister()) { |
| 2345 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2346 | } else if (in.IsConstant()) { |
| 2347 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2348 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2349 | if (v == 0) { |
| 2350 | __ xorpd(dest, dest); |
| 2351 | } else { |
| 2352 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2353 | } |
| 2354 | } else { |
| 2355 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2356 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2357 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2358 | break; |
| 2359 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2360 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2361 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2362 | if (in.IsFpuRegister()) { |
| 2363 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2364 | } else if (in.IsConstant()) { |
| 2365 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2366 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2367 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2368 | __ xorpd(dest, dest); |
| 2369 | } else { |
| 2370 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2371 | } |
| 2372 | } else { |
| 2373 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2374 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2375 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2376 | break; |
| 2377 | |
| 2378 | default: |
| 2379 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2380 | << " to " << result_type; |
| 2381 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2382 | break; |
| 2383 | |
| 2384 | default: |
| 2385 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2386 | << " to " << result_type; |
| 2387 | } |
| 2388 | } |
| 2389 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2390 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2391 | LocationSummary* locations = |
| 2392 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2393 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2394 | case Primitive::kPrimInt: { |
| 2395 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2396 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2397 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2398 | break; |
| 2399 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2400 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2401 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2402 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2403 | // 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] | 2404 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2405 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2406 | break; |
| 2407 | } |
| 2408 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2409 | case Primitive::kPrimDouble: |
| 2410 | case Primitive::kPrimFloat: { |
| 2411 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2412 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2413 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2414 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2415 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2416 | |
| 2417 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2418 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2419 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2423 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2424 | Location first = locations->InAt(0); |
| 2425 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2426 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2427 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2428 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2429 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2430 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2431 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2432 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2433 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2434 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2435 | } else { |
| 2436 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2437 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2438 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2439 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2440 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2441 | __ addl(out.AsRegister<CpuRegister>(), |
| 2442 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2443 | } else { |
| 2444 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2445 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2446 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2447 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2448 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2449 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2450 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2451 | break; |
| 2452 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2453 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2454 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2455 | if (second.IsRegister()) { |
| 2456 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2457 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2458 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2459 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2460 | } else { |
| 2461 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2462 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2463 | } |
| 2464 | } else { |
| 2465 | DCHECK(second.IsConstant()); |
| 2466 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2467 | int32_t int32_value = Low32Bits(value); |
| 2468 | DCHECK_EQ(int32_value, value); |
| 2469 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2470 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2471 | } else { |
| 2472 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2473 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2474 | } |
| 2475 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2476 | break; |
| 2477 | } |
| 2478 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2479 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2480 | if (second.IsFpuRegister()) { |
| 2481 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2482 | } else if (second.IsConstant()) { |
| 2483 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2484 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2485 | } else { |
| 2486 | DCHECK(second.IsStackSlot()); |
| 2487 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2488 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2489 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2490 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2494 | if (second.IsFpuRegister()) { |
| 2495 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2496 | } else if (second.IsConstant()) { |
| 2497 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2498 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2499 | } else { |
| 2500 | DCHECK(second.IsDoubleStackSlot()); |
| 2501 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2502 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2503 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2504 | break; |
| 2505 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2506 | |
| 2507 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2508 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2513 | LocationSummary* locations = |
| 2514 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2515 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2516 | case Primitive::kPrimInt: { |
| 2517 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2518 | locations->SetInAt(1, Location::Any()); |
| 2519 | locations->SetOut(Location::SameAsFirstInput()); |
| 2520 | break; |
| 2521 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2522 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2523 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2524 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2525 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2526 | break; |
| 2527 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2528 | case Primitive::kPrimFloat: |
| 2529 | case Primitive::kPrimDouble: { |
| 2530 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2531 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2532 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2533 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2534 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2535 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2536 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2537 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2541 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2542 | Location first = locations->InAt(0); |
| 2543 | Location second = locations->InAt(1); |
| 2544 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2545 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2546 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2547 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2548 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2549 | } else if (second.IsConstant()) { |
| 2550 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2551 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2552 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2553 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2554 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2555 | break; |
| 2556 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2557 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2558 | if (second.IsConstant()) { |
| 2559 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2560 | DCHECK(IsInt<32>(value)); |
| 2561 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2562 | } else { |
| 2563 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2564 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2565 | break; |
| 2566 | } |
| 2567 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2568 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2569 | if (second.IsFpuRegister()) { |
| 2570 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2571 | } else if (second.IsConstant()) { |
| 2572 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2573 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2574 | } else { |
| 2575 | DCHECK(second.IsStackSlot()); |
| 2576 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2577 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2578 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2579 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2583 | if (second.IsFpuRegister()) { |
| 2584 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2585 | } else if (second.IsConstant()) { |
| 2586 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2587 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2588 | } else { |
| 2589 | DCHECK(second.IsDoubleStackSlot()); |
| 2590 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2591 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2592 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2593 | break; |
| 2594 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2595 | |
| 2596 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2597 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2598 | } |
| 2599 | } |
| 2600 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2601 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2602 | LocationSummary* locations = |
| 2603 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2604 | switch (mul->GetResultType()) { |
| 2605 | case Primitive::kPrimInt: { |
| 2606 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2607 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2608 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2609 | // Can use 3 operand multiply. |
| 2610 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2611 | } else { |
| 2612 | locations->SetOut(Location::SameAsFirstInput()); |
| 2613 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2614 | break; |
| 2615 | } |
| 2616 | case Primitive::kPrimLong: { |
| 2617 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2618 | locations->SetInAt(1, Location::Any()); |
| 2619 | if (mul->InputAt(1)->IsLongConstant() && |
| 2620 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2621 | // Can use 3 operand multiply. |
| 2622 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2623 | } else { |
| 2624 | locations->SetOut(Location::SameAsFirstInput()); |
| 2625 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2626 | break; |
| 2627 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2628 | case Primitive::kPrimFloat: |
| 2629 | case Primitive::kPrimDouble: { |
| 2630 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2631 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2632 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2633 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2634 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2635 | |
| 2636 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2637 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2642 | LocationSummary* locations = mul->GetLocations(); |
| 2643 | Location first = locations->InAt(0); |
| 2644 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2645 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2646 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2647 | case Primitive::kPrimInt: |
| 2648 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2649 | // problems where the output may not be the same as the first operand. |
| 2650 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2651 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2652 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 2653 | } else if (second.IsRegister()) { |
| 2654 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2655 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2656 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2657 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2658 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2659 | __ imull(first.AsRegister<CpuRegister>(), |
| 2660 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2661 | } |
| 2662 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2663 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2664 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2665 | // problems where the output may not be the same as the first operand. |
| 2666 | if (mul->InputAt(1)->IsLongConstant()) { |
| 2667 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 2668 | if (IsInt<32>(value)) { |
| 2669 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 2670 | Immediate(static_cast<int32_t>(value))); |
| 2671 | } else { |
| 2672 | // Have to use the constant area. |
| 2673 | DCHECK(first.Equals(out)); |
| 2674 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 2675 | } |
| 2676 | } else if (second.IsRegister()) { |
| 2677 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2678 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2679 | } else { |
| 2680 | DCHECK(second.IsDoubleStackSlot()); |
| 2681 | DCHECK(first.Equals(out)); |
| 2682 | __ imulq(first.AsRegister<CpuRegister>(), |
| 2683 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2684 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2685 | break; |
| 2686 | } |
| 2687 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2688 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2689 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2690 | if (second.IsFpuRegister()) { |
| 2691 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2692 | } else if (second.IsConstant()) { |
| 2693 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2694 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2695 | } else { |
| 2696 | DCHECK(second.IsStackSlot()); |
| 2697 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2698 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2699 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2700 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2704 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2705 | if (second.IsFpuRegister()) { |
| 2706 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2707 | } else if (second.IsConstant()) { |
| 2708 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2709 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2710 | } else { |
| 2711 | DCHECK(second.IsDoubleStackSlot()); |
| 2712 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2713 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2714 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2715 | break; |
| 2716 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2717 | |
| 2718 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2719 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2720 | } |
| 2721 | } |
| 2722 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2723 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2724 | uint32_t stack_adjustment, bool is_float) { |
| 2725 | if (source.IsStackSlot()) { |
| 2726 | DCHECK(is_float); |
| 2727 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2728 | } else if (source.IsDoubleStackSlot()) { |
| 2729 | DCHECK(!is_float); |
| 2730 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2731 | } else { |
| 2732 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2733 | if (is_float) { |
| 2734 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2735 | codegen_->Move(stack_temp, source); |
| 2736 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2737 | } else { |
| 2738 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2739 | codegen_->Move(stack_temp, source); |
| 2740 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2741 | } |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2746 | Primitive::Type type = rem->GetResultType(); |
| 2747 | bool is_float = type == Primitive::kPrimFloat; |
| 2748 | size_t elem_size = Primitive::ComponentSize(type); |
| 2749 | LocationSummary* locations = rem->GetLocations(); |
| 2750 | Location first = locations->InAt(0); |
| 2751 | Location second = locations->InAt(1); |
| 2752 | Location out = locations->Out(); |
| 2753 | |
| 2754 | // Create stack space for 2 elements. |
| 2755 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2756 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2757 | |
| 2758 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2759 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2760 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2761 | |
| 2762 | // Loop doing FPREM until we stabilize. |
| 2763 | Label retry; |
| 2764 | __ Bind(&retry); |
| 2765 | __ fprem(); |
| 2766 | |
| 2767 | // Move FP status to AX. |
| 2768 | __ fstsw(); |
| 2769 | |
| 2770 | // And see if the argument reduction is complete. This is signaled by the |
| 2771 | // C2 FPU flag bit set to 0. |
| 2772 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2773 | __ j(kNotEqual, &retry); |
| 2774 | |
| 2775 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2776 | // Store FP top of stack to real stack. |
| 2777 | if (is_float) { |
| 2778 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2779 | } else { |
| 2780 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2781 | } |
| 2782 | |
| 2783 | // Pop the 2 items from the FP stack. |
| 2784 | __ fucompp(); |
| 2785 | |
| 2786 | // Load the value from the stack into an XMM register. |
| 2787 | DCHECK(out.IsFpuRegister()) << out; |
| 2788 | if (is_float) { |
| 2789 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2790 | } else { |
| 2791 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2792 | } |
| 2793 | |
| 2794 | // And remove the temporary stack space we allocated. |
| 2795 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2796 | } |
| 2797 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2798 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2799 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2800 | |
| 2801 | LocationSummary* locations = instruction->GetLocations(); |
| 2802 | Location second = locations->InAt(1); |
| 2803 | DCHECK(second.IsConstant()); |
| 2804 | |
| 2805 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2806 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2807 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2808 | |
| 2809 | DCHECK(imm == 1 || imm == -1); |
| 2810 | |
| 2811 | switch (instruction->GetResultType()) { |
| 2812 | case Primitive::kPrimInt: { |
| 2813 | if (instruction->IsRem()) { |
| 2814 | __ xorl(output_register, output_register); |
| 2815 | } else { |
| 2816 | __ movl(output_register, input_register); |
| 2817 | if (imm == -1) { |
| 2818 | __ negl(output_register); |
| 2819 | } |
| 2820 | } |
| 2821 | break; |
| 2822 | } |
| 2823 | |
| 2824 | case Primitive::kPrimLong: { |
| 2825 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2826 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2827 | } else { |
| 2828 | __ movq(output_register, input_register); |
| 2829 | if (imm == -1) { |
| 2830 | __ negq(output_register); |
| 2831 | } |
| 2832 | } |
| 2833 | break; |
| 2834 | } |
| 2835 | |
| 2836 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2837 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2838 | } |
| 2839 | } |
| 2840 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2841 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2842 | LocationSummary* locations = instruction->GetLocations(); |
| 2843 | Location second = locations->InAt(1); |
| 2844 | |
| 2845 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2846 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2847 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2848 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2849 | |
| 2850 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 2851 | |
| 2852 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2853 | |
| 2854 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2855 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 2856 | __ testl(numerator, numerator); |
| 2857 | __ cmov(kGreaterEqual, tmp, numerator); |
| 2858 | int shift = CTZ(imm); |
| 2859 | __ sarl(tmp, Immediate(shift)); |
| 2860 | |
| 2861 | if (imm < 0) { |
| 2862 | __ negl(tmp); |
| 2863 | } |
| 2864 | |
| 2865 | __ movl(output_register, tmp); |
| 2866 | } else { |
| 2867 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2868 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2869 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2870 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2871 | __ addq(rdx, numerator); |
| 2872 | __ testq(numerator, numerator); |
| 2873 | __ cmov(kGreaterEqual, rdx, numerator); |
| 2874 | int shift = CTZ(imm); |
| 2875 | __ sarq(rdx, Immediate(shift)); |
| 2876 | |
| 2877 | if (imm < 0) { |
| 2878 | __ negq(rdx); |
| 2879 | } |
| 2880 | |
| 2881 | __ movq(output_register, rdx); |
| 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2886 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2887 | |
| 2888 | LocationSummary* locations = instruction->GetLocations(); |
| 2889 | Location second = locations->InAt(1); |
| 2890 | |
| 2891 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 2892 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2893 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2894 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 2895 | : locations->Out().AsRegister<CpuRegister>(); |
| 2896 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 2897 | |
| 2898 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 2899 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 2900 | if (instruction->IsDiv()) { |
| 2901 | DCHECK_EQ(RAX, out.AsRegister()); |
| 2902 | } else { |
| 2903 | DCHECK_EQ(RDX, out.AsRegister()); |
| 2904 | } |
| 2905 | |
| 2906 | int64_t magic; |
| 2907 | int shift; |
| 2908 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2909 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2910 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2911 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2912 | |
| 2913 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2914 | |
| 2915 | __ movl(numerator, eax); |
| 2916 | |
| 2917 | Label no_div; |
| 2918 | Label end; |
| 2919 | __ testl(eax, eax); |
| 2920 | __ j(kNotEqual, &no_div); |
| 2921 | |
| 2922 | __ xorl(out, out); |
| 2923 | __ jmp(&end); |
| 2924 | |
| 2925 | __ Bind(&no_div); |
| 2926 | |
| 2927 | __ movl(eax, Immediate(magic)); |
| 2928 | __ imull(numerator); |
| 2929 | |
| 2930 | if (imm > 0 && magic < 0) { |
| 2931 | __ addl(edx, numerator); |
| 2932 | } else if (imm < 0 && magic > 0) { |
| 2933 | __ subl(edx, numerator); |
| 2934 | } |
| 2935 | |
| 2936 | if (shift != 0) { |
| 2937 | __ sarl(edx, Immediate(shift)); |
| 2938 | } |
| 2939 | |
| 2940 | __ movl(eax, edx); |
| 2941 | __ shrl(edx, Immediate(31)); |
| 2942 | __ addl(edx, eax); |
| 2943 | |
| 2944 | if (instruction->IsRem()) { |
| 2945 | __ movl(eax, numerator); |
| 2946 | __ imull(edx, Immediate(imm)); |
| 2947 | __ subl(eax, edx); |
| 2948 | __ movl(edx, eax); |
| 2949 | } else { |
| 2950 | __ movl(eax, edx); |
| 2951 | } |
| 2952 | __ Bind(&end); |
| 2953 | } else { |
| 2954 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2955 | |
| 2956 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2957 | |
| 2958 | CpuRegister rax = eax; |
| 2959 | CpuRegister rdx = edx; |
| 2960 | |
| 2961 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 2962 | |
| 2963 | // Save the numerator. |
| 2964 | __ movq(numerator, rax); |
| 2965 | |
| 2966 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2967 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2968 | |
| 2969 | // RDX:RAX = magic * numerator |
| 2970 | __ imulq(numerator); |
| 2971 | |
| 2972 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2973 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2974 | __ addq(rdx, numerator); |
| 2975 | } else if (imm < 0 && magic > 0) { |
| 2976 | // RDX -= numerator |
| 2977 | __ subq(rdx, numerator); |
| 2978 | } |
| 2979 | |
| 2980 | // Shift if needed. |
| 2981 | if (shift != 0) { |
| 2982 | __ sarq(rdx, Immediate(shift)); |
| 2983 | } |
| 2984 | |
| 2985 | // RDX += 1 if RDX < 0 |
| 2986 | __ movq(rax, rdx); |
| 2987 | __ shrq(rdx, Immediate(63)); |
| 2988 | __ addq(rdx, rax); |
| 2989 | |
| 2990 | if (instruction->IsRem()) { |
| 2991 | __ movq(rax, numerator); |
| 2992 | |
| 2993 | if (IsInt<32>(imm)) { |
| 2994 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 2995 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2996 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | __ subq(rax, rdx); |
| 3000 | __ movq(rdx, rax); |
| 3001 | } else { |
| 3002 | __ movq(rax, rdx); |
| 3003 | } |
| 3004 | } |
| 3005 | } |
| 3006 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3007 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3008 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3009 | Primitive::Type type = instruction->GetResultType(); |
| 3010 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3011 | |
| 3012 | bool is_div = instruction->IsDiv(); |
| 3013 | LocationSummary* locations = instruction->GetLocations(); |
| 3014 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3015 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3016 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3017 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3018 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3019 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3020 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3021 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3022 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3023 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3024 | if (imm == 0) { |
| 3025 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3026 | } else if (imm == 1 || imm == -1) { |
| 3027 | DivRemOneOrMinusOne(instruction); |
| 3028 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3029 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3030 | } else { |
| 3031 | DCHECK(imm <= -2 || imm >= 2); |
| 3032 | GenerateDivRemWithAnyConstant(instruction); |
| 3033 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3034 | } else { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3035 | SlowPathCodeX86_64* slow_path = |
| 3036 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3037 | out.AsRegister(), type, is_div); |
| 3038 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3039 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3040 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3041 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3042 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3043 | // so it's safe to just use negl instead of more complex comparisons. |
| 3044 | if (type == Primitive::kPrimInt) { |
| 3045 | __ cmpl(second_reg, Immediate(-1)); |
| 3046 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3047 | // edx:eax <- sign-extended of eax |
| 3048 | __ cdq(); |
| 3049 | // eax = quotient, edx = remainder |
| 3050 | __ idivl(second_reg); |
| 3051 | } else { |
| 3052 | __ cmpq(second_reg, Immediate(-1)); |
| 3053 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3054 | // rdx:rax <- sign-extended of rax |
| 3055 | __ cqo(); |
| 3056 | // rax = quotient, rdx = remainder |
| 3057 | __ idivq(second_reg); |
| 3058 | } |
| 3059 | __ Bind(slow_path->GetExitLabel()); |
| 3060 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3061 | } |
| 3062 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3063 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3064 | LocationSummary* locations = |
| 3065 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3066 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3067 | case Primitive::kPrimInt: |
| 3068 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3069 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3070 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3071 | locations->SetOut(Location::SameAsFirstInput()); |
| 3072 | // Intel uses edx:eax as the dividend. |
| 3073 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3074 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3075 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3076 | // output and request another temp. |
| 3077 | if (div->InputAt(1)->IsConstant()) { |
| 3078 | locations->AddTemp(Location::RequiresRegister()); |
| 3079 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3080 | break; |
| 3081 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3082 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3083 | case Primitive::kPrimFloat: |
| 3084 | case Primitive::kPrimDouble: { |
| 3085 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3086 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3087 | locations->SetOut(Location::SameAsFirstInput()); |
| 3088 | break; |
| 3089 | } |
| 3090 | |
| 3091 | default: |
| 3092 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3097 | LocationSummary* locations = div->GetLocations(); |
| 3098 | Location first = locations->InAt(0); |
| 3099 | Location second = locations->InAt(1); |
| 3100 | DCHECK(first.Equals(locations->Out())); |
| 3101 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3102 | Primitive::Type type = div->GetResultType(); |
| 3103 | switch (type) { |
| 3104 | case Primitive::kPrimInt: |
| 3105 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3106 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3107 | break; |
| 3108 | } |
| 3109 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3110 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3111 | if (second.IsFpuRegister()) { |
| 3112 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3113 | } else if (second.IsConstant()) { |
| 3114 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3115 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3116 | } else { |
| 3117 | DCHECK(second.IsStackSlot()); |
| 3118 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3119 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3120 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3121 | break; |
| 3122 | } |
| 3123 | |
| 3124 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3125 | if (second.IsFpuRegister()) { |
| 3126 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3127 | } else if (second.IsConstant()) { |
| 3128 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3129 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3130 | } else { |
| 3131 | DCHECK(second.IsDoubleStackSlot()); |
| 3132 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3133 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3134 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3135 | break; |
| 3136 | } |
| 3137 | |
| 3138 | default: |
| 3139 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3140 | } |
| 3141 | } |
| 3142 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3143 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3144 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3145 | LocationSummary* locations = |
| 3146 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3147 | |
| 3148 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3149 | case Primitive::kPrimInt: |
| 3150 | case Primitive::kPrimLong: { |
| 3151 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3152 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3153 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3154 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3155 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3156 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3157 | // output and request another temp. |
| 3158 | if (rem->InputAt(1)->IsConstant()) { |
| 3159 | locations->AddTemp(Location::RequiresRegister()); |
| 3160 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3161 | break; |
| 3162 | } |
| 3163 | |
| 3164 | case Primitive::kPrimFloat: |
| 3165 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3166 | locations->SetInAt(0, Location::Any()); |
| 3167 | locations->SetInAt(1, Location::Any()); |
| 3168 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3169 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3170 | break; |
| 3171 | } |
| 3172 | |
| 3173 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3174 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3179 | Primitive::Type type = rem->GetResultType(); |
| 3180 | switch (type) { |
| 3181 | case Primitive::kPrimInt: |
| 3182 | case Primitive::kPrimLong: { |
| 3183 | GenerateDivRemIntegral(rem); |
| 3184 | break; |
| 3185 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3186 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3187 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3188 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3189 | break; |
| 3190 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3191 | default: |
| 3192 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3193 | } |
| 3194 | } |
| 3195 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3196 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3197 | LocationSummary* locations = |
| 3198 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3199 | locations->SetInAt(0, Location::Any()); |
| 3200 | if (instruction->HasUses()) { |
| 3201 | locations->SetOut(Location::SameAsFirstInput()); |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3206 | SlowPathCodeX86_64* slow_path = |
| 3207 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3208 | codegen_->AddSlowPath(slow_path); |
| 3209 | |
| 3210 | LocationSummary* locations = instruction->GetLocations(); |
| 3211 | Location value = locations->InAt(0); |
| 3212 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3213 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3214 | case Primitive::kPrimByte: |
| 3215 | case Primitive::kPrimChar: |
| 3216 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3217 | case Primitive::kPrimInt: { |
| 3218 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3219 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3220 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3221 | } else if (value.IsStackSlot()) { |
| 3222 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3223 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3224 | } else { |
| 3225 | DCHECK(value.IsConstant()) << value; |
| 3226 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3227 | __ jmp(slow_path->GetEntryLabel()); |
| 3228 | } |
| 3229 | } |
| 3230 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3231 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3232 | case Primitive::kPrimLong: { |
| 3233 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3234 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3235 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3236 | } else if (value.IsDoubleStackSlot()) { |
| 3237 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3238 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3239 | } else { |
| 3240 | DCHECK(value.IsConstant()) << value; |
| 3241 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3242 | __ jmp(slow_path->GetEntryLabel()); |
| 3243 | } |
| 3244 | } |
| 3245 | break; |
| 3246 | } |
| 3247 | default: |
| 3248 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3249 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3252 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3253 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3254 | |
| 3255 | LocationSummary* locations = |
| 3256 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3257 | |
| 3258 | switch (op->GetResultType()) { |
| 3259 | case Primitive::kPrimInt: |
| 3260 | case Primitive::kPrimLong: { |
| 3261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3262 | // The shift count needs to be in CL. |
| 3263 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3264 | locations->SetOut(Location::SameAsFirstInput()); |
| 3265 | break; |
| 3266 | } |
| 3267 | default: |
| 3268 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3269 | } |
| 3270 | } |
| 3271 | |
| 3272 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3273 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3274 | |
| 3275 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3276 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3277 | Location second = locations->InAt(1); |
| 3278 | |
| 3279 | switch (op->GetResultType()) { |
| 3280 | case Primitive::kPrimInt: { |
| 3281 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3282 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3283 | if (op->IsShl()) { |
| 3284 | __ shll(first_reg, second_reg); |
| 3285 | } else if (op->IsShr()) { |
| 3286 | __ sarl(first_reg, second_reg); |
| 3287 | } else { |
| 3288 | __ shrl(first_reg, second_reg); |
| 3289 | } |
| 3290 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3291 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3292 | if (op->IsShl()) { |
| 3293 | __ shll(first_reg, imm); |
| 3294 | } else if (op->IsShr()) { |
| 3295 | __ sarl(first_reg, imm); |
| 3296 | } else { |
| 3297 | __ shrl(first_reg, imm); |
| 3298 | } |
| 3299 | } |
| 3300 | break; |
| 3301 | } |
| 3302 | case Primitive::kPrimLong: { |
| 3303 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3304 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3305 | if (op->IsShl()) { |
| 3306 | __ shlq(first_reg, second_reg); |
| 3307 | } else if (op->IsShr()) { |
| 3308 | __ sarq(first_reg, second_reg); |
| 3309 | } else { |
| 3310 | __ shrq(first_reg, second_reg); |
| 3311 | } |
| 3312 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3313 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3314 | if (op->IsShl()) { |
| 3315 | __ shlq(first_reg, imm); |
| 3316 | } else if (op->IsShr()) { |
| 3317 | __ sarq(first_reg, imm); |
| 3318 | } else { |
| 3319 | __ shrq(first_reg, imm); |
| 3320 | } |
| 3321 | } |
| 3322 | break; |
| 3323 | } |
| 3324 | default: |
| 3325 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3326 | } |
| 3327 | } |
| 3328 | |
| 3329 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3330 | HandleShift(shl); |
| 3331 | } |
| 3332 | |
| 3333 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3334 | HandleShift(shl); |
| 3335 | } |
| 3336 | |
| 3337 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3338 | HandleShift(shr); |
| 3339 | } |
| 3340 | |
| 3341 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3342 | HandleShift(shr); |
| 3343 | } |
| 3344 | |
| 3345 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3346 | HandleShift(ushr); |
| 3347 | } |
| 3348 | |
| 3349 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3350 | HandleShift(ushr); |
| 3351 | } |
| 3352 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3353 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3354 | LocationSummary* locations = |
| 3355 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3356 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3357 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3358 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3359 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3363 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3364 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3365 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3366 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3367 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3368 | |
| 3369 | codegen_->InvokeRuntime( |
| 3370 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true), |
| 3371 | instruction, |
| 3372 | instruction->GetDexPc(), |
| 3373 | nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3374 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3375 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3376 | } |
| 3377 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3378 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3379 | LocationSummary* locations = |
| 3380 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3381 | InvokeRuntimeCallingConvention calling_convention; |
| 3382 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3383 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3384 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3385 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3389 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3390 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3391 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3392 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3393 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3394 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3395 | codegen_->InvokeRuntime( |
| 3396 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true), |
| 3397 | instruction, |
| 3398 | instruction->GetDexPc(), |
| 3399 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3400 | |
| 3401 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3402 | } |
| 3403 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3404 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3405 | LocationSummary* locations = |
| 3406 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3407 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3408 | if (location.IsStackSlot()) { |
| 3409 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3410 | } else if (location.IsDoubleStackSlot()) { |
| 3411 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3412 | } |
| 3413 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3414 | } |
| 3415 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3416 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3417 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3418 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3422 | LocationSummary* locations = |
| 3423 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3424 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3425 | } |
| 3426 | |
| 3427 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3428 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3429 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3430 | } |
| 3431 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3432 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3433 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3434 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3435 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3436 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3437 | } |
| 3438 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3439 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3440 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3441 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3442 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3443 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3444 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3445 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3446 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3447 | break; |
| 3448 | |
| 3449 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3450 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3451 | break; |
| 3452 | |
| 3453 | default: |
| 3454 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3455 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3456 | } |
| 3457 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3458 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3459 | LocationSummary* locations = |
| 3460 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3461 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3462 | locations->SetOut(Location::SameAsFirstInput()); |
| 3463 | } |
| 3464 | |
| 3465 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3466 | LocationSummary* locations = bool_not->GetLocations(); |
| 3467 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3468 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3469 | Location out = locations->Out(); |
| 3470 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3471 | } |
| 3472 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3473 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3474 | LocationSummary* locations = |
| 3475 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3476 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3477 | locations->SetInAt(i, Location::Any()); |
| 3478 | } |
| 3479 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3483 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3484 | LOG(FATAL) << "Unimplemented"; |
| 3485 | } |
| 3486 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3487 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3488 | /* |
| 3489 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3490 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3491 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3492 | */ |
| 3493 | switch (kind) { |
| 3494 | case MemBarrierKind::kAnyAny: { |
| 3495 | __ mfence(); |
| 3496 | break; |
| 3497 | } |
| 3498 | case MemBarrierKind::kAnyStore: |
| 3499 | case MemBarrierKind::kLoadAny: |
| 3500 | case MemBarrierKind::kStoreStore: { |
| 3501 | // nop |
| 3502 | break; |
| 3503 | } |
| 3504 | default: |
| 3505 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3506 | } |
| 3507 | } |
| 3508 | |
| 3509 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3510 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3511 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3512 | LocationSummary* locations = |
| 3513 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3514 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3515 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3516 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3517 | } else { |
| 3518 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3519 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3523 | const FieldInfo& field_info) { |
| 3524 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3525 | |
| 3526 | LocationSummary* locations = instruction->GetLocations(); |
| 3527 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3528 | Location out = locations->Out(); |
| 3529 | bool is_volatile = field_info.IsVolatile(); |
| 3530 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3531 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3532 | |
| 3533 | switch (field_type) { |
| 3534 | case Primitive::kPrimBoolean: { |
| 3535 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3536 | break; |
| 3537 | } |
| 3538 | |
| 3539 | case Primitive::kPrimByte: { |
| 3540 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3541 | break; |
| 3542 | } |
| 3543 | |
| 3544 | case Primitive::kPrimShort: { |
| 3545 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3546 | break; |
| 3547 | } |
| 3548 | |
| 3549 | case Primitive::kPrimChar: { |
| 3550 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3551 | break; |
| 3552 | } |
| 3553 | |
| 3554 | case Primitive::kPrimInt: |
| 3555 | case Primitive::kPrimNot: { |
| 3556 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3557 | break; |
| 3558 | } |
| 3559 | |
| 3560 | case Primitive::kPrimLong: { |
| 3561 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3562 | break; |
| 3563 | } |
| 3564 | |
| 3565 | case Primitive::kPrimFloat: { |
| 3566 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3567 | break; |
| 3568 | } |
| 3569 | |
| 3570 | case Primitive::kPrimDouble: { |
| 3571 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3572 | break; |
| 3573 | } |
| 3574 | |
| 3575 | case Primitive::kPrimVoid: |
| 3576 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3577 | UNREACHABLE(); |
| 3578 | } |
| 3579 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3580 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3581 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3582 | if (is_volatile) { |
| 3583 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3584 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3585 | |
| 3586 | if (field_type == Primitive::kPrimNot) { |
| 3587 | __ MaybeUnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 3588 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 3592 | const FieldInfo& field_info) { |
| 3593 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3594 | |
| 3595 | LocationSummary* locations = |
| 3596 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3597 | Primitive::Type field_type = field_info.GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3598 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3599 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3600 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3601 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3602 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 3603 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3604 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3605 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3606 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3607 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3608 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3609 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3610 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3611 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3612 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3613 | locations->AddTemp(Location::RequiresRegister()); |
| 3614 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3615 | } |
| 3616 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3617 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3618 | const FieldInfo& field_info, |
| 3619 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3620 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3621 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3622 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3623 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3624 | Location value = locations->InAt(1); |
| 3625 | bool is_volatile = field_info.IsVolatile(); |
| 3626 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3627 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3628 | |
| 3629 | if (is_volatile) { |
| 3630 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3631 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3632 | |
| 3633 | switch (field_type) { |
| 3634 | case Primitive::kPrimBoolean: |
| 3635 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3636 | if (value.IsConstant()) { |
| 3637 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3638 | __ movb(Address(base, offset), Immediate(v)); |
| 3639 | } else { |
| 3640 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3641 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3642 | break; |
| 3643 | } |
| 3644 | |
| 3645 | case Primitive::kPrimShort: |
| 3646 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3647 | if (value.IsConstant()) { |
| 3648 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3649 | __ movw(Address(base, offset), Immediate(v)); |
| 3650 | } else { |
| 3651 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3652 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3653 | break; |
| 3654 | } |
| 3655 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3656 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3657 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3658 | if (value.IsConstant()) { |
| 3659 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3660 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 3661 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 3662 | // Note: if heap poisoning is enabled, no need to poison |
| 3663 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 3664 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3665 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3666 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3667 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3668 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3669 | __ PoisonHeapReference(temp); |
| 3670 | __ movl(Address(base, offset), temp); |
| 3671 | } else { |
| 3672 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3673 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3674 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3675 | break; |
| 3676 | } |
| 3677 | |
| 3678 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3679 | if (value.IsConstant()) { |
| 3680 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3681 | DCHECK(IsInt<32>(v)); |
| 3682 | int32_t v_32 = v; |
| 3683 | __ movq(Address(base, offset), Immediate(v_32)); |
| 3684 | } else { |
| 3685 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3686 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3687 | break; |
| 3688 | } |
| 3689 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3690 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3691 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3692 | break; |
| 3693 | } |
| 3694 | |
| 3695 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3696 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3697 | break; |
| 3698 | } |
| 3699 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3700 | case Primitive::kPrimVoid: |
| 3701 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3702 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3703 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3704 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3705 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3706 | |
| 3707 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3708 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3709 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3710 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3711 | } |
| 3712 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3713 | if (is_volatile) { |
| 3714 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3715 | } |
| 3716 | } |
| 3717 | |
| 3718 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3719 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3720 | } |
| 3721 | |
| 3722 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3723 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3727 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3731 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3732 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3733 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3734 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3735 | HandleFieldGet(instruction); |
| 3736 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3737 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3738 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3739 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3740 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3741 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3742 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3743 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3744 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3745 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3746 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3747 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3751 | LocationSummary* locations = |
| 3752 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3753 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3754 | ? Location::RequiresRegister() |
| 3755 | : Location::Any(); |
| 3756 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3757 | if (instruction->HasUses()) { |
| 3758 | locations->SetOut(Location::SameAsFirstInput()); |
| 3759 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3760 | } |
| 3761 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3762 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3763 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3764 | return; |
| 3765 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3766 | LocationSummary* locations = instruction->GetLocations(); |
| 3767 | Location obj = locations->InAt(0); |
| 3768 | |
| 3769 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 3770 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3771 | } |
| 3772 | |
| 3773 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3774 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3775 | codegen_->AddSlowPath(slow_path); |
| 3776 | |
| 3777 | LocationSummary* locations = instruction->GetLocations(); |
| 3778 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3779 | |
| 3780 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3781 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3782 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3783 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3784 | } else { |
| 3785 | DCHECK(obj.IsConstant()) << obj; |
| 3786 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 3787 | __ jmp(slow_path->GetEntryLabel()); |
| 3788 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3789 | } |
| 3790 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3791 | } |
| 3792 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3793 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| 3794 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3795 | GenerateImplicitNullCheck(instruction); |
| 3796 | } else { |
| 3797 | GenerateExplicitNullCheck(instruction); |
| 3798 | } |
| 3799 | } |
| 3800 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3801 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3802 | LocationSummary* locations = |
| 3803 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3804 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3805 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3806 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3807 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3808 | } else { |
| 3809 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3810 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 3814 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3815 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3816 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3817 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3818 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3819 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3820 | case Primitive::kPrimBoolean: { |
| 3821 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3822 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3823 | if (index.IsConstant()) { |
| 3824 | __ movzxb(out, Address(obj, |
| 3825 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3826 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3827 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3828 | } |
| 3829 | break; |
| 3830 | } |
| 3831 | |
| 3832 | case Primitive::kPrimByte: { |
| 3833 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3834 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3835 | if (index.IsConstant()) { |
| 3836 | __ movsxb(out, Address(obj, |
| 3837 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3838 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3839 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3840 | } |
| 3841 | break; |
| 3842 | } |
| 3843 | |
| 3844 | case Primitive::kPrimShort: { |
| 3845 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3846 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3847 | if (index.IsConstant()) { |
| 3848 | __ movsxw(out, Address(obj, |
| 3849 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3850 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3851 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3852 | } |
| 3853 | break; |
| 3854 | } |
| 3855 | |
| 3856 | case Primitive::kPrimChar: { |
| 3857 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3858 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3859 | if (index.IsConstant()) { |
| 3860 | __ movzxw(out, Address(obj, |
| 3861 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3862 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3863 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3864 | } |
| 3865 | break; |
| 3866 | } |
| 3867 | |
| 3868 | case Primitive::kPrimInt: |
| 3869 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 3870 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 3871 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3872 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3873 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3874 | if (index.IsConstant()) { |
| 3875 | __ movl(out, Address(obj, |
| 3876 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3877 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3878 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3879 | } |
| 3880 | break; |
| 3881 | } |
| 3882 | |
| 3883 | case Primitive::kPrimLong: { |
| 3884 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3885 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3886 | if (index.IsConstant()) { |
| 3887 | __ movq(out, Address(obj, |
| 3888 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3889 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3890 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3891 | } |
| 3892 | break; |
| 3893 | } |
| 3894 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3895 | case Primitive::kPrimFloat: { |
| 3896 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3897 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3898 | if (index.IsConstant()) { |
| 3899 | __ movss(out, Address(obj, |
| 3900 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3901 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3902 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3903 | } |
| 3904 | break; |
| 3905 | } |
| 3906 | |
| 3907 | case Primitive::kPrimDouble: { |
| 3908 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3909 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3910 | if (index.IsConstant()) { |
| 3911 | __ movsd(out, Address(obj, |
| 3912 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3913 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3914 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3915 | } |
| 3916 | break; |
| 3917 | } |
| 3918 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3919 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3920 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3921 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3922 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3923 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3924 | |
| 3925 | if (type == Primitive::kPrimNot) { |
| 3926 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3927 | __ MaybeUnpoisonHeapReference(out); |
| 3928 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3932 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3933 | |
| 3934 | bool needs_write_barrier = |
| 3935 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3936 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 3937 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3938 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3939 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3940 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3941 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3942 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3943 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3944 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3945 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3946 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3947 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3948 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3949 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3950 | if (value_type == Primitive::kPrimLong) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3951 | locations->SetInAt(2, Location::RegisterOrInt32LongConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3952 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 3953 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3954 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3955 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3956 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3957 | |
| 3958 | if (needs_write_barrier) { |
| 3959 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3960 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3961 | locations->AddTemp(Location::RequiresRegister()); |
| 3962 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3963 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 3967 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3968 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3969 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3970 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3971 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3972 | bool needs_runtime_call = locations->WillCall(); |
| 3973 | bool needs_write_barrier = |
| 3974 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3975 | |
| 3976 | switch (value_type) { |
| 3977 | case Primitive::kPrimBoolean: |
| 3978 | case Primitive::kPrimByte: { |
| 3979 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3980 | if (index.IsConstant()) { |
| 3981 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3982 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3983 | __ movb(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3984 | } else { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3985 | __ movb(Address(obj, offset), |
| 3986 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3987 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3988 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3989 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3990 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
| 3991 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3992 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3993 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3994 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3995 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3996 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3997 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3998 | break; |
| 3999 | } |
| 4000 | |
| 4001 | case Primitive::kPrimShort: |
| 4002 | case Primitive::kPrimChar: { |
| 4003 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4004 | if (index.IsConstant()) { |
| 4005 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4006 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4007 | __ movw(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4008 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4009 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4010 | __ movw(Address(obj, offset), |
| 4011 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4012 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4013 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4014 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4015 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4016 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
| 4017 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4018 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4019 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4020 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4021 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4022 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4023 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4024 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4025 | break; |
| 4026 | } |
| 4027 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4028 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4029 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4030 | if (!needs_runtime_call) { |
| 4031 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4032 | if (index.IsConstant()) { |
| 4033 | size_t offset = |
| 4034 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4035 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4036 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4037 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4038 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4039 | __ PoisonHeapReference(temp); |
| 4040 | __ movl(Address(obj, offset), temp); |
| 4041 | } else { |
| 4042 | __ movl(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 4043 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4044 | } else { |
| 4045 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4046 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4047 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4048 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4049 | // Note: if heap poisoning is enabled, no need to poison |
| 4050 | // (negate) `v` if it is a reference, as it would be null. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4051 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4052 | } |
| 4053 | } else { |
| 4054 | DCHECK(index.IsRegister()) << index; |
| 4055 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4056 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4057 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4058 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4059 | __ PoisonHeapReference(temp); |
| 4060 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), temp); |
| 4061 | } else { |
| 4062 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 4063 | value.AsRegister<CpuRegister>()); |
| 4064 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4065 | } else { |
| 4066 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4067 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4068 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4069 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4070 | // Note: if heap poisoning is enabled, no need to poison |
| 4071 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4072 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4073 | Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4074 | } |
| 4075 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4076 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4077 | if (needs_write_barrier) { |
| 4078 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4079 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4080 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4081 | codegen_->MarkGCCard( |
| 4082 | temp, card, obj, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4083 | } |
| 4084 | } else { |
| 4085 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4086 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4087 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4088 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4089 | instruction, |
| 4090 | instruction->GetDexPc(), |
| 4091 | nullptr); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4092 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4093 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4094 | break; |
| 4095 | } |
| 4096 | |
| 4097 | case Primitive::kPrimLong: { |
| 4098 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4099 | if (index.IsConstant()) { |
| 4100 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4101 | if (value.IsRegister()) { |
| 4102 | __ movq(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 4103 | } else { |
| 4104 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4105 | DCHECK(IsInt<32>(v)); |
| 4106 | int32_t v_32 = v; |
| 4107 | __ movq(Address(obj, offset), Immediate(v_32)); |
| 4108 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4109 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4110 | if (value.IsRegister()) { |
| 4111 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4112 | value.AsRegister<CpuRegister>()); |
| 4113 | } else { |
| 4114 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4115 | DCHECK(IsInt<32>(v)); |
| 4116 | int32_t v_32 = v; |
| 4117 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4118 | Immediate(v_32)); |
| 4119 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4120 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4121 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4122 | break; |
| 4123 | } |
| 4124 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4125 | case Primitive::kPrimFloat: { |
| 4126 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4127 | if (index.IsConstant()) { |
| 4128 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4129 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4130 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4131 | } else { |
| 4132 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4133 | __ movss(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 4134 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4135 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4136 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4137 | break; |
| 4138 | } |
| 4139 | |
| 4140 | case Primitive::kPrimDouble: { |
| 4141 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4142 | if (index.IsConstant()) { |
| 4143 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4144 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4145 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4146 | } else { |
| 4147 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4148 | __ movsd(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4149 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4150 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4151 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4152 | break; |
| 4153 | } |
| 4154 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4155 | case Primitive::kPrimVoid: |
| 4156 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4157 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4162 | LocationSummary* locations = |
| 4163 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4164 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4165 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4169 | LocationSummary* locations = instruction->GetLocations(); |
| 4170 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4171 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4172 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4173 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4174 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4178 | LocationSummary* locations = |
| 4179 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4180 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4181 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4182 | if (instruction->HasUses()) { |
| 4183 | locations->SetOut(Location::SameAsFirstInput()); |
| 4184 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4188 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4189 | Location index_loc = locations->InAt(0); |
| 4190 | Location length_loc = locations->InAt(1); |
| 4191 | SlowPathCodeX86_64* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4192 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4193 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4194 | if (length_loc.IsConstant()) { |
| 4195 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4196 | if (index_loc.IsConstant()) { |
| 4197 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4198 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4199 | if (index < 0 || index >= length) { |
| 4200 | codegen_->AddSlowPath(slow_path); |
| 4201 | __ jmp(slow_path->GetEntryLabel()); |
| 4202 | } else { |
| 4203 | // Some optimization after BCE may have generated this, and we should not |
| 4204 | // generate a bounds check if it is a valid range. |
| 4205 | } |
| 4206 | return; |
| 4207 | } |
| 4208 | |
| 4209 | // We have to reverse the jump condition because the length is the constant. |
| 4210 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4211 | __ cmpl(index_reg, Immediate(length)); |
| 4212 | codegen_->AddSlowPath(slow_path); |
| 4213 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4214 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4215 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4216 | if (index_loc.IsConstant()) { |
| 4217 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4218 | __ cmpl(length, Immediate(value)); |
| 4219 | } else { |
| 4220 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4221 | } |
| 4222 | codegen_->AddSlowPath(slow_path); |
| 4223 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4224 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4225 | } |
| 4226 | |
| 4227 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4228 | CpuRegister card, |
| 4229 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4230 | CpuRegister value, |
| 4231 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4232 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4233 | if (value_can_be_null) { |
| 4234 | __ testl(value, value); |
| 4235 | __ j(kEqual, &is_null); |
| 4236 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4237 | __ gs()->movq(card, Address::Absolute( |
| 4238 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4239 | __ movq(temp, object); |
| 4240 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4241 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4242 | if (value_can_be_null) { |
| 4243 | __ Bind(&is_null); |
| 4244 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4245 | } |
| 4246 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4247 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4248 | temp->SetLocations(nullptr); |
| 4249 | } |
| 4250 | |
| 4251 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 4252 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4253 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4254 | } |
| 4255 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4256 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4257 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4258 | LOG(FATAL) << "Unimplemented"; |
| 4259 | } |
| 4260 | |
| 4261 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4262 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4263 | } |
| 4264 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4265 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4266 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4267 | } |
| 4268 | |
| 4269 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4270 | HBasicBlock* block = instruction->GetBlock(); |
| 4271 | if (block->GetLoopInformation() != nullptr) { |
| 4272 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4273 | // The back edge will generate the suspend check. |
| 4274 | return; |
| 4275 | } |
| 4276 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4277 | // The goto will generate the suspend check. |
| 4278 | return; |
| 4279 | } |
| 4280 | GenerateSuspendCheck(instruction, nullptr); |
| 4281 | } |
| 4282 | |
| 4283 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4284 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4285 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4286 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4287 | if (slow_path == nullptr) { |
| 4288 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4289 | instruction->SetSlowPath(slow_path); |
| 4290 | codegen_->AddSlowPath(slow_path); |
| 4291 | if (successor != nullptr) { |
| 4292 | DCHECK(successor->IsLoopHeader()); |
| 4293 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4294 | } |
| 4295 | } else { |
| 4296 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4297 | } |
| 4298 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4299 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4300 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4301 | if (successor == nullptr) { |
| 4302 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4303 | __ Bind(slow_path->GetReturnLabel()); |
| 4304 | } else { |
| 4305 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4306 | __ jmp(slow_path->GetEntryLabel()); |
| 4307 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4308 | } |
| 4309 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4310 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4311 | return codegen_->GetAssembler(); |
| 4312 | } |
| 4313 | |
| 4314 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 4315 | MoveOperands* move = moves_.Get(index); |
| 4316 | Location source = move->GetSource(); |
| 4317 | Location destination = move->GetDestination(); |
| 4318 | |
| 4319 | if (source.IsRegister()) { |
| 4320 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4321 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4322 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4323 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4324 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4325 | } else { |
| 4326 | DCHECK(destination.IsDoubleStackSlot()); |
| 4327 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4328 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4329 | } |
| 4330 | } else if (source.IsStackSlot()) { |
| 4331 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4332 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4333 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4334 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4335 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4336 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4337 | } else { |
| 4338 | DCHECK(destination.IsStackSlot()); |
| 4339 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4340 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4341 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4342 | } else if (source.IsDoubleStackSlot()) { |
| 4343 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4344 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4345 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4346 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4347 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4348 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4349 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4350 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4351 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4352 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4353 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4354 | } else if (source.IsConstant()) { |
| 4355 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4356 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4357 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4358 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4359 | if (value == 0) { |
| 4360 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4361 | } else { |
| 4362 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4363 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4364 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4365 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4366 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4367 | } |
| 4368 | } else if (constant->IsLongConstant()) { |
| 4369 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4370 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4371 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4372 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4373 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4374 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4375 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4376 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4377 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4378 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4379 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4380 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4381 | if (value == 0) { |
| 4382 | // easy FP 0.0. |
| 4383 | __ xorps(dest, dest); |
| 4384 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4385 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4386 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4387 | } else { |
| 4388 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4389 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4390 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4391 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4392 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4393 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4394 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4395 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4396 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4397 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4398 | if (value == 0) { |
| 4399 | __ xorpd(dest, dest); |
| 4400 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4401 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4402 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4403 | } else { |
| 4404 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4405 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4406 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4407 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4408 | } else if (source.IsFpuRegister()) { |
| 4409 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4410 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4411 | } else if (destination.IsStackSlot()) { |
| 4412 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4413 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4414 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 4415 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4416 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4417 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4418 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4419 | } |
| 4420 | } |
| 4421 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4422 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4423 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4424 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 4425 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4428 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4429 | ScratchRegisterScope ensure_scratch( |
| 4430 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 4431 | |
| 4432 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4433 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4434 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 4435 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4436 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4437 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4438 | CpuRegister(ensure_scratch.GetRegister())); |
| 4439 | } |
| 4440 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4441 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 4442 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4443 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 4444 | __ movq(reg, CpuRegister(TMP)); |
| 4445 | } |
| 4446 | |
| 4447 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 4448 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4449 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4450 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4451 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4452 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4453 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 4454 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4455 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4456 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4457 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4458 | } |
| 4459 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4460 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 4461 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4462 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 4463 | __ movd(reg, CpuRegister(TMP)); |
| 4464 | } |
| 4465 | |
| 4466 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 4467 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4468 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 4469 | __ movd(reg, CpuRegister(TMP)); |
| 4470 | } |
| 4471 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4472 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 4473 | MoveOperands* move = moves_.Get(index); |
| 4474 | Location source = move->GetSource(); |
| 4475 | Location destination = move->GetDestination(); |
| 4476 | |
| 4477 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4478 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4479 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4480 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4481 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4482 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4483 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4484 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4485 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4486 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4487 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4488 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4489 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 4490 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4491 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4492 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 4493 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4494 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4495 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4496 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4497 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4498 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4499 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4500 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4501 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4502 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4503 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4504 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | |
| 4509 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 4510 | __ pushq(CpuRegister(reg)); |
| 4511 | } |
| 4512 | |
| 4513 | |
| 4514 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 4515 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4516 | } |
| 4517 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4518 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| 4519 | SlowPathCodeX86_64* slow_path, CpuRegister class_reg) { |
| 4520 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4521 | Immediate(mirror::Class::kStatusInitialized)); |
| 4522 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4523 | __ Bind(slow_path->GetExitLabel()); |
| 4524 | // No need for memory fence, thanks to the X86_64 memory model. |
| 4525 | } |
| 4526 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4527 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4528 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4529 | ? LocationSummary::kCallOnSlowPath |
| 4530 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4531 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4532 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4533 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4534 | locations->SetOut(Location::RequiresRegister()); |
| 4535 | } |
| 4536 | |
| 4537 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4538 | LocationSummary* locations = cls->GetLocations(); |
| 4539 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4540 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4541 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4542 | DCHECK(!cls->CanCallRuntime()); |
| 4543 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4544 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4545 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4546 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4547 | __ movq(out, Address( |
| 4548 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4549 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4550 | // TODO: We will need a read barrier here. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4551 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4552 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4553 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4554 | codegen_->AddSlowPath(slow_path); |
| 4555 | __ testl(out, out); |
| 4556 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4557 | if (cls->MustGenerateClinitCheck()) { |
| 4558 | GenerateClassInitializationCheck(slow_path, out); |
| 4559 | } else { |
| 4560 | __ Bind(slow_path->GetExitLabel()); |
| 4561 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 4566 | LocationSummary* locations = |
| 4567 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4568 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4569 | if (check->HasUses()) { |
| 4570 | locations->SetOut(Location::SameAsFirstInput()); |
| 4571 | } |
| 4572 | } |
| 4573 | |
| 4574 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4575 | // We assume the class to not be null. |
| 4576 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4577 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4578 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4579 | GenerateClassInitializationCheck(slow_path, |
| 4580 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4581 | } |
| 4582 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4583 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 4584 | LocationSummary* locations = |
| 4585 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4586 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4587 | locations->SetOut(Location::RequiresRegister()); |
| 4588 | } |
| 4589 | |
| 4590 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
| 4591 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 4592 | codegen_->AddSlowPath(slow_path); |
| 4593 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4594 | LocationSummary* locations = load->GetLocations(); |
| 4595 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4596 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4597 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4598 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4599 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4600 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4601 | __ testl(out, out); |
| 4602 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4603 | __ Bind(slow_path->GetExitLabel()); |
| 4604 | } |
| 4605 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4606 | static Address GetExceptionTlsAddress() { |
| 4607 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 4608 | } |
| 4609 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4610 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 4611 | LocationSummary* locations = |
| 4612 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4613 | locations->SetOut(Location::RequiresRegister()); |
| 4614 | } |
| 4615 | |
| 4616 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4617 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 4618 | } |
| 4619 | |
| 4620 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 4621 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4622 | } |
| 4623 | |
| 4624 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4625 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 4629 | LocationSummary* locations = |
| 4630 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4631 | InvokeRuntimeCallingConvention calling_convention; |
| 4632 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4633 | } |
| 4634 | |
| 4635 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4636 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4637 | instruction, |
| 4638 | instruction->GetDexPc(), |
| 4639 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4642 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4643 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4644 | ? LocationSummary::kNoCall |
| 4645 | : LocationSummary::kCallOnSlowPath; |
| 4646 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4647 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4648 | locations->SetInAt(1, Location::Any()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4649 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4650 | locations->SetOut(Location::RequiresRegister()); |
| 4651 | } |
| 4652 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4653 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4654 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4655 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4656 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4657 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4658 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4659 | Label done, zero; |
| 4660 | SlowPathCodeX86_64* slow_path = nullptr; |
| 4661 | |
| 4662 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4663 | // Avoid null check if we know obj is not null. |
| 4664 | if (instruction->MustDoNullCheck()) { |
| 4665 | __ testl(obj, obj); |
| 4666 | __ j(kEqual, &zero); |
| 4667 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4668 | // Compare the class of `obj` with `cls`. |
| 4669 | __ movl(out, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4670 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4671 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4672 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4673 | } else { |
| 4674 | DCHECK(cls.IsStackSlot()) << cls; |
| 4675 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4676 | } |
| 4677 | if (instruction->IsClassFinal()) { |
| 4678 | // Classes must be equal for the instanceof to succeed. |
| 4679 | __ j(kNotEqual, &zero); |
| 4680 | __ movl(out, Immediate(1)); |
| 4681 | __ jmp(&done); |
| 4682 | } else { |
| 4683 | // If the classes are not equal, we go into a slow path. |
| 4684 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4685 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4686 | codegen_->AddSlowPath(slow_path); |
| 4687 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4688 | __ movl(out, Immediate(1)); |
| 4689 | __ jmp(&done); |
| 4690 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4691 | |
| 4692 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4693 | __ Bind(&zero); |
| 4694 | __ movl(out, Immediate(0)); |
| 4695 | } |
| 4696 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4697 | if (slow_path != nullptr) { |
| 4698 | __ Bind(slow_path->GetExitLabel()); |
| 4699 | } |
| 4700 | __ Bind(&done); |
| 4701 | } |
| 4702 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4703 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4704 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4705 | instruction, LocationSummary::kCallOnSlowPath); |
| 4706 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4707 | locations->SetInAt(1, Location::Any()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4708 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4709 | locations->AddTemp(Location::RequiresRegister()); |
| 4710 | } |
| 4711 | |
| 4712 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4713 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4714 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4715 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4716 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4717 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4718 | SlowPathCodeX86_64* slow_path = |
| 4719 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4720 | codegen_->AddSlowPath(slow_path); |
| 4721 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4722 | // Avoid null check if we know obj is not null. |
| 4723 | if (instruction->MustDoNullCheck()) { |
| 4724 | __ testl(obj, obj); |
| 4725 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4726 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4727 | // Compare the class of `obj` with `cls`. |
| 4728 | __ movl(temp, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4729 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4730 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4731 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4732 | } else { |
| 4733 | DCHECK(cls.IsStackSlot()) << cls; |
| 4734 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4735 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4736 | // The checkcast succeeds if the classes are equal (fast path). |
| 4737 | // 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] | 4738 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4739 | __ Bind(slow_path->GetExitLabel()); |
| 4740 | } |
| 4741 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4742 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4743 | LocationSummary* locations = |
| 4744 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4745 | InvokeRuntimeCallingConvention calling_convention; |
| 4746 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4747 | } |
| 4748 | |
| 4749 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4750 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 4751 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 4752 | instruction, |
| 4753 | instruction->GetDexPc(), |
| 4754 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4755 | } |
| 4756 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4757 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4758 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4759 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4760 | |
| 4761 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4762 | LocationSummary* locations = |
| 4763 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4764 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4765 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4766 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4767 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4768 | locations->SetOut(Location::SameAsFirstInput()); |
| 4769 | } |
| 4770 | |
| 4771 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 4772 | HandleBitwiseOperation(instruction); |
| 4773 | } |
| 4774 | |
| 4775 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 4776 | HandleBitwiseOperation(instruction); |
| 4777 | } |
| 4778 | |
| 4779 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 4780 | HandleBitwiseOperation(instruction); |
| 4781 | } |
| 4782 | |
| 4783 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4784 | LocationSummary* locations = instruction->GetLocations(); |
| 4785 | Location first = locations->InAt(0); |
| 4786 | Location second = locations->InAt(1); |
| 4787 | DCHECK(first.Equals(locations->Out())); |
| 4788 | |
| 4789 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 4790 | if (second.IsRegister()) { |
| 4791 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4792 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4793 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4794 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4795 | } else { |
| 4796 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4797 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4798 | } |
| 4799 | } else if (second.IsConstant()) { |
| 4800 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 4801 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4802 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4803 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4804 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4805 | } else { |
| 4806 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4807 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4808 | } |
| 4809 | } else { |
| 4810 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 4811 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4812 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4813 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4814 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4815 | } else { |
| 4816 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4817 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4818 | } |
| 4819 | } |
| 4820 | } else { |
| 4821 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4822 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 4823 | bool second_is_constant = false; |
| 4824 | int64_t value = 0; |
| 4825 | if (second.IsConstant()) { |
| 4826 | second_is_constant = true; |
| 4827 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4828 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4829 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4830 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4831 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4832 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4833 | if (is_int32_value) { |
| 4834 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4835 | } else { |
| 4836 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4837 | } |
| 4838 | } else if (second.IsDoubleStackSlot()) { |
| 4839 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4840 | } else { |
| 4841 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 4842 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4843 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4844 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4845 | if (is_int32_value) { |
| 4846 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4847 | } else { |
| 4848 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4849 | } |
| 4850 | } else if (second.IsDoubleStackSlot()) { |
| 4851 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4852 | } else { |
| 4853 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 4854 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4855 | } else { |
| 4856 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4857 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4858 | if (is_int32_value) { |
| 4859 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4860 | } else { |
| 4861 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4862 | } |
| 4863 | } else if (second.IsDoubleStackSlot()) { |
| 4864 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4865 | } else { |
| 4866 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 4867 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4868 | } |
| 4869 | } |
| 4870 | } |
| 4871 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4872 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction) { |
| 4873 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4874 | UNUSED(instruction); |
| 4875 | LOG(FATAL) << "Unreachable"; |
| 4876 | } |
| 4877 | |
| 4878 | void InstructionCodeGeneratorX86_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 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4884 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 4885 | DCHECK(codegen_->IsBaseline()); |
| 4886 | LocationSummary* locations = |
| 4887 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4888 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 4889 | } |
| 4890 | |
| 4891 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 4892 | DCHECK(codegen_->IsBaseline()); |
| 4893 | // Will be generated at use site. |
| 4894 | } |
| 4895 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4896 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 4897 | if (value == 0) { |
| 4898 | __ xorl(dest, dest); |
| 4899 | } else if (value > 0 && IsInt<32>(value)) { |
| 4900 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 4901 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 4902 | } else { |
| 4903 | __ movq(dest, Immediate(value)); |
| 4904 | } |
| 4905 | } |
| 4906 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4907 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 4908 | DCHECK(dest.IsDoubleStackSlot()); |
| 4909 | if (IsInt<32>(value)) { |
| 4910 | // Can move directly as an int32 constant. |
| 4911 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 4912 | Immediate(static_cast<int32_t>(value))); |
| 4913 | } else { |
| 4914 | Load64BitValue(CpuRegister(TMP), value); |
| 4915 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 4916 | } |
| 4917 | } |
| 4918 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4919 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 4920 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4921 | X86_64Assembler* assembler = GetAssembler(); |
| 4922 | if (!assembler->IsConstantAreaEmpty()) { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4923 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 4924 | // byte values. If used for vectors at a later time, this will need to be |
| 4925 | // updated to 16 bytes with the appropriate offset. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4926 | assembler->Align(4, 0); |
| 4927 | constant_area_start_ = assembler->CodeSize(); |
| 4928 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | // And finish up. |
| 4932 | CodeGenerator::Finalize(allocator); |
| 4933 | } |
| 4934 | |
| 4935 | /** |
| 4936 | * Class to handle late fixup of offsets into constant area. |
| 4937 | */ |
| 4938 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 4939 | public: |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4940 | RIPFixup(const CodeGeneratorX86_64& codegen, int offset) |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4941 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 4942 | |
| 4943 | private: |
| 4944 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 4945 | // Patch the correct offset for the instruction. We use the address of the |
| 4946 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 4947 | int constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 4948 | int relative_position = constant_offset - pos; |
| 4949 | |
| 4950 | // Patch in the right value. |
| 4951 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 4952 | } |
| 4953 | |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4954 | const CodeGeneratorX86_64& codegen_; |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4955 | |
| 4956 | // Location in constant area that the fixup refers to. |
| 4957 | int offset_into_constant_area_; |
| 4958 | }; |
| 4959 | |
| 4960 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 4961 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 4962 | return Address::RIP(fixup); |
| 4963 | } |
| 4964 | |
| 4965 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 4966 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 4967 | return Address::RIP(fixup); |
| 4968 | } |
| 4969 | |
| 4970 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 4971 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 4972 | return Address::RIP(fixup); |
| 4973 | } |
| 4974 | |
| 4975 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 4976 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 4977 | return Address::RIP(fixup); |
| 4978 | } |
| 4979 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4980 | #undef __ |
| 4981 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4982 | } // namespace x86_64 |
| 4983 | } // namespace art |