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