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