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