Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
| 19 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 20 | #include "gc/accounting/card_table.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 21 | #include "mirror/array-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "mirror/art_method.h" |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 23 | #include "mirror/class.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 24 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 25 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 26 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 27 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 28 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 29 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 31 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | namespace x86 { |
| 33 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 34 | static constexpr bool kExplicitStackOverflowCheck = false; |
| 35 | |
| 36 | static constexpr int kNumberOfPushedRegistersAtEntry = 1; |
| 37 | static constexpr int kCurrentMethodStackOffset = 0; |
| 38 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 39 | static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX }; |
| 40 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 41 | arraysize(kRuntimeParameterCoreRegisters); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 42 | static constexpr XmmRegister kRuntimeParameterFpuRegisters[] = { }; |
| 43 | static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 44 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 45 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, XmmRegister> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 46 | public: |
| 47 | InvokeRuntimeCallingConvention() |
| 48 | : CallingConvention(kRuntimeParameterCoreRegisters, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 49 | kRuntimeParameterCoreRegistersLength, |
| 50 | kRuntimeParameterFpuRegisters, |
| 51 | kRuntimeParameterFpuRegistersLength) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 52 | |
| 53 | private: |
| 54 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 55 | }; |
| 56 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | #define __ reinterpret_cast<X86Assembler*>(codegen->GetAssembler())-> |
| 58 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 59 | class SlowPathCodeX86 : public SlowPathCode { |
| 60 | public: |
| 61 | SlowPathCodeX86() : entry_label_(), exit_label_() {} |
| 62 | |
| 63 | Label* GetEntryLabel() { return &entry_label_; } |
| 64 | Label* GetExitLabel() { return &exit_label_; } |
| 65 | |
| 66 | private: |
| 67 | Label entry_label_; |
| 68 | Label exit_label_; |
| 69 | |
| 70 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeX86); |
| 71 | }; |
| 72 | |
| 73 | class NullCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 75 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | |
| 77 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 78 | __ Bind(GetEntryLabel()); |
| 79 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowNullPointer))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 80 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 84 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 86 | }; |
| 87 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 88 | class StackOverflowCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 89 | public: |
| 90 | StackOverflowCheckSlowPathX86() {} |
| 91 | |
| 92 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 93 | __ Bind(GetEntryLabel()); |
| 94 | __ addl(ESP, |
| 95 | Immediate(codegen->GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
| 96 | __ fs()->jmp(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowStackOverflow))); |
| 97 | } |
| 98 | |
| 99 | private: |
| 100 | DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathX86); |
| 101 | }; |
| 102 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 103 | class BoundsCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 104 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 105 | BoundsCheckSlowPathX86(HBoundsCheck* instruction, |
| 106 | Location index_location, |
| 107 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 108 | : instruction_(instruction), index_location_(index_location), length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 109 | |
| 110 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 111 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 112 | __ Bind(GetEntryLabel()); |
| 113 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 114 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_); |
| 115 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 116 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowArrayBounds))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 117 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 121 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 122 | const Location index_location_; |
| 123 | const Location length_location_; |
| 124 | |
| 125 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 126 | }; |
| 127 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 128 | class SuspendCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 129 | public: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 130 | explicit SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
| 131 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 132 | |
| 133 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 134 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 135 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 136 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 137 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pTestSuspend))); |
| 138 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 139 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 140 | if (successor_ == nullptr) { |
| 141 | __ jmp(GetReturnLabel()); |
| 142 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 143 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 144 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 147 | Label* GetReturnLabel() { |
| 148 | DCHECK(successor_ == nullptr); |
| 149 | return &return_label_; |
| 150 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 151 | |
| 152 | private: |
| 153 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 154 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 155 | Label return_label_; |
| 156 | |
| 157 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 158 | }; |
| 159 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 160 | #undef __ |
| 161 | #define __ reinterpret_cast<X86Assembler*>(GetAssembler())-> |
| 162 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 163 | inline Condition X86Condition(IfCondition cond) { |
| 164 | switch (cond) { |
| 165 | case kCondEQ: return kEqual; |
| 166 | case kCondNE: return kNotEqual; |
| 167 | case kCondLT: return kLess; |
| 168 | case kCondLE: return kLessEqual; |
| 169 | case kCondGT: return kGreater; |
| 170 | case kCondGE: return kGreaterEqual; |
| 171 | default: |
| 172 | LOG(FATAL) << "Unknown if condition"; |
| 173 | } |
| 174 | return kEqual; |
| 175 | } |
| 176 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 177 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 178 | stream << X86ManagedRegister::FromCpuRegister(Register(reg)); |
| 179 | } |
| 180 | |
| 181 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 182 | stream << X86ManagedRegister::FromXmmRegister(XmmRegister(reg)); |
| 183 | } |
| 184 | |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 185 | void CodeGeneratorX86::SaveCoreRegister(Location stack_location, uint32_t reg_id) { |
| 186 | __ movl(Address(ESP, stack_location.GetStackIndex()), static_cast<Register>(reg_id)); |
| 187 | } |
| 188 | |
| 189 | void CodeGeneratorX86::RestoreCoreRegister(Location stack_location, uint32_t reg_id) { |
| 190 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_location.GetStackIndex())); |
| 191 | } |
| 192 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 193 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph) |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 194 | : CodeGenerator(graph, kNumberOfCpuRegisters, kNumberOfXmmRegisters, kNumberOfRegisterPairs), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 195 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 196 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 197 | instruction_visitor_(graph, this), |
| 198 | move_resolver_(graph->GetArena(), this) {} |
| 199 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 200 | size_t CodeGeneratorX86::FrameEntrySpillSize() const { |
| 201 | return kNumberOfPushedRegistersAtEntry * kX86WordSize; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 202 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 203 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 204 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 205 | switch (type) { |
| 206 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 207 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 208 | X86ManagedRegister pair = |
| 209 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame^] | 210 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 211 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 212 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 213 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame^] | 214 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 215 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | case Primitive::kPrimByte: |
| 219 | case Primitive::kPrimBoolean: |
| 220 | case Primitive::kPrimChar: |
| 221 | case Primitive::kPrimShort: |
| 222 | case Primitive::kPrimInt: |
| 223 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 224 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 225 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 226 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 227 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 228 | X86ManagedRegister current = |
| 229 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 230 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 231 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 232 | } |
| 233 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 234 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 238 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 239 | return Location::FpuRegisterLocation( |
| 240 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 241 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 242 | |
| 243 | case Primitive::kPrimVoid: |
| 244 | LOG(FATAL) << "Unreachable type " << type; |
| 245 | } |
| 246 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 247 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 250 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 251 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 252 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 253 | |
| 254 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 255 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 256 | |
| 257 | // TODO: We currently don't use Quick's callee saved registers. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 258 | blocked_core_registers_[EBP] = true; |
| 259 | blocked_core_registers_[ESI] = true; |
| 260 | blocked_core_registers_[EDI] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame^] | 261 | |
| 262 | UpdateBlockedPairRegisters(); |
| 263 | } |
| 264 | |
| 265 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 266 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 267 | X86ManagedRegister current = |
| 268 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 269 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 270 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 271 | blocked_register_pairs_[i] = true; |
| 272 | } |
| 273 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 276 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 277 | : HGraphVisitor(graph), |
| 278 | assembler_(codegen->GetAssembler()), |
| 279 | codegen_(codegen) {} |
| 280 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 281 | void CodeGeneratorX86::GenerateFrameEntry() { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 282 | // Create a fake register to mimic Quick. |
| 283 | static const int kFakeReturnRegister = 8; |
| 284 | core_spill_mask_ |= (1 << kFakeReturnRegister); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 285 | |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 286 | bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 287 | if (!skip_overflow_check && !kExplicitStackOverflowCheck) { |
| 288 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 289 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 290 | } |
| 291 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 292 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 293 | __ subl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 294 | |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 295 | if (!skip_overflow_check && kExplicitStackOverflowCheck) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 296 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86(); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 297 | AddSlowPath(slow_path); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 298 | |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 299 | __ fs()->cmpl(ESP, Address::Absolute(Thread::StackEndOffset<kX86WordSize>())); |
| 300 | __ j(kLess, slow_path->GetEntryLabel()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 303 | __ movl(Address(ESP, kCurrentMethodStackOffset), EAX); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void CodeGeneratorX86::GenerateFrameExit() { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 307 | __ addl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 310 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 311 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 314 | void InstructionCodeGeneratorX86::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 315 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 318 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 319 | switch (load->GetType()) { |
| 320 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 321 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 322 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 323 | break; |
| 324 | |
| 325 | case Primitive::kPrimInt: |
| 326 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 327 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 328 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 329 | |
| 330 | case Primitive::kPrimBoolean: |
| 331 | case Primitive::kPrimByte: |
| 332 | case Primitive::kPrimChar: |
| 333 | case Primitive::kPrimShort: |
| 334 | case Primitive::kPrimVoid: |
| 335 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 336 | } |
| 337 | |
| 338 | LOG(FATAL) << "Unreachable"; |
| 339 | return Location(); |
| 340 | } |
| 341 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 342 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 343 | switch (type) { |
| 344 | case Primitive::kPrimBoolean: |
| 345 | case Primitive::kPrimByte: |
| 346 | case Primitive::kPrimChar: |
| 347 | case Primitive::kPrimShort: |
| 348 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 349 | case Primitive::kPrimFloat: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 350 | case Primitive::kPrimNot: { |
| 351 | uint32_t index = gp_index_++; |
| 352 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 353 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 354 | } else { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 355 | return Location::StackSlot(calling_convention.GetStackOffsetOf(index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 356 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 357 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 358 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 359 | case Primitive::kPrimLong: |
| 360 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 361 | uint32_t index = gp_index_; |
| 362 | gp_index_ += 2; |
| 363 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 364 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 365 | calling_convention.GetRegisterPairAt(index)); |
| 366 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 367 | } else if (index + 1 == calling_convention.GetNumberOfRegisters()) { |
| 368 | return Location::QuickParameter(index); |
| 369 | } else { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 370 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 374 | case Primitive::kPrimVoid: |
| 375 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 376 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 377 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 378 | return Location(); |
| 379 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 380 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 381 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 382 | if (source.Equals(destination)) { |
| 383 | return; |
| 384 | } |
| 385 | if (destination.IsRegister()) { |
| 386 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 387 | __ movl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 388 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 389 | __ movd(destination.As<Register>(), source.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 390 | } else { |
| 391 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 392 | __ movl(destination.As<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 393 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 394 | } else if (destination.IsFpuRegister()) { |
| 395 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 396 | __ movd(destination.As<XmmRegister>(), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 397 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 398 | __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 399 | } else { |
| 400 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 401 | __ movss(destination.As<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 402 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 403 | } else { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 404 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 405 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 406 | __ movl(Address(ESP, destination.GetStackIndex()), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 407 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 408 | __ movss(Address(ESP, destination.GetStackIndex()), source.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 409 | } else { |
| 410 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 411 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 412 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 418 | if (source.Equals(destination)) { |
| 419 | return; |
| 420 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 421 | if (destination.IsRegisterPair()) { |
| 422 | if (source.IsRegisterPair()) { |
| 423 | __ movl(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 424 | __ movl(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 425 | } else if (source.IsFpuRegister()) { |
| 426 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 427 | } else if (source.IsQuickParameter()) { |
| 428 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 429 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 430 | __ movl(destination.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 431 | calling_convention.GetRegisterAt(argument_index)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 432 | __ movl(destination.AsRegisterPairHigh<Register>(), Address(ESP, |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 433 | calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 434 | } else { |
| 435 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 436 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 437 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 438 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 439 | } |
| 440 | } else if (destination.IsQuickParameter()) { |
| 441 | InvokeDexCallingConvention calling_convention; |
| 442 | uint32_t argument_index = destination.GetQuickParameterIndex(); |
| 443 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 444 | __ movl(calling_convention.GetRegisterAt(argument_index), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 445 | __ movl(Address(ESP, calling_convention.GetStackOffsetOf(argument_index + 1)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 446 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 447 | } else if (source.IsFpuRegister()) { |
| 448 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 449 | } else { |
| 450 | DCHECK(source.IsDoubleStackSlot()); |
| 451 | __ movl(calling_convention.GetRegisterAt(argument_index), |
| 452 | Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 453 | __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 454 | __ popl(Address(ESP, calling_convention.GetStackOffsetOf(argument_index + 1))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 455 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 456 | } else if (destination.IsFpuRegister()) { |
| 457 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 458 | __ movsd(destination.As<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 459 | } else { |
| 460 | LOG(FATAL) << "Unimplemented"; |
| 461 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 462 | } else { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 463 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 464 | if (source.IsRegisterPair()) { |
| 465 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 466 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 467 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 468 | } else if (source.IsQuickParameter()) { |
| 469 | InvokeDexCallingConvention calling_convention; |
| 470 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 471 | __ movl(Address(ESP, destination.GetStackIndex()), |
| 472 | calling_convention.GetRegisterAt(argument_index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 473 | DCHECK_EQ(calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize(), |
| 474 | static_cast<size_t>(destination.GetHighStackIndex(kX86WordSize))); |
| 475 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 476 | __ movsd(Address(ESP, destination.GetStackIndex()), source.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 477 | } else { |
| 478 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 479 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 480 | __ popl(Address(ESP, destination.GetStackIndex())); |
| 481 | __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 482 | __ popl(Address(ESP, destination.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 487 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 488 | if (instruction->IsIntConstant()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 489 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 490 | if (location.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 491 | __ movl(location.As<Register>(), imm); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 492 | } else { |
| 493 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 494 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 495 | } else if (instruction->IsLongConstant()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 496 | int64_t value = instruction->AsLongConstant()->GetValue(); |
| 497 | if (location.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 498 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 499 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 500 | } else { |
| 501 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
| 502 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
| 503 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 504 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 505 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 506 | switch (instruction->GetType()) { |
| 507 | case Primitive::kPrimBoolean: |
| 508 | case Primitive::kPrimByte: |
| 509 | case Primitive::kPrimChar: |
| 510 | case Primitive::kPrimShort: |
| 511 | case Primitive::kPrimInt: |
| 512 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 513 | case Primitive::kPrimFloat: |
| 514 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 515 | break; |
| 516 | |
| 517 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 518 | case Primitive::kPrimDouble: |
| 519 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 520 | break; |
| 521 | |
| 522 | default: |
| 523 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 524 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 525 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 526 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 527 | switch (instruction->GetType()) { |
| 528 | case Primitive::kPrimBoolean: |
| 529 | case Primitive::kPrimByte: |
| 530 | case Primitive::kPrimChar: |
| 531 | case Primitive::kPrimShort: |
| 532 | case Primitive::kPrimInt: |
| 533 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 534 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 535 | Move32(location, instruction->GetLocations()->Out()); |
| 536 | break; |
| 537 | |
| 538 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 539 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 540 | Move64(location, instruction->GetLocations()->Out()); |
| 541 | break; |
| 542 | |
| 543 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 544 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 545 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
| 549 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 550 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 553 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 554 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 555 | DCHECK(!successor->IsExitBlock()); |
| 556 | |
| 557 | HBasicBlock* block = got->GetBlock(); |
| 558 | HInstruction* previous = got->GetPrevious(); |
| 559 | |
| 560 | HLoopInformation* info = block->GetLoopInformation(); |
| 561 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 562 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 563 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 568 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 569 | } |
| 570 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 571 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 575 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 576 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 579 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 580 | if (kIsDebugBuild) { |
| 581 | __ Comment("Unreachable"); |
| 582 | __ int3(); |
| 583 | } |
| 584 | } |
| 585 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 586 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 587 | LocationSummary* locations = |
| 588 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 589 | HInstruction* cond = if_instr->InputAt(0); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 590 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 591 | locations->SetInAt(0, Location::Any(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 592 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 595 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 596 | HInstruction* cond = if_instr->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 597 | if (cond->IsIntConstant()) { |
| 598 | // Constant condition, statically compared against 1. |
| 599 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 600 | if (cond_value == 1) { |
| 601 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 602 | if_instr->IfTrueSuccessor())) { |
| 603 | __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 604 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 605 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 606 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 607 | DCHECK_EQ(cond_value, 0); |
| 608 | } |
| 609 | } else { |
| 610 | bool materialized = |
| 611 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 612 | // Moves do not affect the eflags register, so if the condition is |
| 613 | // evaluated just before the if, we don't need to evaluate it |
| 614 | // again. |
| 615 | bool eflags_set = cond->IsCondition() |
| 616 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr); |
| 617 | if (materialized) { |
| 618 | if (!eflags_set) { |
| 619 | // Materialized condition, compare against 0. |
| 620 | Location lhs = if_instr->GetLocations()->InAt(0); |
| 621 | if (lhs.IsRegister()) { |
| 622 | __ cmpl(lhs.As<Register>(), Immediate(0)); |
| 623 | } else { |
| 624 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 625 | } |
| 626 | __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 627 | } else { |
| 628 | __ j(X86Condition(cond->AsCondition()->GetCondition()), |
| 629 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 630 | } |
| 631 | } else { |
| 632 | Location lhs = cond->GetLocations()->InAt(0); |
| 633 | Location rhs = cond->GetLocations()->InAt(1); |
| 634 | // LHS is guaranteed to be in a register (see |
| 635 | // LocationsBuilderX86::VisitCondition). |
| 636 | if (rhs.IsRegister()) { |
| 637 | __ cmpl(lhs.As<Register>(), rhs.As<Register>()); |
| 638 | } else if (rhs.IsConstant()) { |
| 639 | HIntConstant* instruction = rhs.GetConstant()->AsIntConstant(); |
| 640 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 641 | __ cmpl(lhs.As<Register>(), imm); |
| 642 | } else { |
| 643 | __ cmpl(lhs.As<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 644 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 645 | __ j(X86Condition(cond->AsCondition()->GetCondition()), |
| 646 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 647 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 648 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 649 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 650 | if_instr->IfFalseSuccessor())) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 651 | __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | |
| 655 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 656 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 659 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 660 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 663 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 664 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 667 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 668 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 671 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 672 | LocationSummary* locations = |
| 673 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 674 | switch (store->InputAt(1)->GetType()) { |
| 675 | case Primitive::kPrimBoolean: |
| 676 | case Primitive::kPrimByte: |
| 677 | case Primitive::kPrimChar: |
| 678 | case Primitive::kPrimShort: |
| 679 | case Primitive::kPrimInt: |
| 680 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 681 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 682 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 683 | break; |
| 684 | |
| 685 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 686 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 687 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 688 | break; |
| 689 | |
| 690 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 691 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 692 | } |
| 693 | store->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 696 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 699 | void LocationsBuilderX86::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 700 | LocationSummary* locations = |
| 701 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 702 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 703 | locations->SetInAt(1, Location::Any(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 704 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 705 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 706 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 709 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* comp) { |
| 710 | if (comp->NeedsMaterialization()) { |
| 711 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 712 | Register reg = locations->Out().As<Register>(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 713 | // Clear register: setcc only sets the low byte. |
| 714 | __ xorl(reg, reg); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 715 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 716 | __ cmpl(locations->InAt(0).As<Register>(), |
| 717 | locations->InAt(1).As<Register>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 718 | } else if (locations->InAt(1).IsConstant()) { |
| 719 | HConstant* instruction = locations->InAt(1).GetConstant(); |
| 720 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 721 | __ cmpl(locations->InAt(0).As<Register>(), imm); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 722 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 723 | __ cmpl(locations->InAt(0).As<Register>(), |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 724 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 725 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 726 | __ setb(X86Condition(comp->GetCondition()), reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 727 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 731 | VisitCondition(comp); |
| 732 | } |
| 733 | |
| 734 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 735 | VisitCondition(comp); |
| 736 | } |
| 737 | |
| 738 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 739 | VisitCondition(comp); |
| 740 | } |
| 741 | |
| 742 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 743 | VisitCondition(comp); |
| 744 | } |
| 745 | |
| 746 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 747 | VisitCondition(comp); |
| 748 | } |
| 749 | |
| 750 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 751 | VisitCondition(comp); |
| 752 | } |
| 753 | |
| 754 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 755 | VisitCondition(comp); |
| 756 | } |
| 757 | |
| 758 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 759 | VisitCondition(comp); |
| 760 | } |
| 761 | |
| 762 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 763 | VisitCondition(comp); |
| 764 | } |
| 765 | |
| 766 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 767 | VisitCondition(comp); |
| 768 | } |
| 769 | |
| 770 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 771 | VisitCondition(comp); |
| 772 | } |
| 773 | |
| 774 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 775 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 779 | LocationSummary* locations = |
| 780 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 781 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 784 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 785 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 788 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 789 | LocationSummary* locations = |
| 790 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 791 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 795 | // Will be generated at use site. |
| 796 | } |
| 797 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 798 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 799 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 802 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
| 803 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 804 | __ ret(); |
| 805 | } |
| 806 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 807 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 808 | LocationSummary* locations = |
| 809 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 810 | switch (ret->InputAt(0)->GetType()) { |
| 811 | case Primitive::kPrimBoolean: |
| 812 | case Primitive::kPrimByte: |
| 813 | case Primitive::kPrimChar: |
| 814 | case Primitive::kPrimShort: |
| 815 | case Primitive::kPrimInt: |
| 816 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 817 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 818 | break; |
| 819 | |
| 820 | case Primitive::kPrimLong: |
| 821 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 822 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 823 | break; |
| 824 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 825 | case Primitive::kPrimFloat: |
| 826 | case Primitive::kPrimDouble: |
| 827 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 828 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 829 | break; |
| 830 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 831 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 832 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 833 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 836 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 837 | if (kIsDebugBuild) { |
| 838 | switch (ret->InputAt(0)->GetType()) { |
| 839 | case Primitive::kPrimBoolean: |
| 840 | case Primitive::kPrimByte: |
| 841 | case Primitive::kPrimChar: |
| 842 | case Primitive::kPrimShort: |
| 843 | case Primitive::kPrimInt: |
| 844 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 845 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 846 | break; |
| 847 | |
| 848 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 849 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 850 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 851 | break; |
| 852 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 853 | case Primitive::kPrimFloat: |
| 854 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 855 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 856 | break; |
| 857 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 858 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 859 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 860 | } |
| 861 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 862 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 863 | __ ret(); |
| 864 | } |
| 865 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 866 | void LocationsBuilderX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 867 | HandleInvoke(invoke); |
| 868 | } |
| 869 | |
| 870 | void InstructionCodeGeneratorX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 871 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 872 | uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>); |
| 873 | size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).Int32Value() + |
| 874 | invoke->GetIndexInDexCache() * kX86WordSize; |
| 875 | |
| 876 | // TODO: Implement all kinds of calls: |
| 877 | // 1) boot -> boot |
| 878 | // 2) app -> boot |
| 879 | // 3) app -> app |
| 880 | // |
| 881 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 882 | |
| 883 | // temp = method; |
| 884 | LoadCurrentMethod(temp); |
| 885 | // temp = temp->dex_cache_resolved_methods_; |
| 886 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 887 | // temp = temp[index_in_cache] |
| 888 | __ movl(temp, Address(temp, index_in_cache)); |
| 889 | // (temp + offset_of_quick_compiled_code)() |
| 890 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 891 | |
| 892 | DCHECK(!codegen_->IsLeafMethod()); |
| 893 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 894 | } |
| 895 | |
| 896 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 897 | HandleInvoke(invoke); |
| 898 | } |
| 899 | |
| 900 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 901 | LocationSummary* locations = |
| 902 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 903 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 904 | |
| 905 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 906 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 907 | HInstruction* input = invoke->InputAt(i); |
| 908 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 909 | } |
| 910 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 911 | switch (invoke->GetType()) { |
| 912 | case Primitive::kPrimBoolean: |
| 913 | case Primitive::kPrimByte: |
| 914 | case Primitive::kPrimChar: |
| 915 | case Primitive::kPrimShort: |
| 916 | case Primitive::kPrimInt: |
| 917 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 918 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 919 | break; |
| 920 | |
| 921 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 922 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 923 | break; |
| 924 | |
| 925 | case Primitive::kPrimVoid: |
| 926 | break; |
| 927 | |
| 928 | case Primitive::kPrimDouble: |
| 929 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 930 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 931 | break; |
| 932 | } |
| 933 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 934 | invoke->SetLocations(locations); |
| 935 | } |
| 936 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 937 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 938 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 939 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 940 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 941 | LocationSummary* locations = invoke->GetLocations(); |
| 942 | Location receiver = locations->InAt(0); |
| 943 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 944 | // temp = object->GetClass(); |
| 945 | if (receiver.IsStackSlot()) { |
| 946 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 947 | __ movl(temp, Address(temp, class_offset)); |
| 948 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 949 | __ movl(temp, Address(receiver.As<Register>(), class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 950 | } |
| 951 | // temp = temp->GetMethodAt(method_offset); |
| 952 | __ movl(temp, Address(temp, method_offset)); |
| 953 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 954 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 955 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 956 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 957 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 960 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 961 | LocationSummary* locations = |
| 962 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 963 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 964 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 965 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 966 | locations->SetInAt(0, Location::RequiresRegister()); |
| 967 | locations->SetInAt(1, Location::Any()); |
| 968 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 969 | break; |
| 970 | } |
| 971 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 972 | case Primitive::kPrimFloat: |
| 973 | case Primitive::kPrimDouble: { |
| 974 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 975 | locations->SetInAt(1, Location::Any()); |
| 976 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 977 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 978 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 979 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 980 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 981 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 982 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 983 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 987 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 988 | Location first = locations->InAt(0); |
| 989 | Location second = locations->InAt(1); |
| 990 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 991 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 992 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 993 | DCHECK_EQ(first.As<Register>(), locations->Out().As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 994 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 995 | __ addl(first.As<Register>(), second.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 996 | } else if (second.IsConstant()) { |
| 997 | HConstant* instruction = second.GetConstant(); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 998 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 999 | __ addl(first.As<Register>(), imm); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1000 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1001 | __ addl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1002 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1003 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1007 | DCHECK_EQ(first.AsRegisterPairLow<Register>(), |
| 1008 | locations->Out().AsRegisterPairLow<Register>()); |
| 1009 | DCHECK_EQ(first.AsRegisterPairHigh<Register>(), |
| 1010 | locations->Out().AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1011 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1012 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1013 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1014 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1015 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 1016 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1017 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1018 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1019 | break; |
| 1020 | } |
| 1021 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1022 | case Primitive::kPrimFloat: { |
| 1023 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1024 | __ addss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1025 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1026 | __ addss(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1027 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1028 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | case Primitive::kPrimDouble: { |
| 1032 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1033 | __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1034 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1035 | __ addsd(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1036 | } |
| 1037 | break; |
| 1038 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1039 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1040 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1041 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1045 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1046 | LocationSummary* locations = |
| 1047 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1048 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1049 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1050 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1051 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1052 | locations->SetInAt(1, Location::Any()); |
| 1053 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1054 | break; |
| 1055 | } |
| 1056 | |
| 1057 | case Primitive::kPrimBoolean: |
| 1058 | case Primitive::kPrimByte: |
| 1059 | case Primitive::kPrimChar: |
| 1060 | case Primitive::kPrimShort: |
| 1061 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 1062 | break; |
| 1063 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1064 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1065 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1066 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 1070 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1071 | Location first = locations->InAt(0); |
| 1072 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1073 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1074 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1075 | DCHECK_EQ(first.As<Register>(), |
| 1076 | locations->Out().As<Register>()); |
| 1077 | if (second.IsRegister()) { |
| 1078 | __ subl(first.As<Register>(), |
| 1079 | second.As<Register>()); |
| 1080 | } else if (second.IsConstant()) { |
| 1081 | HConstant* instruction = second.GetConstant(); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1082 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1083 | __ subl(first.As<Register>(), imm); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1084 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1085 | __ subl(first.As<Register>(), |
| 1086 | Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1087 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1088 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1092 | DCHECK_EQ(first.AsRegisterPairLow<Register>(), |
| 1093 | locations->Out().AsRegisterPairLow<Register>()); |
| 1094 | DCHECK_EQ(first.AsRegisterPairHigh<Register>(), |
| 1095 | locations->Out().AsRegisterPairHigh<Register>()); |
| 1096 | if (second.IsRegister()) { |
| 1097 | __ subl(first.AsRegisterPairLow<Register>(), |
| 1098 | second.AsRegisterPairLow<Register>()); |
| 1099 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 1100 | second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1101 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1102 | __ subl(first.AsRegisterPairLow<Register>(), |
| 1103 | Address(ESP, second.GetStackIndex())); |
| 1104 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 1105 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1106 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1107 | break; |
| 1108 | } |
| 1109 | |
| 1110 | case Primitive::kPrimBoolean: |
| 1111 | case Primitive::kPrimByte: |
| 1112 | case Primitive::kPrimChar: |
| 1113 | case Primitive::kPrimShort: |
| 1114 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 1115 | break; |
| 1116 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1117 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1118 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame^] | 1122 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 1123 | LocationSummary* locations = |
| 1124 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1125 | switch (mul->GetResultType()) { |
| 1126 | case Primitive::kPrimInt: |
| 1127 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1128 | locations->SetInAt(1, Location::Any()); |
| 1129 | locations->SetOut(Location::SameAsFirstInput()); |
| 1130 | break; |
| 1131 | case Primitive::kPrimLong: { |
| 1132 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1133 | // TODO: Currently this handles only stack operands: |
| 1134 | // - we don't have enough registers because we currently use Quick ABI. |
| 1135 | // - by the time we have a working register allocator we will probably change the ABI |
| 1136 | // and fix the above. |
| 1137 | // - we don't have a way yet to request operands on stack but the base line compiler |
| 1138 | // will leave the operands on the stack with Any(). |
| 1139 | locations->SetInAt(1, Location::Any()); |
| 1140 | locations->SetOut(Location::SameAsFirstInput()); |
| 1141 | // Needed for imul on 32bits with 64bits output. |
| 1142 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 1143 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 1144 | break; |
| 1145 | } |
| 1146 | |
| 1147 | case Primitive::kPrimBoolean: |
| 1148 | case Primitive::kPrimByte: |
| 1149 | case Primitive::kPrimChar: |
| 1150 | case Primitive::kPrimShort: |
| 1151 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 1152 | break; |
| 1153 | |
| 1154 | default: |
| 1155 | LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType(); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 1160 | LocationSummary* locations = mul->GetLocations(); |
| 1161 | Location first = locations->InAt(0); |
| 1162 | Location second = locations->InAt(1); |
| 1163 | DCHECK(first.Equals(locations->Out())); |
| 1164 | |
| 1165 | switch (mul->GetResultType()) { |
| 1166 | case Primitive::kPrimInt: { |
| 1167 | if (second.IsRegister()) { |
| 1168 | __ imull(first.As<Register>(), second.As<Register>()); |
| 1169 | } else if (second.IsConstant()) { |
| 1170 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1171 | __ imull(first.As<Register>(), imm); |
| 1172 | } else { |
| 1173 | DCHECK(second.IsStackSlot()); |
| 1174 | __ imull(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 1175 | } |
| 1176 | break; |
| 1177 | } |
| 1178 | |
| 1179 | case Primitive::kPrimLong: { |
| 1180 | DCHECK(second.IsDoubleStackSlot()); |
| 1181 | |
| 1182 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 1183 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 1184 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 1185 | Address in2_lo(ESP, second.GetStackIndex()); |
| 1186 | Register eax = locations->GetTemp(0).As<Register>(); |
| 1187 | Register edx = locations->GetTemp(1).As<Register>(); |
| 1188 | |
| 1189 | DCHECK_EQ(EAX, eax); |
| 1190 | DCHECK_EQ(EDX, edx); |
| 1191 | |
| 1192 | // input: in1 - 64 bits, in2 - 64 bits |
| 1193 | // output: in1 |
| 1194 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 1195 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 1196 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| 1197 | |
| 1198 | __ movl(eax, in2_hi); |
| 1199 | // eax <- in1.lo * in2.hi |
| 1200 | __ imull(eax, in1_lo); |
| 1201 | // in1.hi <- in1.hi * in2.lo |
| 1202 | __ imull(in1_hi, in2_lo); |
| 1203 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 1204 | __ addl(in1_hi, eax); |
| 1205 | // move in1_lo to eax to prepare for double precision |
| 1206 | __ movl(eax, in1_lo); |
| 1207 | // edx:eax <- in1.lo * in2.lo |
| 1208 | __ mull(in2_lo); |
| 1209 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 1210 | __ addl(in1_hi, edx); |
| 1211 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 1212 | __ movl(in1_lo, eax); |
| 1213 | |
| 1214 | break; |
| 1215 | } |
| 1216 | |
| 1217 | case Primitive::kPrimBoolean: |
| 1218 | case Primitive::kPrimByte: |
| 1219 | case Primitive::kPrimChar: |
| 1220 | case Primitive::kPrimShort: |
| 1221 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 1222 | break; |
| 1223 | |
| 1224 | default: |
| 1225 | LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType(); |
| 1226 | } |
| 1227 | } |
| 1228 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1229 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1230 | LocationSummary* locations = |
| 1231 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1232 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1233 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1234 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1235 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 1239 | InvokeRuntimeCallingConvention calling_convention; |
| 1240 | LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1241 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1242 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 1243 | __ fs()->call( |
| 1244 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1245 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1246 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1247 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1248 | } |
| 1249 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1250 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1251 | LocationSummary* locations = |
| 1252 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1253 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1254 | if (location.IsStackSlot()) { |
| 1255 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1256 | } else if (location.IsDoubleStackSlot()) { |
| 1257 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1258 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1259 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1263 | } |
| 1264 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1265 | void LocationsBuilderX86::VisitNot(HNot* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1266 | LocationSummary* locations = |
| 1267 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1268 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1269 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | void InstructionCodeGeneratorX86::VisitNot(HNot* instruction) { |
| 1273 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1274 | Location out = locations->Out(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1275 | DCHECK_EQ(locations->InAt(0).As<Register>(), out.As<Register>()); |
| 1276 | __ xorl(out.As<Register>(), Immediate(1)); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1277 | } |
| 1278 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1279 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1280 | LocationSummary* locations = |
| 1281 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1282 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1283 | locations->SetInAt(1, Location::Any(), Location::kDiesAtEntry); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1284 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
| 1288 | Label greater, done; |
| 1289 | LocationSummary* locations = compare->GetLocations(); |
| 1290 | switch (compare->InputAt(0)->GetType()) { |
| 1291 | case Primitive::kPrimLong: { |
| 1292 | Label less, greater, done; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1293 | Register output = locations->Out().As<Register>(); |
| 1294 | Location left = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1295 | Location right = locations->InAt(1); |
| 1296 | if (right.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1297 | __ cmpl(left.AsRegisterPairHigh<Register>(), right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1298 | } else { |
| 1299 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1300 | __ cmpl(left.AsRegisterPairHigh<Register>(), |
| 1301 | Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1302 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1303 | __ j(kLess, &less); // Signed compare. |
| 1304 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1305 | if (right.IsRegisterPair()) { |
| 1306 | __ cmpl(left.AsRegisterPairLow<Register>(), right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1307 | } else { |
| 1308 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1309 | __ cmpl(left.AsRegisterPairLow<Register>(), Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1310 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1311 | __ movl(output, Immediate(0)); |
| 1312 | __ j(kEqual, &done); |
| 1313 | __ j(kBelow, &less); // Unsigned compare. |
| 1314 | |
| 1315 | __ Bind(&greater); |
| 1316 | __ movl(output, Immediate(1)); |
| 1317 | __ jmp(&done); |
| 1318 | |
| 1319 | __ Bind(&less); |
| 1320 | __ movl(output, Immediate(-1)); |
| 1321 | |
| 1322 | __ Bind(&done); |
| 1323 | break; |
| 1324 | } |
| 1325 | default: |
| 1326 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 1327 | } |
| 1328 | } |
| 1329 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1330 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1331 | LocationSummary* locations = |
| 1332 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1333 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1334 | locations->SetInAt(i, Location::Any()); |
| 1335 | } |
| 1336 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1340 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1341 | } |
| 1342 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1343 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1344 | LocationSummary* locations = |
| 1345 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1346 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1347 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1348 | bool is_object_type = field_type == Primitive::kPrimNot; |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1349 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 1350 | || (field_type == Primitive::kPrimByte); |
| 1351 | // The register allocator does not support multiple |
| 1352 | // inputs that die at entry with one in a specific register. |
| 1353 | bool dies_at_entry = !is_object_type && !is_byte_type; |
| 1354 | if (is_byte_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1355 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1356 | locations->SetInAt(1, Location::RegisterLocation(EAX), dies_at_entry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1357 | } else { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1358 | locations->SetInAt(1, Location::RequiresRegister(), dies_at_entry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1359 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1360 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1361 | if (is_object_type) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1362 | locations->AddTemp(Location::RequiresRegister()); |
| 1363 | // Ensure the card is in a byte register. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1364 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1365 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1369 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1370 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1371 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1372 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1373 | |
| 1374 | switch (field_type) { |
| 1375 | case Primitive::kPrimBoolean: |
| 1376 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1377 | ByteRegister value = locations->InAt(1).As<ByteRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1378 | __ movb(Address(obj, offset), value); |
| 1379 | break; |
| 1380 | } |
| 1381 | |
| 1382 | case Primitive::kPrimShort: |
| 1383 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1384 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1385 | __ movw(Address(obj, offset), value); |
| 1386 | break; |
| 1387 | } |
| 1388 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1389 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1390 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1391 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1392 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1393 | |
| 1394 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1395 | Register temp = locations->GetTemp(0).As<Register>(); |
| 1396 | Register card = locations->GetTemp(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1397 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1398 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1399 | break; |
| 1400 | } |
| 1401 | |
| 1402 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1403 | Location value = locations->InAt(1); |
| 1404 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 1405 | __ movl(Address(obj, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1406 | break; |
| 1407 | } |
| 1408 | |
| 1409 | case Primitive::kPrimFloat: |
| 1410 | case Primitive::kPrimDouble: |
| 1411 | LOG(FATAL) << "Unimplemented register type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1412 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1413 | case Primitive::kPrimVoid: |
| 1414 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1415 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1416 | } |
| 1417 | } |
| 1418 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1419 | void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 1420 | Label is_null; |
| 1421 | __ testl(value, value); |
| 1422 | __ j(kEqual, &is_null); |
| 1423 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 1424 | __ movl(temp, object); |
| 1425 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 1426 | __ movb(Address(temp, card, TIMES_1, 0), |
| 1427 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| 1428 | __ Bind(&is_null); |
| 1429 | } |
| 1430 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1431 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1432 | LocationSummary* locations = |
| 1433 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1434 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1435 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1439 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1440 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1441 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 1442 | |
| 1443 | switch (instruction->GetType()) { |
| 1444 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1445 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1446 | __ movzxb(out, Address(obj, offset)); |
| 1447 | break; |
| 1448 | } |
| 1449 | |
| 1450 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1451 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1452 | __ movsxb(out, Address(obj, offset)); |
| 1453 | break; |
| 1454 | } |
| 1455 | |
| 1456 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1457 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1458 | __ movsxw(out, Address(obj, offset)); |
| 1459 | break; |
| 1460 | } |
| 1461 | |
| 1462 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1463 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1464 | __ movzxw(out, Address(obj, offset)); |
| 1465 | break; |
| 1466 | } |
| 1467 | |
| 1468 | case Primitive::kPrimInt: |
| 1469 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1470 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1471 | __ movl(out, Address(obj, offset)); |
| 1472 | break; |
| 1473 | } |
| 1474 | |
| 1475 | case Primitive::kPrimLong: { |
| 1476 | // TODO: support volatile. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1477 | __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 1478 | __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(obj, kX86WordSize + offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1479 | break; |
| 1480 | } |
| 1481 | |
| 1482 | case Primitive::kPrimFloat: |
| 1483 | case Primitive::kPrimDouble: |
| 1484 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1485 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1486 | case Primitive::kPrimVoid: |
| 1487 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1488 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1493 | LocationSummary* locations = |
| 1494 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1495 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1496 | if (instruction->HasUses()) { |
| 1497 | locations->SetOut(Location::SameAsFirstInput()); |
| 1498 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1502 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1503 | codegen_->AddSlowPath(slow_path); |
| 1504 | |
| 1505 | LocationSummary* locations = instruction->GetLocations(); |
| 1506 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1507 | |
| 1508 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1509 | __ cmpl(obj.As<Register>(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1510 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1511 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1512 | } else { |
| 1513 | DCHECK(obj.IsConstant()) << obj; |
| 1514 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1515 | __ jmp(slow_path->GetEntryLabel()); |
| 1516 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1517 | } |
| 1518 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1519 | } |
| 1520 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1521 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1522 | LocationSummary* locations = |
| 1523 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1524 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1525 | locations->SetInAt( |
| 1526 | 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1527 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 1531 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1532 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1533 | Location index = locations->InAt(1); |
| 1534 | |
| 1535 | switch (instruction->GetType()) { |
| 1536 | case Primitive::kPrimBoolean: { |
| 1537 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1538 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1539 | if (index.IsConstant()) { |
| 1540 | __ movzxb(out, Address(obj, |
| 1541 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1542 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1543 | __ movzxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1544 | } |
| 1545 | break; |
| 1546 | } |
| 1547 | |
| 1548 | case Primitive::kPrimByte: { |
| 1549 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1550 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1551 | if (index.IsConstant()) { |
| 1552 | __ movsxb(out, Address(obj, |
| 1553 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1554 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1555 | __ movsxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1556 | } |
| 1557 | break; |
| 1558 | } |
| 1559 | |
| 1560 | case Primitive::kPrimShort: { |
| 1561 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1562 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1563 | if (index.IsConstant()) { |
| 1564 | __ movsxw(out, Address(obj, |
| 1565 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1566 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1567 | __ movsxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1568 | } |
| 1569 | break; |
| 1570 | } |
| 1571 | |
| 1572 | case Primitive::kPrimChar: { |
| 1573 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1574 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1575 | if (index.IsConstant()) { |
| 1576 | __ movzxw(out, Address(obj, |
| 1577 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1578 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1579 | __ movzxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1580 | } |
| 1581 | break; |
| 1582 | } |
| 1583 | |
| 1584 | case Primitive::kPrimInt: |
| 1585 | case Primitive::kPrimNot: { |
| 1586 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1587 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1588 | if (index.IsConstant()) { |
| 1589 | __ movl(out, Address(obj, |
| 1590 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 1591 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1592 | __ movl(out, Address(obj, index.As<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1593 | } |
| 1594 | break; |
| 1595 | } |
| 1596 | |
| 1597 | case Primitive::kPrimLong: { |
| 1598 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1599 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1600 | if (index.IsConstant()) { |
| 1601 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1602 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 1603 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1604 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1605 | __ movl(out.AsRegisterPairLow<Register>(), |
| 1606 | Address(obj, index.As<Register>(), TIMES_8, data_offset)); |
| 1607 | __ movl(out.AsRegisterPairHigh<Register>(), |
| 1608 | Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1609 | } |
| 1610 | break; |
| 1611 | } |
| 1612 | |
| 1613 | case Primitive::kPrimFloat: |
| 1614 | case Primitive::kPrimDouble: |
| 1615 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1616 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1617 | case Primitive::kPrimVoid: |
| 1618 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1619 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1624 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1625 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1626 | instruction, |
| 1627 | value_type == Primitive::kPrimNot ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 1628 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1629 | if (value_type == Primitive::kPrimNot) { |
| 1630 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1631 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1632 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1633 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1634 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1635 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 1636 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1637 | // 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] | 1638 | // In case of a byte operation, the register allocator does not support multiple |
| 1639 | // inputs that die at entry with one in a specific register. |
| 1640 | bool dies_at_entry = value_type != Primitive::kPrimLong && !is_byte_type; |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1641 | locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry); |
| 1642 | locations->SetInAt( |
| 1643 | 1, Location::RegisterOrConstant(instruction->InputAt(1)), dies_at_entry); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1644 | if (is_byte_type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1645 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1646 | locations->SetInAt(2, Location::ByteRegisterOrConstant( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1647 | EAX, instruction->InputAt(2)), dies_at_entry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1648 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1649 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2)), dies_at_entry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1650 | } |
| 1651 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 1655 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1656 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1657 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1658 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1659 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1660 | |
| 1661 | switch (value_type) { |
| 1662 | case Primitive::kPrimBoolean: |
| 1663 | case Primitive::kPrimByte: { |
| 1664 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1665 | if (index.IsConstant()) { |
| 1666 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1667 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1668 | __ movb(Address(obj, offset), value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1669 | } else { |
| 1670 | __ movb(Address(obj, offset), |
| 1671 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1672 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1673 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1674 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1675 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
| 1676 | value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1677 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1678 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1679 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1680 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1681 | } |
| 1682 | break; |
| 1683 | } |
| 1684 | |
| 1685 | case Primitive::kPrimShort: |
| 1686 | case Primitive::kPrimChar: { |
| 1687 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1688 | if (index.IsConstant()) { |
| 1689 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1690 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1691 | __ movw(Address(obj, offset), value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1692 | } else { |
| 1693 | __ movw(Address(obj, offset), |
| 1694 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1695 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1696 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1697 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1698 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
| 1699 | value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1700 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1701 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1702 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1703 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1704 | } |
| 1705 | break; |
| 1706 | } |
| 1707 | |
| 1708 | case Primitive::kPrimInt: { |
| 1709 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1710 | if (index.IsConstant()) { |
| 1711 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1712 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1713 | __ movl(Address(obj, offset), value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1714 | } else { |
| 1715 | __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1716 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1717 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1718 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1719 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
| 1720 | value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1721 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1722 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1723 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1724 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1725 | } |
| 1726 | break; |
| 1727 | } |
| 1728 | |
| 1729 | case Primitive::kPrimNot: { |
| 1730 | DCHECK(!codegen_->IsLeafMethod()); |
| 1731 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1732 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1733 | break; |
| 1734 | } |
| 1735 | |
| 1736 | case Primitive::kPrimLong: { |
| 1737 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1738 | if (index.IsConstant()) { |
| 1739 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1740 | if (value.IsRegisterPair()) { |
| 1741 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 1742 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1743 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1744 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1745 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 1746 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
| 1747 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 1748 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1749 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1750 | if (value.IsRegisterPair()) { |
| 1751 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
| 1752 | value.AsRegisterPairLow<Register>()); |
| 1753 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
| 1754 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1755 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1756 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1757 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1758 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1759 | Immediate(Low32Bits(val))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1760 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1761 | Immediate(High32Bits(val))); |
| 1762 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1763 | } |
| 1764 | break; |
| 1765 | } |
| 1766 | |
| 1767 | case Primitive::kPrimFloat: |
| 1768 | case Primitive::kPrimDouble: |
| 1769 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1770 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1771 | case Primitive::kPrimVoid: |
| 1772 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1773 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 1778 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1779 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1780 | locations->SetOut(Location::RequiresRegister()); |
| 1781 | instruction->SetLocations(locations); |
| 1782 | } |
| 1783 | |
| 1784 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 1785 | LocationSummary* locations = instruction->GetLocations(); |
| 1786 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1787 | Register obj = locations->InAt(0).As<Register>(); |
| 1788 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1789 | __ movl(out, Address(obj, offset)); |
| 1790 | } |
| 1791 | |
| 1792 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1793 | LocationSummary* locations = |
| 1794 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1795 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1796 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1797 | if (instruction->HasUses()) { |
| 1798 | locations->SetOut(Location::SameAsFirstInput()); |
| 1799 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1803 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1804 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1805 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1806 | codegen_->AddSlowPath(slow_path); |
| 1807 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1808 | Register index = locations->InAt(0).As<Register>(); |
| 1809 | Register length = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1810 | |
| 1811 | __ cmpl(index, length); |
| 1812 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 1813 | } |
| 1814 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1815 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 1816 | temp->SetLocations(nullptr); |
| 1817 | } |
| 1818 | |
| 1819 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 1820 | // Nothing to do, this is driven by the code generator. |
| 1821 | } |
| 1822 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1823 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1824 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1828 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 1829 | } |
| 1830 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1831 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1832 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 1833 | } |
| 1834 | |
| 1835 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1836 | HBasicBlock* block = instruction->GetBlock(); |
| 1837 | if (block->GetLoopInformation() != nullptr) { |
| 1838 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 1839 | // The back edge will generate the suspend check. |
| 1840 | return; |
| 1841 | } |
| 1842 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 1843 | // The goto will generate the suspend check. |
| 1844 | return; |
| 1845 | } |
| 1846 | GenerateSuspendCheck(instruction, nullptr); |
| 1847 | } |
| 1848 | |
| 1849 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1850 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1851 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1852 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1853 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1854 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1855 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1856 | if (successor == nullptr) { |
| 1857 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 1858 | __ Bind(slow_path->GetReturnLabel()); |
| 1859 | } else { |
| 1860 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 1861 | __ jmp(slow_path->GetEntryLabel()); |
| 1862 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1865 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 1866 | return codegen_->GetAssembler(); |
| 1867 | } |
| 1868 | |
| 1869 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) { |
| 1870 | ScratchRegisterScope ensure_scratch( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1871 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1872 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 1873 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset)); |
| 1874 | __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister())); |
| 1875 | } |
| 1876 | |
| 1877 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 1878 | MoveOperands* move = moves_.Get(index); |
| 1879 | Location source = move->GetSource(); |
| 1880 | Location destination = move->GetDestination(); |
| 1881 | |
| 1882 | if (source.IsRegister()) { |
| 1883 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1884 | __ movl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1885 | } else { |
| 1886 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1887 | __ movl(Address(ESP, destination.GetStackIndex()), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1888 | } |
| 1889 | } else if (source.IsStackSlot()) { |
| 1890 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1891 | __ movl(destination.As<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1892 | } else { |
| 1893 | DCHECK(destination.IsStackSlot()); |
| 1894 | MoveMemoryToMemory(destination.GetStackIndex(), |
| 1895 | source.GetStackIndex()); |
| 1896 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1897 | } else if (source.IsConstant()) { |
| 1898 | HIntConstant* instruction = source.GetConstant()->AsIntConstant(); |
| 1899 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 1900 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1901 | __ movl(destination.As<Register>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1902 | } else { |
| 1903 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 1904 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1905 | } else { |
| 1906 | LOG(FATAL) << "Unimplemented"; |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1911 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 1912 | ScratchRegisterScope ensure_scratch( |
| 1913 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 1914 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1915 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 1916 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 1917 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 1918 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| 1919 | } |
| 1920 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1921 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
| 1922 | ScratchRegisterScope ensure_scratch1( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1923 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 1924 | |
| 1925 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1926 | ScratchRegisterScope ensure_scratch2( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1927 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 1928 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1929 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 1930 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 1931 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 1932 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 1933 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 1934 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 1935 | } |
| 1936 | |
| 1937 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 1938 | MoveOperands* move = moves_.Get(index); |
| 1939 | Location source = move->GetSource(); |
| 1940 | Location destination = move->GetDestination(); |
| 1941 | |
| 1942 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1943 | __ xchgl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1944 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1945 | Exchange(source.As<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1946 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1947 | Exchange(destination.As<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1948 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 1949 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 1950 | } else { |
| 1951 | LOG(FATAL) << "Unimplemented"; |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 1956 | __ pushl(static_cast<Register>(reg)); |
| 1957 | } |
| 1958 | |
| 1959 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 1960 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1961 | } |
| 1962 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1963 | } // namespace x86 |
| 1964 | } // namespace art |