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