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