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