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