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