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()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame^] | 880 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 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 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1123 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1124 | memory_barrier->SetLocations(nullptr); |
| 1125 | } |
| 1126 | |
| 1127 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1128 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1129 | } |
| 1130 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1131 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1132 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1135 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1136 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1137 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1140 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1141 | LocationSummary* locations = |
| 1142 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1143 | switch (ret->InputAt(0)->GetType()) { |
| 1144 | case Primitive::kPrimBoolean: |
| 1145 | case Primitive::kPrimByte: |
| 1146 | case Primitive::kPrimChar: |
| 1147 | case Primitive::kPrimShort: |
| 1148 | case Primitive::kPrimInt: |
| 1149 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1150 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1151 | break; |
| 1152 | |
| 1153 | case Primitive::kPrimLong: |
| 1154 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1155 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1156 | break; |
| 1157 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1158 | case Primitive::kPrimFloat: |
| 1159 | case Primitive::kPrimDouble: |
| 1160 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1161 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1162 | break; |
| 1163 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1164 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1165 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1166 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1169 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1170 | if (kIsDebugBuild) { |
| 1171 | switch (ret->InputAt(0)->GetType()) { |
| 1172 | case Primitive::kPrimBoolean: |
| 1173 | case Primitive::kPrimByte: |
| 1174 | case Primitive::kPrimChar: |
| 1175 | case Primitive::kPrimShort: |
| 1176 | case Primitive::kPrimInt: |
| 1177 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1178 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1179 | break; |
| 1180 | |
| 1181 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1182 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1183 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1184 | break; |
| 1185 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1186 | case Primitive::kPrimFloat: |
| 1187 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1188 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1189 | break; |
| 1190 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1191 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1192 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1193 | } |
| 1194 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1195 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1198 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1199 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1200 | if (intrinsic.TryDispatch(invoke)) { |
| 1201 | return; |
| 1202 | } |
| 1203 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1204 | HandleInvoke(invoke); |
| 1205 | } |
| 1206 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1207 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1208 | if (invoke->GetLocations()->Intrinsified()) { |
| 1209 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1210 | intrinsic.Dispatch(invoke); |
| 1211 | return true; |
| 1212 | } |
| 1213 | return false; |
| 1214 | } |
| 1215 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1216 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1217 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1218 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1219 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1220 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1221 | codegen_->GenerateStaticOrDirectCall( |
| 1222 | invoke, invoke->GetLocations()->GetTemp(0).AsRegister<Register>()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1223 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1227 | HandleInvoke(invoke); |
| 1228 | } |
| 1229 | |
| 1230 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1231 | LocationSummary* locations = |
| 1232 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1233 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1234 | |
| 1235 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1236 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1237 | HInstruction* input = invoke->InputAt(i); |
| 1238 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1239 | } |
| 1240 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1241 | switch (invoke->GetType()) { |
| 1242 | case Primitive::kPrimBoolean: |
| 1243 | case Primitive::kPrimByte: |
| 1244 | case Primitive::kPrimChar: |
| 1245 | case Primitive::kPrimShort: |
| 1246 | case Primitive::kPrimInt: |
| 1247 | case Primitive::kPrimNot: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1248 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1249 | break; |
| 1250 | |
| 1251 | case Primitive::kPrimLong: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1252 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1253 | break; |
| 1254 | |
| 1255 | case Primitive::kPrimVoid: |
| 1256 | break; |
| 1257 | |
| 1258 | case Primitive::kPrimDouble: |
| 1259 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1260 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1261 | break; |
| 1262 | } |
| 1263 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1264 | invoke->SetLocations(locations); |
| 1265 | } |
| 1266 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1267 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1268 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1269 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 1270 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1271 | LocationSummary* locations = invoke->GetLocations(); |
| 1272 | Location receiver = locations->InAt(0); |
| 1273 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1274 | // temp = object->GetClass(); |
| 1275 | if (receiver.IsStackSlot()) { |
| 1276 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1277 | __ movl(temp, Address(temp, class_offset)); |
| 1278 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1279 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1280 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1281 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1282 | // temp = temp->GetMethodAt(method_offset); |
| 1283 | __ movl(temp, Address(temp, method_offset)); |
| 1284 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1285 | __ call(Address( |
| 1286 | temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1287 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1288 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1289 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1292 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1293 | HandleInvoke(invoke); |
| 1294 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1295 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1299 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1300 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1301 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1302 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1303 | LocationSummary* locations = invoke->GetLocations(); |
| 1304 | Location receiver = locations->InAt(0); |
| 1305 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1306 | |
| 1307 | // Set the hidden argument. |
| 1308 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1309 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1310 | |
| 1311 | // temp = object->GetClass(); |
| 1312 | if (receiver.IsStackSlot()) { |
| 1313 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1314 | __ movl(temp, Address(temp, class_offset)); |
| 1315 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1316 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1317 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1318 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1319 | // temp = temp->GetImtEntryAt(method_offset); |
| 1320 | __ movl(temp, Address(temp, method_offset)); |
| 1321 | // call temp->GetEntryPoint(); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1322 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1323 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1324 | |
| 1325 | DCHECK(!codegen_->IsLeafMethod()); |
| 1326 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1327 | } |
| 1328 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1329 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1330 | LocationSummary* locations = |
| 1331 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1332 | switch (neg->GetResultType()) { |
| 1333 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1334 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1335 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1336 | locations->SetOut(Location::SameAsFirstInput()); |
| 1337 | break; |
| 1338 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1339 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1340 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1341 | locations->SetOut(Location::SameAsFirstInput()); |
| 1342 | locations->AddTemp(Location::RequiresRegister()); |
| 1343 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1344 | break; |
| 1345 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1346 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1347 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1348 | locations->SetOut(Location::SameAsFirstInput()); |
| 1349 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1350 | break; |
| 1351 | |
| 1352 | default: |
| 1353 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1358 | LocationSummary* locations = neg->GetLocations(); |
| 1359 | Location out = locations->Out(); |
| 1360 | Location in = locations->InAt(0); |
| 1361 | switch (neg->GetResultType()) { |
| 1362 | case Primitive::kPrimInt: |
| 1363 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1364 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1365 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1366 | break; |
| 1367 | |
| 1368 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1369 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1370 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1371 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1372 | // Negation is similar to subtraction from zero. The least |
| 1373 | // significant byte triggers a borrow when it is different from |
| 1374 | // zero; to take it into account, add 1 to the most significant |
| 1375 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1376 | // operation. |
| 1377 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1378 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1379 | break; |
| 1380 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1381 | case Primitive::kPrimFloat: { |
| 1382 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1383 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1384 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1385 | // Implement float negation with an exclusive or with value |
| 1386 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1387 | // single-precision floating-point number). |
| 1388 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1389 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1390 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1391 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1392 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1393 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1394 | case Primitive::kPrimDouble: { |
| 1395 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1396 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1397 | // Implement double negation with an exclusive or with value |
| 1398 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1399 | // a double-precision floating-point number). |
| 1400 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1401 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1402 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1403 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1404 | |
| 1405 | default: |
| 1406 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1407 | } |
| 1408 | } |
| 1409 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1410 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1411 | Primitive::Type result_type = conversion->GetResultType(); |
| 1412 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1413 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1414 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1415 | // The float-to-long and double-to-long type conversions rely on a |
| 1416 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1417 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1418 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1419 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1420 | ? LocationSummary::kCall |
| 1421 | : LocationSummary::kNoCall; |
| 1422 | LocationSummary* locations = |
| 1423 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1424 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1425 | // The Java language does not allow treating boolean as an integral type but |
| 1426 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1427 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1428 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1429 | case Primitive::kPrimByte: |
| 1430 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1431 | case Primitive::kPrimBoolean: |
| 1432 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1433 | case Primitive::kPrimShort: |
| 1434 | case Primitive::kPrimInt: |
| 1435 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1436 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1437 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1438 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1439 | // the validation of the linear scan implementation |
| 1440 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1441 | break; |
| 1442 | |
| 1443 | default: |
| 1444 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1445 | << " to " << result_type; |
| 1446 | } |
| 1447 | break; |
| 1448 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1449 | case Primitive::kPrimShort: |
| 1450 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1451 | case Primitive::kPrimBoolean: |
| 1452 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1453 | case Primitive::kPrimByte: |
| 1454 | case Primitive::kPrimInt: |
| 1455 | case Primitive::kPrimChar: |
| 1456 | // Processing a Dex `int-to-short' instruction. |
| 1457 | locations->SetInAt(0, Location::Any()); |
| 1458 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1459 | break; |
| 1460 | |
| 1461 | default: |
| 1462 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1463 | << " to " << result_type; |
| 1464 | } |
| 1465 | break; |
| 1466 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1467 | case Primitive::kPrimInt: |
| 1468 | switch (input_type) { |
| 1469 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1470 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1471 | locations->SetInAt(0, Location::Any()); |
| 1472 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1473 | break; |
| 1474 | |
| 1475 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1476 | // Processing a Dex `float-to-int' instruction. |
| 1477 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1478 | locations->SetOut(Location::RequiresRegister()); |
| 1479 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1480 | break; |
| 1481 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1482 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1483 | // Processing a Dex `double-to-int' instruction. |
| 1484 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1485 | locations->SetOut(Location::RequiresRegister()); |
| 1486 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1487 | break; |
| 1488 | |
| 1489 | default: |
| 1490 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1491 | << " to " << result_type; |
| 1492 | } |
| 1493 | break; |
| 1494 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1495 | case Primitive::kPrimLong: |
| 1496 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1497 | case Primitive::kPrimBoolean: |
| 1498 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1499 | case Primitive::kPrimByte: |
| 1500 | case Primitive::kPrimShort: |
| 1501 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1502 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1503 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1504 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1505 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1506 | break; |
| 1507 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1508 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1509 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1510 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1511 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1512 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1513 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1514 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1515 | // The runtime helper puts the result in EAX, EDX. |
| 1516 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1517 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1518 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1519 | |
| 1520 | default: |
| 1521 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1522 | << " to " << result_type; |
| 1523 | } |
| 1524 | break; |
| 1525 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1526 | case Primitive::kPrimChar: |
| 1527 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1528 | case Primitive::kPrimBoolean: |
| 1529 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1530 | case Primitive::kPrimByte: |
| 1531 | case Primitive::kPrimShort: |
| 1532 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1533 | // Processing a Dex `int-to-char' instruction. |
| 1534 | locations->SetInAt(0, Location::Any()); |
| 1535 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1536 | break; |
| 1537 | |
| 1538 | default: |
| 1539 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1540 | << " to " << result_type; |
| 1541 | } |
| 1542 | break; |
| 1543 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1544 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1545 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1546 | case Primitive::kPrimBoolean: |
| 1547 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1548 | case Primitive::kPrimByte: |
| 1549 | case Primitive::kPrimShort: |
| 1550 | case Primitive::kPrimInt: |
| 1551 | case Primitive::kPrimChar: |
| 1552 | // Processing a Dex `int-to-float' instruction. |
| 1553 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1554 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1555 | break; |
| 1556 | |
| 1557 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1558 | // Processing a Dex `long-to-float' instruction. |
| 1559 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1560 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1561 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1562 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1563 | break; |
| 1564 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1565 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1566 | // Processing a Dex `double-to-float' instruction. |
| 1567 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1568 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1569 | break; |
| 1570 | |
| 1571 | default: |
| 1572 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1573 | << " to " << result_type; |
| 1574 | }; |
| 1575 | break; |
| 1576 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1577 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1578 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1579 | case Primitive::kPrimBoolean: |
| 1580 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1581 | case Primitive::kPrimByte: |
| 1582 | case Primitive::kPrimShort: |
| 1583 | case Primitive::kPrimInt: |
| 1584 | case Primitive::kPrimChar: |
| 1585 | // Processing a Dex `int-to-double' instruction. |
| 1586 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1587 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1588 | break; |
| 1589 | |
| 1590 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1591 | // Processing a Dex `long-to-double' instruction. |
| 1592 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1593 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1594 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1595 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1596 | break; |
| 1597 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1598 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1599 | // Processing a Dex `float-to-double' instruction. |
| 1600 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1601 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1602 | break; |
| 1603 | |
| 1604 | default: |
| 1605 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1606 | << " to " << result_type; |
| 1607 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1608 | break; |
| 1609 | |
| 1610 | default: |
| 1611 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1612 | << " to " << result_type; |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1617 | LocationSummary* locations = conversion->GetLocations(); |
| 1618 | Location out = locations->Out(); |
| 1619 | Location in = locations->InAt(0); |
| 1620 | Primitive::Type result_type = conversion->GetResultType(); |
| 1621 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1622 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1623 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1624 | case Primitive::kPrimByte: |
| 1625 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1626 | case Primitive::kPrimBoolean: |
| 1627 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1628 | case Primitive::kPrimShort: |
| 1629 | case Primitive::kPrimInt: |
| 1630 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1631 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1632 | if (in.IsRegister()) { |
| 1633 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1634 | } else { |
| 1635 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1636 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1637 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 1638 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1639 | break; |
| 1640 | |
| 1641 | default: |
| 1642 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1643 | << " to " << result_type; |
| 1644 | } |
| 1645 | break; |
| 1646 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1647 | case Primitive::kPrimShort: |
| 1648 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1649 | case Primitive::kPrimBoolean: |
| 1650 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1651 | case Primitive::kPrimByte: |
| 1652 | case Primitive::kPrimInt: |
| 1653 | case Primitive::kPrimChar: |
| 1654 | // Processing a Dex `int-to-short' instruction. |
| 1655 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1656 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1657 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1658 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1659 | } else { |
| 1660 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1661 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1662 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1663 | } |
| 1664 | break; |
| 1665 | |
| 1666 | default: |
| 1667 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1668 | << " to " << result_type; |
| 1669 | } |
| 1670 | break; |
| 1671 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1672 | case Primitive::kPrimInt: |
| 1673 | switch (input_type) { |
| 1674 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1675 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1676 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1677 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1678 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1679 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1680 | } else { |
| 1681 | DCHECK(in.IsConstant()); |
| 1682 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1683 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1684 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1685 | } |
| 1686 | break; |
| 1687 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1688 | case Primitive::kPrimFloat: { |
| 1689 | // Processing a Dex `float-to-int' instruction. |
| 1690 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1691 | Register output = out.AsRegister<Register>(); |
| 1692 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1693 | Label done, nan; |
| 1694 | |
| 1695 | __ movl(output, Immediate(kPrimIntMax)); |
| 1696 | // temp = int-to-float(output) |
| 1697 | __ cvtsi2ss(temp, output); |
| 1698 | // if input >= temp goto done |
| 1699 | __ comiss(input, temp); |
| 1700 | __ j(kAboveEqual, &done); |
| 1701 | // if input == NaN goto nan |
| 1702 | __ j(kUnordered, &nan); |
| 1703 | // output = float-to-int-truncate(input) |
| 1704 | __ cvttss2si(output, input); |
| 1705 | __ jmp(&done); |
| 1706 | __ Bind(&nan); |
| 1707 | // output = 0 |
| 1708 | __ xorl(output, output); |
| 1709 | __ Bind(&done); |
| 1710 | break; |
| 1711 | } |
| 1712 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1713 | case Primitive::kPrimDouble: { |
| 1714 | // Processing a Dex `double-to-int' instruction. |
| 1715 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1716 | Register output = out.AsRegister<Register>(); |
| 1717 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1718 | Label done, nan; |
| 1719 | |
| 1720 | __ movl(output, Immediate(kPrimIntMax)); |
| 1721 | // temp = int-to-double(output) |
| 1722 | __ cvtsi2sd(temp, output); |
| 1723 | // if input >= temp goto done |
| 1724 | __ comisd(input, temp); |
| 1725 | __ j(kAboveEqual, &done); |
| 1726 | // if input == NaN goto nan |
| 1727 | __ j(kUnordered, &nan); |
| 1728 | // output = double-to-int-truncate(input) |
| 1729 | __ cvttsd2si(output, input); |
| 1730 | __ jmp(&done); |
| 1731 | __ Bind(&nan); |
| 1732 | // output = 0 |
| 1733 | __ xorl(output, output); |
| 1734 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1735 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1736 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1737 | |
| 1738 | default: |
| 1739 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1740 | << " to " << result_type; |
| 1741 | } |
| 1742 | break; |
| 1743 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1744 | case Primitive::kPrimLong: |
| 1745 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1746 | case Primitive::kPrimBoolean: |
| 1747 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1748 | case Primitive::kPrimByte: |
| 1749 | case Primitive::kPrimShort: |
| 1750 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1751 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1752 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1753 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 1754 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1755 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1756 | __ cdq(); |
| 1757 | break; |
| 1758 | |
| 1759 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1760 | // Processing a Dex `float-to-long' instruction. |
| 1761 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pF2l))); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1762 | codegen_->RecordPcInfo(conversion, conversion->GetDexPc()); |
| 1763 | break; |
| 1764 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1765 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1766 | // Processing a Dex `double-to-long' instruction. |
| 1767 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pD2l))); |
| 1768 | codegen_->RecordPcInfo(conversion, conversion->GetDexPc()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1769 | break; |
| 1770 | |
| 1771 | default: |
| 1772 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1773 | << " to " << result_type; |
| 1774 | } |
| 1775 | break; |
| 1776 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1777 | case Primitive::kPrimChar: |
| 1778 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1779 | case Primitive::kPrimBoolean: |
| 1780 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1781 | case Primitive::kPrimByte: |
| 1782 | case Primitive::kPrimShort: |
| 1783 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1784 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 1785 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1786 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1787 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1788 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1789 | } else { |
| 1790 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1791 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1792 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1793 | } |
| 1794 | break; |
| 1795 | |
| 1796 | default: |
| 1797 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1798 | << " to " << result_type; |
| 1799 | } |
| 1800 | break; |
| 1801 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1802 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1803 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1804 | case Primitive::kPrimBoolean: |
| 1805 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1806 | case Primitive::kPrimByte: |
| 1807 | case Primitive::kPrimShort: |
| 1808 | case Primitive::kPrimInt: |
| 1809 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1810 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1811 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1814 | case Primitive::kPrimLong: { |
| 1815 | // Processing a Dex `long-to-float' instruction. |
| 1816 | Register low = in.AsRegisterPairLow<Register>(); |
| 1817 | Register high = in.AsRegisterPairHigh<Register>(); |
| 1818 | XmmRegister result = out.AsFpuRegister<XmmRegister>(); |
| 1819 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1820 | XmmRegister constant = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 1821 | |
| 1822 | // Operations use doubles for precision reasons (each 32-bit |
| 1823 | // half of a long fits in the 53-bit mantissa of a double, |
| 1824 | // but not in the 24-bit mantissa of a float). This is |
| 1825 | // especially important for the low bits. The result is |
| 1826 | // eventually converted to float. |
| 1827 | |
| 1828 | // low = low - 2^31 (to prevent bit 31 of `low` to be |
| 1829 | // interpreted as a sign bit) |
| 1830 | __ subl(low, Immediate(0x80000000)); |
| 1831 | // temp = int-to-double(high) |
| 1832 | __ cvtsi2sd(temp, high); |
| 1833 | // temp = temp * 2^32 |
| 1834 | __ LoadLongConstant(constant, k2Pow32EncodingForDouble); |
| 1835 | __ mulsd(temp, constant); |
| 1836 | // result = int-to-double(low) |
| 1837 | __ cvtsi2sd(result, low); |
| 1838 | // result = result + 2^31 (restore the original value of `low`) |
| 1839 | __ LoadLongConstant(constant, k2Pow31EncodingForDouble); |
| 1840 | __ addsd(result, constant); |
| 1841 | // result = result + temp |
| 1842 | __ addsd(result, temp); |
| 1843 | // result = double-to-float(result) |
| 1844 | __ cvtsd2ss(result, result); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1845 | // Restore low. |
| 1846 | __ addl(low, Immediate(0x80000000)); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1847 | break; |
| 1848 | } |
| 1849 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1850 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1851 | // Processing a Dex `double-to-float' instruction. |
| 1852 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1853 | break; |
| 1854 | |
| 1855 | default: |
| 1856 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1857 | << " to " << result_type; |
| 1858 | }; |
| 1859 | break; |
| 1860 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1861 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1862 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1863 | case Primitive::kPrimBoolean: |
| 1864 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1865 | case Primitive::kPrimByte: |
| 1866 | case Primitive::kPrimShort: |
| 1867 | case Primitive::kPrimInt: |
| 1868 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1869 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1870 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1871 | break; |
| 1872 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1873 | case Primitive::kPrimLong: { |
| 1874 | // Processing a Dex `long-to-double' instruction. |
| 1875 | Register low = in.AsRegisterPairLow<Register>(); |
| 1876 | Register high = in.AsRegisterPairHigh<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1877 | XmmRegister result = out.AsFpuRegister<XmmRegister>(); |
| 1878 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1879 | XmmRegister constant = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1880 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1881 | // low = low - 2^31 (to prevent bit 31 of `low` to be |
| 1882 | // interpreted as a sign bit) |
| 1883 | __ subl(low, Immediate(0x80000000)); |
| 1884 | // temp = int-to-double(high) |
| 1885 | __ cvtsi2sd(temp, high); |
| 1886 | // temp = temp * 2^32 |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1887 | __ LoadLongConstant(constant, k2Pow32EncodingForDouble); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1888 | __ mulsd(temp, constant); |
| 1889 | // result = int-to-double(low) |
| 1890 | __ cvtsi2sd(result, low); |
| 1891 | // result = result + 2^31 (restore the original value of `low`) |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1892 | __ LoadLongConstant(constant, k2Pow31EncodingForDouble); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1893 | __ addsd(result, constant); |
| 1894 | // result = result + temp |
| 1895 | __ addsd(result, temp); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1896 | // Restore low. |
| 1897 | __ addl(low, Immediate(0x80000000)); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1898 | break; |
| 1899 | } |
| 1900 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1901 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1902 | // Processing a Dex `float-to-double' instruction. |
| 1903 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1904 | break; |
| 1905 | |
| 1906 | default: |
| 1907 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1908 | << " to " << result_type; |
| 1909 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1910 | break; |
| 1911 | |
| 1912 | default: |
| 1913 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1914 | << " to " << result_type; |
| 1915 | } |
| 1916 | } |
| 1917 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1918 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1919 | LocationSummary* locations = |
| 1920 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1921 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1922 | case Primitive::kPrimInt: { |
| 1923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1924 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 1925 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1926 | break; |
| 1927 | } |
| 1928 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1929 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1930 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1931 | locations->SetInAt(1, Location::Any()); |
| 1932 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1933 | break; |
| 1934 | } |
| 1935 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1936 | case Primitive::kPrimFloat: |
| 1937 | case Primitive::kPrimDouble: { |
| 1938 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Calin Juravle | 3173c8a | 2015-02-23 15:53:39 +0000 | [diff] [blame] | 1939 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1940 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1941 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1942 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1943 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1944 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1945 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 1946 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1947 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 1951 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1952 | Location first = locations->InAt(0); |
| 1953 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1954 | Location out = locations->Out(); |
| 1955 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1956 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1957 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1958 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1959 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 1960 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
| 1961 | } else { |
| 1962 | __ leal(out.AsRegister<Register>(), Address( |
| 1963 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 1964 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1965 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1966 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 1967 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 1968 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 1969 | } else { |
| 1970 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 1971 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1972 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1973 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1974 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1975 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1976 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1980 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1981 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1982 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1983 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1984 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 1985 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1986 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1987 | } else { |
| 1988 | DCHECK(second.IsConstant()) << second; |
| 1989 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 1990 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 1991 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1992 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1993 | break; |
| 1994 | } |
| 1995 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1996 | case Primitive::kPrimFloat: { |
| 1997 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1998 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1999 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2000 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | case Primitive::kPrimDouble: { |
| 2004 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2005 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2006 | } |
| 2007 | break; |
| 2008 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2009 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2010 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2011 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2015 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2016 | LocationSummary* locations = |
| 2017 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2018 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2019 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2020 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2021 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2022 | locations->SetInAt(1, Location::Any()); |
| 2023 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2024 | break; |
| 2025 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2026 | case Primitive::kPrimFloat: |
| 2027 | case Primitive::kPrimDouble: { |
| 2028 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2029 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2030 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2031 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2032 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2033 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2034 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2035 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2036 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2040 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2041 | Location first = locations->InAt(0); |
| 2042 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2043 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2044 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2045 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2046 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2047 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2048 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2049 | __ subl(first.AsRegister<Register>(), |
| 2050 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2051 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2052 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2053 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2054 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2058 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2059 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2060 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2061 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2062 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2063 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2064 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2065 | } else { |
| 2066 | DCHECK(second.IsConstant()) << second; |
| 2067 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2068 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2069 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2070 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2071 | break; |
| 2072 | } |
| 2073 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2074 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2075 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2076 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2080 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2081 | break; |
| 2082 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2083 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2084 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2085 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2086 | } |
| 2087 | } |
| 2088 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2089 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2090 | LocationSummary* locations = |
| 2091 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2092 | switch (mul->GetResultType()) { |
| 2093 | case Primitive::kPrimInt: |
| 2094 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2095 | locations->SetInAt(1, Location::Any()); |
| 2096 | locations->SetOut(Location::SameAsFirstInput()); |
| 2097 | break; |
| 2098 | case Primitive::kPrimLong: { |
| 2099 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2100 | locations->SetInAt(1, Location::Any()); |
| 2101 | locations->SetOut(Location::SameAsFirstInput()); |
| 2102 | // Needed for imul on 32bits with 64bits output. |
| 2103 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2104 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2105 | break; |
| 2106 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2107 | case Primitive::kPrimFloat: |
| 2108 | case Primitive::kPrimDouble: { |
| 2109 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2110 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2111 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2112 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2113 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2114 | |
| 2115 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2116 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2121 | LocationSummary* locations = mul->GetLocations(); |
| 2122 | Location first = locations->InAt(0); |
| 2123 | Location second = locations->InAt(1); |
| 2124 | DCHECK(first.Equals(locations->Out())); |
| 2125 | |
| 2126 | switch (mul->GetResultType()) { |
| 2127 | case Primitive::kPrimInt: { |
| 2128 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2129 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2130 | } else if (second.IsConstant()) { |
| 2131 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2132 | __ imull(first.AsRegister<Register>(), imm); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2133 | } else { |
| 2134 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2135 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2136 | } |
| 2137 | break; |
| 2138 | } |
| 2139 | |
| 2140 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2141 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2142 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2143 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2144 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2145 | |
| 2146 | DCHECK_EQ(EAX, eax); |
| 2147 | DCHECK_EQ(EDX, edx); |
| 2148 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2149 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2150 | // output: in1 |
| 2151 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2152 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2153 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2154 | if (second.IsConstant()) { |
| 2155 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2156 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2157 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2158 | int32_t low_value = Low32Bits(value); |
| 2159 | int32_t high_value = High32Bits(value); |
| 2160 | Immediate low(low_value); |
| 2161 | Immediate high(high_value); |
| 2162 | |
| 2163 | __ movl(eax, high); |
| 2164 | // eax <- in1.lo * in2.hi |
| 2165 | __ imull(eax, in1_lo); |
| 2166 | // in1.hi <- in1.hi * in2.lo |
| 2167 | __ imull(in1_hi, low); |
| 2168 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2169 | __ addl(in1_hi, eax); |
| 2170 | // move in2_lo to eax to prepare for double precision |
| 2171 | __ movl(eax, low); |
| 2172 | // edx:eax <- in1.lo * in2.lo |
| 2173 | __ mull(in1_lo); |
| 2174 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2175 | __ addl(in1_hi, edx); |
| 2176 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2177 | __ movl(in1_lo, eax); |
| 2178 | } else if (second.IsRegisterPair()) { |
| 2179 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2180 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2181 | |
| 2182 | __ movl(eax, in2_hi); |
| 2183 | // eax <- in1.lo * in2.hi |
| 2184 | __ imull(eax, in1_lo); |
| 2185 | // in1.hi <- in1.hi * in2.lo |
| 2186 | __ imull(in1_hi, in2_lo); |
| 2187 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2188 | __ addl(in1_hi, eax); |
| 2189 | // move in1_lo to eax to prepare for double precision |
| 2190 | __ movl(eax, in1_lo); |
| 2191 | // edx:eax <- in1.lo * in2.lo |
| 2192 | __ mull(in2_lo); |
| 2193 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2194 | __ addl(in1_hi, edx); |
| 2195 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2196 | __ movl(in1_lo, eax); |
| 2197 | } else { |
| 2198 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2199 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2200 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2201 | |
| 2202 | __ movl(eax, in2_hi); |
| 2203 | // eax <- in1.lo * in2.hi |
| 2204 | __ imull(eax, in1_lo); |
| 2205 | // in1.hi <- in1.hi * in2.lo |
| 2206 | __ imull(in1_hi, in2_lo); |
| 2207 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2208 | __ addl(in1_hi, eax); |
| 2209 | // move in1_lo to eax to prepare for double precision |
| 2210 | __ movl(eax, in1_lo); |
| 2211 | // edx:eax <- in1.lo * in2.lo |
| 2212 | __ mull(in2_lo); |
| 2213 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2214 | __ addl(in1_hi, edx); |
| 2215 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2216 | __ movl(in1_lo, eax); |
| 2217 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2218 | |
| 2219 | break; |
| 2220 | } |
| 2221 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2222 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2223 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2224 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2228 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2229 | break; |
| 2230 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2231 | |
| 2232 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2233 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2234 | } |
| 2235 | } |
| 2236 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2237 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2238 | uint32_t stack_adjustment, bool is_float) { |
| 2239 | if (source.IsStackSlot()) { |
| 2240 | DCHECK(is_float); |
| 2241 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2242 | } else if (source.IsDoubleStackSlot()) { |
| 2243 | DCHECK(!is_float); |
| 2244 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2245 | } else { |
| 2246 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2247 | if (is_float) { |
| 2248 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2249 | codegen_->Move32(stack_temp, source); |
| 2250 | __ flds(Address(ESP, temp_offset)); |
| 2251 | } else { |
| 2252 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2253 | codegen_->Move64(stack_temp, source); |
| 2254 | __ fldl(Address(ESP, temp_offset)); |
| 2255 | } |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2260 | Primitive::Type type = rem->GetResultType(); |
| 2261 | bool is_float = type == Primitive::kPrimFloat; |
| 2262 | size_t elem_size = Primitive::ComponentSize(type); |
| 2263 | LocationSummary* locations = rem->GetLocations(); |
| 2264 | Location first = locations->InAt(0); |
| 2265 | Location second = locations->InAt(1); |
| 2266 | Location out = locations->Out(); |
| 2267 | |
| 2268 | // Create stack space for 2 elements. |
| 2269 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2270 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2271 | |
| 2272 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2273 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2274 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2275 | |
| 2276 | // Loop doing FPREM until we stabilize. |
| 2277 | Label retry; |
| 2278 | __ Bind(&retry); |
| 2279 | __ fprem(); |
| 2280 | |
| 2281 | // Move FP status to AX. |
| 2282 | __ fstsw(); |
| 2283 | |
| 2284 | // And see if the argument reduction is complete. This is signaled by the |
| 2285 | // C2 FPU flag bit set to 0. |
| 2286 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2287 | __ j(kNotEqual, &retry); |
| 2288 | |
| 2289 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2290 | // Store FP top of stack to real stack. |
| 2291 | if (is_float) { |
| 2292 | __ fsts(Address(ESP, 0)); |
| 2293 | } else { |
| 2294 | __ fstl(Address(ESP, 0)); |
| 2295 | } |
| 2296 | |
| 2297 | // Pop the 2 items from the FP stack. |
| 2298 | __ fucompp(); |
| 2299 | |
| 2300 | // Load the value from the stack into an XMM register. |
| 2301 | DCHECK(out.IsFpuRegister()) << out; |
| 2302 | if (is_float) { |
| 2303 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2304 | } else { |
| 2305 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2306 | } |
| 2307 | |
| 2308 | // And remove the temporary stack space we allocated. |
| 2309 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2310 | } |
| 2311 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2312 | |
| 2313 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2314 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2315 | |
| 2316 | LocationSummary* locations = instruction->GetLocations(); |
| 2317 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2318 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2319 | |
| 2320 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2321 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2322 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2323 | |
| 2324 | DCHECK(imm == 1 || imm == -1); |
| 2325 | |
| 2326 | if (instruction->IsRem()) { |
| 2327 | __ xorl(out_register, out_register); |
| 2328 | } else { |
| 2329 | __ movl(out_register, input_register); |
| 2330 | if (imm == -1) { |
| 2331 | __ negl(out_register); |
| 2332 | } |
| 2333 | } |
| 2334 | } |
| 2335 | |
| 2336 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2337 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2338 | LocationSummary* locations = instruction->GetLocations(); |
| 2339 | |
| 2340 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2341 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2342 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2343 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2344 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2345 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2346 | |
| 2347 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2348 | __ testl(input_register, input_register); |
| 2349 | __ cmovl(kGreaterEqual, num, input_register); |
| 2350 | int shift = CTZ(imm); |
| 2351 | __ sarl(num, Immediate(shift)); |
| 2352 | |
| 2353 | if (imm < 0) { |
| 2354 | __ negl(num); |
| 2355 | } |
| 2356 | |
| 2357 | __ movl(out_register, num); |
| 2358 | } |
| 2359 | |
| 2360 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2361 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2362 | |
| 2363 | LocationSummary* locations = instruction->GetLocations(); |
| 2364 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2365 | |
| 2366 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2367 | Register out = locations->Out().AsRegister<Register>(); |
| 2368 | Register num; |
| 2369 | Register edx; |
| 2370 | |
| 2371 | if (instruction->IsDiv()) { |
| 2372 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2373 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2374 | } else { |
| 2375 | edx = locations->Out().AsRegister<Register>(); |
| 2376 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2377 | } |
| 2378 | |
| 2379 | DCHECK_EQ(EAX, eax); |
| 2380 | DCHECK_EQ(EDX, edx); |
| 2381 | if (instruction->IsDiv()) { |
| 2382 | DCHECK_EQ(EAX, out); |
| 2383 | } else { |
| 2384 | DCHECK_EQ(EDX, out); |
| 2385 | } |
| 2386 | |
| 2387 | int64_t magic; |
| 2388 | int shift; |
| 2389 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2390 | |
| 2391 | Label ndiv; |
| 2392 | Label end; |
| 2393 | // If numerator is 0, the result is 0, no computation needed. |
| 2394 | __ testl(eax, eax); |
| 2395 | __ j(kNotEqual, &ndiv); |
| 2396 | |
| 2397 | __ xorl(out, out); |
| 2398 | __ jmp(&end); |
| 2399 | |
| 2400 | __ Bind(&ndiv); |
| 2401 | |
| 2402 | // Save the numerator. |
| 2403 | __ movl(num, eax); |
| 2404 | |
| 2405 | // EAX = magic |
| 2406 | __ movl(eax, Immediate(magic)); |
| 2407 | |
| 2408 | // EDX:EAX = magic * numerator |
| 2409 | __ imull(num); |
| 2410 | |
| 2411 | if (imm > 0 && magic < 0) { |
| 2412 | // EDX += num |
| 2413 | __ addl(edx, num); |
| 2414 | } else if (imm < 0 && magic > 0) { |
| 2415 | __ subl(edx, num); |
| 2416 | } |
| 2417 | |
| 2418 | // Shift if needed. |
| 2419 | if (shift != 0) { |
| 2420 | __ sarl(edx, Immediate(shift)); |
| 2421 | } |
| 2422 | |
| 2423 | // EDX += 1 if EDX < 0 |
| 2424 | __ movl(eax, edx); |
| 2425 | __ shrl(edx, Immediate(31)); |
| 2426 | __ addl(edx, eax); |
| 2427 | |
| 2428 | if (instruction->IsRem()) { |
| 2429 | __ movl(eax, num); |
| 2430 | __ imull(edx, Immediate(imm)); |
| 2431 | __ subl(eax, edx); |
| 2432 | __ movl(edx, eax); |
| 2433 | } else { |
| 2434 | __ movl(eax, edx); |
| 2435 | } |
| 2436 | __ Bind(&end); |
| 2437 | } |
| 2438 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2439 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2440 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2441 | |
| 2442 | LocationSummary* locations = instruction->GetLocations(); |
| 2443 | Location out = locations->Out(); |
| 2444 | Location first = locations->InAt(0); |
| 2445 | Location second = locations->InAt(1); |
| 2446 | bool is_div = instruction->IsDiv(); |
| 2447 | |
| 2448 | switch (instruction->GetResultType()) { |
| 2449 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2450 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2451 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2452 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2453 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2454 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2455 | |
| 2456 | if (imm == 0) { |
| 2457 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2458 | } else if (imm == 1 || imm == -1) { |
| 2459 | DivRemOneOrMinusOne(instruction); |
| 2460 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2461 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2462 | } else { |
| 2463 | DCHECK(imm <= -2 || imm >= 2); |
| 2464 | GenerateDivRemWithAnyConstant(instruction); |
| 2465 | } |
| 2466 | } else { |
| 2467 | SlowPathCodeX86* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2468 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2469 | is_div); |
| 2470 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2471 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2472 | Register second_reg = second.AsRegister<Register>(); |
| 2473 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2474 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2475 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2476 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2477 | __ cmpl(second_reg, Immediate(-1)); |
| 2478 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2479 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2480 | // edx:eax <- sign-extended of eax |
| 2481 | __ cdq(); |
| 2482 | // eax = quotient, edx = remainder |
| 2483 | __ idivl(second_reg); |
| 2484 | __ Bind(slow_path->GetExitLabel()); |
| 2485 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2486 | break; |
| 2487 | } |
| 2488 | |
| 2489 | case Primitive::kPrimLong: { |
| 2490 | InvokeRuntimeCallingConvention calling_convention; |
| 2491 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2492 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2493 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2494 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2495 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2496 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2497 | |
| 2498 | if (is_div) { |
| 2499 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLdiv))); |
| 2500 | } else { |
| 2501 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLmod))); |
| 2502 | } |
| 2503 | uint32_t dex_pc = is_div |
| 2504 | ? instruction->AsDiv()->GetDexPc() |
| 2505 | : instruction->AsRem()->GetDexPc(); |
| 2506 | codegen_->RecordPcInfo(instruction, dex_pc); |
| 2507 | |
| 2508 | break; |
| 2509 | } |
| 2510 | |
| 2511 | default: |
| 2512 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 2513 | } |
| 2514 | } |
| 2515 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2516 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2517 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2518 | ? LocationSummary::kCall |
| 2519 | : LocationSummary::kNoCall; |
| 2520 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2521 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2522 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2523 | case Primitive::kPrimInt: { |
| 2524 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2525 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2526 | locations->SetOut(Location::SameAsFirstInput()); |
| 2527 | // Intel uses edx:eax as the dividend. |
| 2528 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2529 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2530 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 2531 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2532 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2533 | locations->AddTemp(Location::RequiresRegister()); |
| 2534 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2537 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2538 | InvokeRuntimeCallingConvention calling_convention; |
| 2539 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2540 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2541 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2542 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2543 | // Runtime helper puts the result in EAX, EDX. |
| 2544 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2545 | break; |
| 2546 | } |
| 2547 | case Primitive::kPrimFloat: |
| 2548 | case Primitive::kPrimDouble: { |
| 2549 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2550 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2551 | locations->SetOut(Location::SameAsFirstInput()); |
| 2552 | break; |
| 2553 | } |
| 2554 | |
| 2555 | default: |
| 2556 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 2561 | LocationSummary* locations = div->GetLocations(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2562 | Location out = locations->Out(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2563 | Location first = locations->InAt(0); |
| 2564 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2565 | |
| 2566 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2568 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2569 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2570 | break; |
| 2571 | } |
| 2572 | |
| 2573 | case Primitive::kPrimFloat: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2574 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2575 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2576 | break; |
| 2577 | } |
| 2578 | |
| 2579 | case Primitive::kPrimDouble: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2580 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2581 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2582 | break; |
| 2583 | } |
| 2584 | |
| 2585 | default: |
| 2586 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2587 | } |
| 2588 | } |
| 2589 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2590 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2591 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2592 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2593 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 2594 | ? LocationSummary::kCall |
| 2595 | : LocationSummary::kNoCall; |
| 2596 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2597 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2598 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2599 | case Primitive::kPrimInt: { |
| 2600 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2601 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2602 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2603 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2604 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 2605 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2606 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2607 | locations->AddTemp(Location::RequiresRegister()); |
| 2608 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2609 | break; |
| 2610 | } |
| 2611 | case Primitive::kPrimLong: { |
| 2612 | InvokeRuntimeCallingConvention calling_convention; |
| 2613 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2614 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2615 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2616 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2617 | // Runtime helper puts the result in EAX, EDX. |
| 2618 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2619 | break; |
| 2620 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2621 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2623 | locations->SetInAt(0, Location::Any()); |
| 2624 | locations->SetInAt(1, Location::Any()); |
| 2625 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2626 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2627 | break; |
| 2628 | } |
| 2629 | |
| 2630 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2631 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 2636 | Primitive::Type type = rem->GetResultType(); |
| 2637 | switch (type) { |
| 2638 | case Primitive::kPrimInt: |
| 2639 | case Primitive::kPrimLong: { |
| 2640 | GenerateDivRemIntegral(rem); |
| 2641 | break; |
| 2642 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2643 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2644 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2645 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2646 | break; |
| 2647 | } |
| 2648 | default: |
| 2649 | LOG(FATAL) << "Unexpected rem type " << type; |
| 2650 | } |
| 2651 | } |
| 2652 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2653 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2654 | LocationSummary* locations = |
| 2655 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2656 | switch (instruction->GetType()) { |
| 2657 | case Primitive::kPrimInt: { |
| 2658 | locations->SetInAt(0, Location::Any()); |
| 2659 | break; |
| 2660 | } |
| 2661 | case Primitive::kPrimLong: { |
| 2662 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2663 | if (!instruction->IsConstant()) { |
| 2664 | locations->AddTemp(Location::RequiresRegister()); |
| 2665 | } |
| 2666 | break; |
| 2667 | } |
| 2668 | default: |
| 2669 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2670 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2671 | if (instruction->HasUses()) { |
| 2672 | locations->SetOut(Location::SameAsFirstInput()); |
| 2673 | } |
| 2674 | } |
| 2675 | |
| 2676 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2677 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 2678 | codegen_->AddSlowPath(slow_path); |
| 2679 | |
| 2680 | LocationSummary* locations = instruction->GetLocations(); |
| 2681 | Location value = locations->InAt(0); |
| 2682 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2683 | switch (instruction->GetType()) { |
| 2684 | case Primitive::kPrimInt: { |
| 2685 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2686 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2687 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2688 | } else if (value.IsStackSlot()) { |
| 2689 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 2690 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2691 | } else { |
| 2692 | DCHECK(value.IsConstant()) << value; |
| 2693 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2694 | __ jmp(slow_path->GetEntryLabel()); |
| 2695 | } |
| 2696 | } |
| 2697 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2698 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2699 | case Primitive::kPrimLong: { |
| 2700 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2701 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2702 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 2703 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 2704 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2705 | } else { |
| 2706 | DCHECK(value.IsConstant()) << value; |
| 2707 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2708 | __ jmp(slow_path->GetEntryLabel()); |
| 2709 | } |
| 2710 | } |
| 2711 | break; |
| 2712 | } |
| 2713 | default: |
| 2714 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2715 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2718 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 2719 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2720 | |
| 2721 | LocationSummary* locations = |
| 2722 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 2723 | |
| 2724 | switch (op->GetResultType()) { |
| 2725 | case Primitive::kPrimInt: { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 2726 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2727 | // The shift count needs to be in CL. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2728 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
| 2729 | locations->SetOut(Location::SameAsFirstInput()); |
| 2730 | break; |
| 2731 | } |
| 2732 | case Primitive::kPrimLong: { |
| 2733 | locations->SetInAt(0, Location::RequiresRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 2734 | // The shift count needs to be in CL. |
| 2735 | locations->SetInAt(1, Location::RegisterLocation(ECX)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2736 | locations->SetOut(Location::SameAsFirstInput()); |
| 2737 | break; |
| 2738 | } |
| 2739 | default: |
| 2740 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 2745 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2746 | |
| 2747 | LocationSummary* locations = op->GetLocations(); |
| 2748 | Location first = locations->InAt(0); |
| 2749 | Location second = locations->InAt(1); |
| 2750 | DCHECK(first.Equals(locations->Out())); |
| 2751 | |
| 2752 | switch (op->GetResultType()) { |
| 2753 | case Primitive::kPrimInt: { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 2754 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2755 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2756 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2757 | DCHECK_EQ(ECX, second_reg); |
| 2758 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 2759 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2760 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 2761 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2762 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 2763 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2764 | } |
| 2765 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 2766 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 2767 | if (op->IsShl()) { |
| 2768 | __ shll(first_reg, imm); |
| 2769 | } else if (op->IsShr()) { |
| 2770 | __ sarl(first_reg, imm); |
| 2771 | } else { |
| 2772 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2773 | } |
| 2774 | } |
| 2775 | break; |
| 2776 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 2777 | case Primitive::kPrimLong: { |
| 2778 | Register second_reg = second.AsRegister<Register>(); |
| 2779 | DCHECK_EQ(ECX, second_reg); |
| 2780 | if (op->IsShl()) { |
| 2781 | GenerateShlLong(first, second_reg); |
| 2782 | } else if (op->IsShr()) { |
| 2783 | GenerateShrLong(first, second_reg); |
| 2784 | } else { |
| 2785 | GenerateUShrLong(first, second_reg); |
| 2786 | } |
| 2787 | break; |
| 2788 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2789 | default: |
| 2790 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 2791 | } |
| 2792 | } |
| 2793 | |
| 2794 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| 2795 | Label done; |
| 2796 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 2797 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 2798 | __ testl(shifter, Immediate(32)); |
| 2799 | __ j(kEqual, &done); |
| 2800 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 2801 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 2802 | __ Bind(&done); |
| 2803 | } |
| 2804 | |
| 2805 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| 2806 | Label done; |
| 2807 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 2808 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 2809 | __ testl(shifter, Immediate(32)); |
| 2810 | __ j(kEqual, &done); |
| 2811 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 2812 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 2813 | __ Bind(&done); |
| 2814 | } |
| 2815 | |
| 2816 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| 2817 | Label done; |
| 2818 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 2819 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 2820 | __ testl(shifter, Immediate(32)); |
| 2821 | __ j(kEqual, &done); |
| 2822 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 2823 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2824 | __ Bind(&done); |
| 2825 | } |
| 2826 | |
| 2827 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 2828 | HandleShift(shl); |
| 2829 | } |
| 2830 | |
| 2831 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 2832 | HandleShift(shl); |
| 2833 | } |
| 2834 | |
| 2835 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 2836 | HandleShift(shr); |
| 2837 | } |
| 2838 | |
| 2839 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 2840 | HandleShift(shr); |
| 2841 | } |
| 2842 | |
| 2843 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 2844 | HandleShift(ushr); |
| 2845 | } |
| 2846 | |
| 2847 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 2848 | HandleShift(ushr); |
| 2849 | } |
| 2850 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2851 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2852 | LocationSummary* locations = |
| 2853 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2854 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2855 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2856 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2857 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 2861 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2862 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2863 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2864 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2865 | __ fs()->call(Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint()))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2866 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2867 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2868 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2869 | } |
| 2870 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2871 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 2872 | LocationSummary* locations = |
| 2873 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2874 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 2875 | InvokeRuntimeCallingConvention calling_convention; |
| 2876 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2877 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2878 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 2882 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2883 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2884 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 2885 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2886 | __ fs()->call(Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint()))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2887 | |
| 2888 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2889 | DCHECK(!codegen_->IsLeafMethod()); |
| 2890 | } |
| 2891 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2892 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2893 | LocationSummary* locations = |
| 2894 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2895 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2896 | if (location.IsStackSlot()) { |
| 2897 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2898 | } else if (location.IsDoubleStackSlot()) { |
| 2899 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2900 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2901 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2905 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2906 | } |
| 2907 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2908 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2909 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2910 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2911 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2912 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2913 | } |
| 2914 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2915 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 2916 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2917 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2918 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2919 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 2920 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2921 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2922 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2923 | break; |
| 2924 | |
| 2925 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2926 | __ notl(out.AsRegisterPairLow<Register>()); |
| 2927 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2928 | break; |
| 2929 | |
| 2930 | default: |
| 2931 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 2932 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2933 | } |
| 2934 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 2935 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 2936 | LocationSummary* locations = |
| 2937 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 2938 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2939 | locations->SetOut(Location::SameAsFirstInput()); |
| 2940 | } |
| 2941 | |
| 2942 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 2943 | LocationSummary* locations = bool_not->GetLocations(); |
| 2944 | Location in = locations->InAt(0); |
| 2945 | Location out = locations->Out(); |
| 2946 | DCHECK(in.Equals(out)); |
| 2947 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 2948 | } |
| 2949 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2950 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2951 | LocationSummary* locations = |
| 2952 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2953 | switch (compare->InputAt(0)->GetType()) { |
| 2954 | case Primitive::kPrimLong: { |
| 2955 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2956 | locations->SetInAt(1, Location::Any()); |
| 2957 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2958 | break; |
| 2959 | } |
| 2960 | case Primitive::kPrimFloat: |
| 2961 | case Primitive::kPrimDouble: { |
| 2962 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2963 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2964 | locations->SetOut(Location::RequiresRegister()); |
| 2965 | break; |
| 2966 | } |
| 2967 | default: |
| 2968 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2969 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2973 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2974 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2975 | Location left = locations->InAt(0); |
| 2976 | Location right = locations->InAt(1); |
| 2977 | |
| 2978 | Label less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2979 | switch (compare->InputAt(0)->GetType()) { |
| 2980 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2981 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 2982 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 2983 | int32_t val_low = 0; |
| 2984 | int32_t val_high = 0; |
| 2985 | bool right_is_const = false; |
| 2986 | |
| 2987 | if (right.IsConstant()) { |
| 2988 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 2989 | right_is_const = true; |
| 2990 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2991 | val_low = Low32Bits(val); |
| 2992 | val_high = High32Bits(val); |
| 2993 | } |
| 2994 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2995 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2996 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2997 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2998 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2999 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3000 | DCHECK(right_is_const) << right; |
| 3001 | if (val_high == 0) { |
| 3002 | __ testl(left_high, left_high); |
| 3003 | } else { |
| 3004 | __ cmpl(left_high, Immediate(val_high)); |
| 3005 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3006 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3007 | __ j(kLess, &less); // Signed compare. |
| 3008 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3009 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3010 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3011 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3012 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3013 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3014 | DCHECK(right_is_const) << right; |
| 3015 | if (val_low == 0) { |
| 3016 | __ testl(left_low, left_low); |
| 3017 | } else { |
| 3018 | __ cmpl(left_low, Immediate(val_low)); |
| 3019 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3020 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3021 | break; |
| 3022 | } |
| 3023 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3024 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3025 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3026 | break; |
| 3027 | } |
| 3028 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3029 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3030 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3031 | break; |
| 3032 | } |
| 3033 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3034 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3035 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3036 | __ movl(out, Immediate(0)); |
| 3037 | __ j(kEqual, &done); |
| 3038 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3039 | |
| 3040 | __ Bind(&greater); |
| 3041 | __ movl(out, Immediate(1)); |
| 3042 | __ jmp(&done); |
| 3043 | |
| 3044 | __ Bind(&less); |
| 3045 | __ movl(out, Immediate(-1)); |
| 3046 | |
| 3047 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3048 | } |
| 3049 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3050 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3051 | LocationSummary* locations = |
| 3052 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3053 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3054 | locations->SetInAt(i, Location::Any()); |
| 3055 | } |
| 3056 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3060 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3061 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3062 | } |
| 3063 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3064 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3065 | /* |
| 3066 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3067 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3068 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3069 | */ |
| 3070 | switch (kind) { |
| 3071 | case MemBarrierKind::kAnyAny: { |
| 3072 | __ mfence(); |
| 3073 | break; |
| 3074 | } |
| 3075 | case MemBarrierKind::kAnyStore: |
| 3076 | case MemBarrierKind::kLoadAny: |
| 3077 | case MemBarrierKind::kStoreStore: { |
| 3078 | // nop |
| 3079 | break; |
| 3080 | } |
| 3081 | default: |
| 3082 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3083 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3084 | } |
| 3085 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3086 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3087 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 3088 | Register temp) { |
| 3089 | // TODO: Implement all kinds of calls: |
| 3090 | // 1) boot -> boot |
| 3091 | // 2) app -> boot |
| 3092 | // 3) app -> app |
| 3093 | // |
| 3094 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 3095 | // temp = method; |
| 3096 | LoadCurrentMethod(temp); |
| 3097 | if (!invoke->IsRecursive()) { |
| 3098 | // temp = temp->dex_cache_resolved_methods_; |
| 3099 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 3100 | // temp = temp[index_in_cache] |
| 3101 | __ movl(temp, Address(temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()))); |
| 3102 | // (temp + offset_of_quick_compiled_code)() |
| 3103 | __ call(Address( |
| 3104 | temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 3105 | } else { |
| 3106 | __ call(GetFrameEntryLabel()); |
| 3107 | } |
| 3108 | |
| 3109 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3110 | } |
| 3111 | |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3112 | void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3113 | Label is_null; |
| 3114 | __ testl(value, value); |
| 3115 | __ j(kEqual, &is_null); |
| 3116 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3117 | __ movl(temp, object); |
| 3118 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3119 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3120 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3121 | __ Bind(&is_null); |
| 3122 | } |
| 3123 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3124 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3125 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3126 | LocationSummary* locations = |
| 3127 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3128 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3129 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3130 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3131 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3132 | } else { |
| 3133 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3134 | // the object's location. |
| 3135 | locations->SetOut(Location::RequiresRegister(), |
| 3136 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3137 | : Location::kNoOutputOverlap); |
| 3138 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3139 | |
| 3140 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3141 | // Long values can be loaded atomically into an XMM using movsd. |
| 3142 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3143 | // and then copy the XMM into the output 32bits at a time). |
| 3144 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3145 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3146 | } |
| 3147 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3148 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3149 | const FieldInfo& field_info) { |
| 3150 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3151 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3152 | LocationSummary* locations = instruction->GetLocations(); |
| 3153 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3154 | Location out = locations->Out(); |
| 3155 | bool is_volatile = field_info.IsVolatile(); |
| 3156 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3157 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3158 | |
| 3159 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3160 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3161 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3162 | break; |
| 3163 | } |
| 3164 | |
| 3165 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3166 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3167 | break; |
| 3168 | } |
| 3169 | |
| 3170 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3171 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3172 | break; |
| 3173 | } |
| 3174 | |
| 3175 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3176 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3177 | break; |
| 3178 | } |
| 3179 | |
| 3180 | case Primitive::kPrimInt: |
| 3181 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3182 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3183 | break; |
| 3184 | } |
| 3185 | |
| 3186 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3187 | if (is_volatile) { |
| 3188 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3189 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3190 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3191 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3192 | __ psrlq(temp, Immediate(32)); |
| 3193 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3194 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3195 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3196 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3197 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3198 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3199 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3200 | break; |
| 3201 | } |
| 3202 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3203 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3204 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3205 | break; |
| 3206 | } |
| 3207 | |
| 3208 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3209 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3210 | break; |
| 3211 | } |
| 3212 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3213 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3214 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3215 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3216 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3217 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3218 | // Longs are handled in the switch. |
| 3219 | if (field_type != Primitive::kPrimLong) { |
| 3220 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3221 | } |
| 3222 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3223 | if (is_volatile) { |
| 3224 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3229 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3230 | |
| 3231 | LocationSummary* locations = |
| 3232 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3233 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3234 | bool is_volatile = field_info.IsVolatile(); |
| 3235 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3236 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3237 | || (field_type == Primitive::kPrimByte); |
| 3238 | |
| 3239 | // The register allocator does not support multiple |
| 3240 | // inputs that die at entry with one in a specific register. |
| 3241 | if (is_byte_type) { |
| 3242 | // Ensure the value is in a byte register. |
| 3243 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3244 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3245 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3246 | } else { |
| 3247 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3248 | } |
| 3249 | // Temporary registers for the write barrier. |
| 3250 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3251 | locations->AddTemp(Location::RequiresRegister()); |
| 3252 | // Ensure the card is in a byte register. |
| 3253 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3254 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3255 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3256 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3257 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3258 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3259 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3260 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3261 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| 3266 | const FieldInfo& field_info) { |
| 3267 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3268 | |
| 3269 | LocationSummary* locations = instruction->GetLocations(); |
| 3270 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3271 | Location value = locations->InAt(1); |
| 3272 | bool is_volatile = field_info.IsVolatile(); |
| 3273 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3274 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3275 | |
| 3276 | if (is_volatile) { |
| 3277 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3278 | } |
| 3279 | |
| 3280 | switch (field_type) { |
| 3281 | case Primitive::kPrimBoolean: |
| 3282 | case Primitive::kPrimByte: { |
| 3283 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 3284 | break; |
| 3285 | } |
| 3286 | |
| 3287 | case Primitive::kPrimShort: |
| 3288 | case Primitive::kPrimChar: { |
| 3289 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 3290 | break; |
| 3291 | } |
| 3292 | |
| 3293 | case Primitive::kPrimInt: |
| 3294 | case Primitive::kPrimNot: { |
| 3295 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3296 | break; |
| 3297 | } |
| 3298 | |
| 3299 | case Primitive::kPrimLong: { |
| 3300 | if (is_volatile) { |
| 3301 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3302 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 3303 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 3304 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 3305 | __ punpckldq(temp1, temp2); |
| 3306 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3307 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3308 | } else { |
| 3309 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3310 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3311 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 3312 | } |
| 3313 | break; |
| 3314 | } |
| 3315 | |
| 3316 | case Primitive::kPrimFloat: { |
| 3317 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3318 | break; |
| 3319 | } |
| 3320 | |
| 3321 | case Primitive::kPrimDouble: { |
| 3322 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3323 | break; |
| 3324 | } |
| 3325 | |
| 3326 | case Primitive::kPrimVoid: |
| 3327 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3328 | UNREACHABLE(); |
| 3329 | } |
| 3330 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3331 | // Longs are handled in the switch. |
| 3332 | if (field_type != Primitive::kPrimLong) { |
| 3333 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3334 | } |
| 3335 | |
| 3336 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3337 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3338 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 3339 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>()); |
| 3340 | } |
| 3341 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3342 | if (is_volatile) { |
| 3343 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3348 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3349 | } |
| 3350 | |
| 3351 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3352 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3353 | } |
| 3354 | |
| 3355 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3356 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3357 | } |
| 3358 | |
| 3359 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3360 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3361 | } |
| 3362 | |
| 3363 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3364 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3365 | } |
| 3366 | |
| 3367 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3368 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3369 | } |
| 3370 | |
| 3371 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3372 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3373 | } |
| 3374 | |
| 3375 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3376 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3380 | LocationSummary* locations = |
| 3381 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3382 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3383 | ? Location::RequiresRegister() |
| 3384 | : Location::Any(); |
| 3385 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3386 | if (instruction->HasUses()) { |
| 3387 | locations->SetOut(Location::SameAsFirstInput()); |
| 3388 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3389 | } |
| 3390 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3391 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3392 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3393 | return; |
| 3394 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3395 | LocationSummary* locations = instruction->GetLocations(); |
| 3396 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3397 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3398 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 3399 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3400 | } |
| 3401 | |
| 3402 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3403 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3404 | codegen_->AddSlowPath(slow_path); |
| 3405 | |
| 3406 | LocationSummary* locations = instruction->GetLocations(); |
| 3407 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3408 | |
| 3409 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 3410 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3411 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3412 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3413 | } else { |
| 3414 | DCHECK(obj.IsConstant()) << obj; |
| 3415 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 3416 | __ jmp(slow_path->GetEntryLabel()); |
| 3417 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3418 | } |
| 3419 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3420 | } |
| 3421 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3422 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| 3423 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3424 | GenerateImplicitNullCheck(instruction); |
| 3425 | } else { |
| 3426 | GenerateExplicitNullCheck(instruction); |
| 3427 | } |
| 3428 | } |
| 3429 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3430 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3431 | LocationSummary* locations = |
| 3432 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3433 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3434 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3435 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3436 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3437 | } else { |
| 3438 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3439 | // the array's location. |
| 3440 | locations->SetOut(Location::RequiresRegister(), |
| 3441 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3442 | : Location::kNoOutputOverlap); |
| 3443 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 3447 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3448 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3449 | Location index = locations->InAt(1); |
| 3450 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3451 | Primitive::Type type = instruction->GetType(); |
| 3452 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3453 | case Primitive::kPrimBoolean: { |
| 3454 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3455 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3456 | if (index.IsConstant()) { |
| 3457 | __ movzxb(out, Address(obj, |
| 3458 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3459 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3460 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3461 | } |
| 3462 | break; |
| 3463 | } |
| 3464 | |
| 3465 | case Primitive::kPrimByte: { |
| 3466 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3467 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3468 | if (index.IsConstant()) { |
| 3469 | __ movsxb(out, Address(obj, |
| 3470 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3471 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3472 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3473 | } |
| 3474 | break; |
| 3475 | } |
| 3476 | |
| 3477 | case Primitive::kPrimShort: { |
| 3478 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3479 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3480 | if (index.IsConstant()) { |
| 3481 | __ movsxw(out, Address(obj, |
| 3482 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3483 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3484 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3485 | } |
| 3486 | break; |
| 3487 | } |
| 3488 | |
| 3489 | case Primitive::kPrimChar: { |
| 3490 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3491 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3492 | if (index.IsConstant()) { |
| 3493 | __ movzxw(out, Address(obj, |
| 3494 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3495 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3496 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3497 | } |
| 3498 | break; |
| 3499 | } |
| 3500 | |
| 3501 | case Primitive::kPrimInt: |
| 3502 | case Primitive::kPrimNot: { |
| 3503 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3504 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3505 | if (index.IsConstant()) { |
| 3506 | __ movl(out, Address(obj, |
| 3507 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3508 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3509 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3510 | } |
| 3511 | break; |
| 3512 | } |
| 3513 | |
| 3514 | case Primitive::kPrimLong: { |
| 3515 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3516 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3517 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3518 | if (index.IsConstant()) { |
| 3519 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3520 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3521 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3522 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3523 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3524 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3525 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3526 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3527 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3528 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3529 | } |
| 3530 | break; |
| 3531 | } |
| 3532 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3533 | case Primitive::kPrimFloat: { |
| 3534 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3535 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 3536 | if (index.IsConstant()) { |
| 3537 | __ movss(out, Address(obj, |
| 3538 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3539 | } else { |
| 3540 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 3541 | } |
| 3542 | break; |
| 3543 | } |
| 3544 | |
| 3545 | case Primitive::kPrimDouble: { |
| 3546 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3547 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 3548 | if (index.IsConstant()) { |
| 3549 | __ movsd(out, Address(obj, |
| 3550 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3551 | } else { |
| 3552 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 3553 | } |
| 3554 | break; |
| 3555 | } |
| 3556 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3557 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3558 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3559 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3560 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3561 | |
| 3562 | if (type != Primitive::kPrimLong) { |
| 3563 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3564 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 3568 | // This location builder might end up asking to up to four registers, which is |
| 3569 | // not currently possible for baseline. The situation in which we need four |
| 3570 | // registers cannot be met by baseline though, because it has not run any |
| 3571 | // optimization. |
| 3572 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3573 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3574 | bool needs_write_barrier = |
| 3575 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3576 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 3577 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3578 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3579 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3580 | instruction, |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3581 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3582 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3583 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3584 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3585 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3586 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3587 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3588 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 3589 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 3590 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3591 | // 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] | 3592 | // In case of a byte operation, the register allocator does not support multiple |
| 3593 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3594 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3595 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 3596 | if (is_byte_type) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3597 | // Ensure the value is in a byte register. |
| 3598 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3599 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 3600 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3601 | } else { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3602 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3603 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3604 | // Temporary registers for the write barrier. |
| 3605 | if (needs_write_barrier) { |
| 3606 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3607 | // Ensure the card is in a byte register. |
| 3608 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3609 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3610 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 3614 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3615 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3616 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3617 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3618 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3619 | bool needs_runtime_call = locations->WillCall(); |
| 3620 | bool needs_write_barrier = |
| 3621 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3622 | |
| 3623 | switch (value_type) { |
| 3624 | case Primitive::kPrimBoolean: |
| 3625 | case Primitive::kPrimByte: { |
| 3626 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3627 | if (index.IsConstant()) { |
| 3628 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3629 | if (value.IsRegister()) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3630 | __ movb(Address(obj, offset), value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3631 | } else { |
| 3632 | __ movb(Address(obj, offset), |
| 3633 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3634 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3635 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3636 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3637 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3638 | value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3639 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3640 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3641 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3642 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3643 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3644 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3645 | break; |
| 3646 | } |
| 3647 | |
| 3648 | case Primitive::kPrimShort: |
| 3649 | case Primitive::kPrimChar: { |
| 3650 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3651 | if (index.IsConstant()) { |
| 3652 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3653 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3654 | __ movw(Address(obj, offset), value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3655 | } else { |
| 3656 | __ movw(Address(obj, offset), |
| 3657 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3658 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3659 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3660 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3661 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
| 3662 | value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3663 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3664 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3665 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3666 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3667 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3668 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3669 | break; |
| 3670 | } |
| 3671 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3672 | case Primitive::kPrimInt: |
| 3673 | case Primitive::kPrimNot: { |
| 3674 | if (!needs_runtime_call) { |
| 3675 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3676 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3677 | size_t offset = |
| 3678 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3679 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3680 | __ movl(Address(obj, offset), value.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3681 | } else { |
| 3682 | DCHECK(value.IsConstant()) << value; |
| 3683 | __ movl(Address(obj, offset), |
| 3684 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3685 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3686 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3687 | DCHECK(index.IsRegister()) << index; |
| 3688 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3689 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 3690 | value.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3691 | } else { |
| 3692 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3693 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3694 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3695 | } |
| 3696 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3697 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3698 | |
| 3699 | if (needs_write_barrier) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3700 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3701 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 3702 | codegen_->MarkGCCard(temp, card, obj, value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3703 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3704 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3705 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 3706 | DCHECK(!codegen_->IsLeafMethod()); |
| 3707 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject))); |
| 3708 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3709 | } |
| 3710 | break; |
| 3711 | } |
| 3712 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3713 | case Primitive::kPrimLong: { |
| 3714 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3715 | if (index.IsConstant()) { |
| 3716 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3717 | if (value.IsRegisterPair()) { |
| 3718 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3719 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3720 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3721 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3722 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3723 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3724 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3725 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3726 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 3727 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3728 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3729 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3730 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3731 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3732 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3733 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3734 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3735 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3736 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3737 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3738 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3739 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3740 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3741 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3742 | Immediate(High32Bits(val))); |
| 3743 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3744 | } |
| 3745 | break; |
| 3746 | } |
| 3747 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3748 | case Primitive::kPrimFloat: { |
| 3749 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3750 | DCHECK(value.IsFpuRegister()); |
| 3751 | if (index.IsConstant()) { |
| 3752 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3753 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 3754 | } else { |
| 3755 | __ movss(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 3756 | value.AsFpuRegister<XmmRegister>()); |
| 3757 | } |
| 3758 | break; |
| 3759 | } |
| 3760 | |
| 3761 | case Primitive::kPrimDouble: { |
| 3762 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3763 | DCHECK(value.IsFpuRegister()); |
| 3764 | if (index.IsConstant()) { |
| 3765 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3766 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 3767 | } else { |
| 3768 | __ movsd(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
| 3769 | value.AsFpuRegister<XmmRegister>()); |
| 3770 | } |
| 3771 | break; |
| 3772 | } |
| 3773 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3774 | case Primitive::kPrimVoid: |
| 3775 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3776 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 3781 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3782 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3783 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3784 | instruction->SetLocations(locations); |
| 3785 | } |
| 3786 | |
| 3787 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 3788 | LocationSummary* locations = instruction->GetLocations(); |
| 3789 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3790 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 3791 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3792 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3793 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3794 | } |
| 3795 | |
| 3796 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3797 | LocationSummary* locations = |
| 3798 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 3799 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3800 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3801 | if (instruction->HasUses()) { |
| 3802 | locations->SetOut(Location::SameAsFirstInput()); |
| 3803 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3807 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 3808 | Location index_loc = locations->InAt(0); |
| 3809 | Location length_loc = locations->InAt(1); |
| 3810 | SlowPathCodeX86* slow_path = |
| 3811 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction, index_loc, length_loc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3812 | codegen_->AddSlowPath(slow_path); |
| 3813 | |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 3814 | Register length = length_loc.AsRegister<Register>(); |
| 3815 | if (index_loc.IsConstant()) { |
| 3816 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 3817 | __ cmpl(length, Immediate(value)); |
| 3818 | } else { |
| 3819 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 3820 | } |
| 3821 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3822 | } |
| 3823 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3824 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 3825 | temp->SetLocations(nullptr); |
| 3826 | } |
| 3827 | |
| 3828 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 3829 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3830 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3831 | } |
| 3832 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3833 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3834 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3835 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3839 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 3840 | } |
| 3841 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3842 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3843 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 3844 | } |
| 3845 | |
| 3846 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3847 | HBasicBlock* block = instruction->GetBlock(); |
| 3848 | if (block->GetLoopInformation() != nullptr) { |
| 3849 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 3850 | // The back edge will generate the suspend check. |
| 3851 | return; |
| 3852 | } |
| 3853 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 3854 | // The goto will generate the suspend check. |
| 3855 | return; |
| 3856 | } |
| 3857 | GenerateSuspendCheck(instruction, nullptr); |
| 3858 | } |
| 3859 | |
| 3860 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 3861 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3862 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3863 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3864 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3865 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3866 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3867 | if (successor == nullptr) { |
| 3868 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 3869 | __ Bind(slow_path->GetReturnLabel()); |
| 3870 | } else { |
| 3871 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 3872 | __ jmp(slow_path->GetEntryLabel()); |
| 3873 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3876 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 3877 | return codegen_->GetAssembler(); |
| 3878 | } |
| 3879 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3880 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 3881 | ScratchRegisterScope ensure_scratch( |
| 3882 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 3883 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 3884 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 3885 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 3886 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 3890 | ScratchRegisterScope ensure_scratch( |
| 3891 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 3892 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 3893 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 3894 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 3895 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 3896 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 3897 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 3901 | MoveOperands* move = moves_.Get(index); |
| 3902 | Location source = move->GetSource(); |
| 3903 | Location destination = move->GetDestination(); |
| 3904 | |
| 3905 | if (source.IsRegister()) { |
| 3906 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3907 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3908 | } else { |
| 3909 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3910 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3911 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3912 | } else if (source.IsFpuRegister()) { |
| 3913 | if (destination.IsFpuRegister()) { |
| 3914 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 3915 | } else if (destination.IsStackSlot()) { |
| 3916 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 3917 | } else { |
| 3918 | DCHECK(destination.IsDoubleStackSlot()); |
| 3919 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 3920 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3921 | } else if (source.IsStackSlot()) { |
| 3922 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3923 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3924 | } else if (destination.IsFpuRegister()) { |
| 3925 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3926 | } else { |
| 3927 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3928 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 3929 | } |
| 3930 | } else if (source.IsDoubleStackSlot()) { |
| 3931 | if (destination.IsFpuRegister()) { |
| 3932 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 3933 | } else { |
| 3934 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 3935 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3936 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3937 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3938 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3939 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3940 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3941 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3942 | if (value == 0) { |
| 3943 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 3944 | } else { |
| 3945 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 3946 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3947 | } else { |
| 3948 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3949 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3950 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3951 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3952 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 3953 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3954 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3955 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3956 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 3957 | if (value == 0) { |
| 3958 | // Easy handling of 0.0. |
| 3959 | __ xorps(dest, dest); |
| 3960 | } else { |
| 3961 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 3962 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 3963 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 3964 | __ movl(temp, Immediate(value)); |
| 3965 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3966 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3967 | } else { |
| 3968 | DCHECK(destination.IsStackSlot()) << destination; |
| 3969 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 3970 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3971 | } else if (constant->IsLongConstant()) { |
| 3972 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 3973 | int32_t low_value = Low32Bits(value); |
| 3974 | int32_t high_value = High32Bits(value); |
| 3975 | Immediate low(low_value); |
| 3976 | Immediate high(high_value); |
| 3977 | if (destination.IsDoubleStackSlot()) { |
| 3978 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 3979 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 3980 | } else { |
| 3981 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 3982 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 3983 | } |
| 3984 | } else { |
| 3985 | DCHECK(constant->IsDoubleConstant()); |
| 3986 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 3987 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3988 | int32_t low_value = Low32Bits(value); |
| 3989 | int32_t high_value = High32Bits(value); |
| 3990 | Immediate low(low_value); |
| 3991 | Immediate high(high_value); |
| 3992 | if (destination.IsFpuRegister()) { |
| 3993 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 3994 | if (value == 0) { |
| 3995 | // Easy handling of 0.0. |
| 3996 | __ xorpd(dest, dest); |
| 3997 | } else { |
| 3998 | __ pushl(high); |
| 3999 | __ pushl(low); |
| 4000 | __ movsd(dest, Address(ESP, 0)); |
| 4001 | __ addl(ESP, Immediate(8)); |
| 4002 | } |
| 4003 | } else { |
| 4004 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4005 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4006 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4007 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4008 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4009 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4010 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4011 | } |
| 4012 | } |
| 4013 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4014 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4015 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4016 | ScratchRegisterScope ensure_scratch( |
| 4017 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4018 | |
| 4019 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4020 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4021 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4022 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4023 | } |
| 4024 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4025 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4026 | ScratchRegisterScope ensure_scratch( |
| 4027 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4028 | |
| 4029 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4030 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4031 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4032 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4033 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4034 | } |
| 4035 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4036 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4037 | ScratchRegisterScope ensure_scratch1( |
| 4038 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4039 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4040 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4041 | ScratchRegisterScope ensure_scratch2( |
| 4042 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4043 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4044 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4045 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4046 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4047 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4048 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4049 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4050 | } |
| 4051 | |
| 4052 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 4053 | MoveOperands* move = moves_.Get(index); |
| 4054 | Location source = move->GetSource(); |
| 4055 | Location destination = move->GetDestination(); |
| 4056 | |
| 4057 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4058 | __ xchgl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4059 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4060 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4061 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4062 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4063 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4064 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4065 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4066 | // Use XOR Swap algorithm to avoid a temporary. |
| 4067 | DCHECK_NE(source.reg(), destination.reg()); |
| 4068 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4069 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4070 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4071 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4072 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4073 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4074 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4075 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4076 | // Take advantage of the 16 bytes in the XMM register. |
| 4077 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4078 | Address stack(ESP, destination.GetStackIndex()); |
| 4079 | // Load the double into the high doubleword. |
| 4080 | __ movhpd(reg, stack); |
| 4081 | |
| 4082 | // Store the low double into the destination. |
| 4083 | __ movsd(stack, reg); |
| 4084 | |
| 4085 | // Move the high double to the low double. |
| 4086 | __ psrldq(reg, Immediate(8)); |
| 4087 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4088 | // Take advantage of the 16 bytes in the XMM register. |
| 4089 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4090 | Address stack(ESP, source.GetStackIndex()); |
| 4091 | // Load the double into the high doubleword. |
| 4092 | __ movhpd(reg, stack); |
| 4093 | |
| 4094 | // Store the low double into the destination. |
| 4095 | __ movsd(stack, reg); |
| 4096 | |
| 4097 | // Move the high double to the low double. |
| 4098 | __ psrldq(reg, Immediate(8)); |
| 4099 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4100 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4101 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4102 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4103 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4108 | __ pushl(static_cast<Register>(reg)); |
| 4109 | } |
| 4110 | |
| 4111 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4112 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4113 | } |
| 4114 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4115 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4116 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4117 | ? LocationSummary::kCallOnSlowPath |
| 4118 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4119 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4120 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4121 | locations->SetOut(Location::RequiresRegister()); |
| 4122 | } |
| 4123 | |
| 4124 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4125 | Register out = cls->GetLocations()->Out().AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4126 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4127 | DCHECK(!cls->CanCallRuntime()); |
| 4128 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4129 | codegen_->LoadCurrentMethod(out); |
| 4130 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 4131 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4132 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4133 | codegen_->LoadCurrentMethod(out); |
| 4134 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
| 4135 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4136 | |
| 4137 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4138 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4139 | codegen_->AddSlowPath(slow_path); |
| 4140 | __ testl(out, out); |
| 4141 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4142 | if (cls->MustGenerateClinitCheck()) { |
| 4143 | GenerateClassInitializationCheck(slow_path, out); |
| 4144 | } else { |
| 4145 | __ Bind(slow_path->GetExitLabel()); |
| 4146 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 4151 | LocationSummary* locations = |
| 4152 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4153 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4154 | if (check->HasUses()) { |
| 4155 | locations->SetOut(Location::SameAsFirstInput()); |
| 4156 | } |
| 4157 | } |
| 4158 | |
| 4159 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4160 | // We assume the class to not be null. |
| 4161 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4162 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4163 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4164 | GenerateClassInitializationCheck(slow_path, |
| 4165 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4166 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4167 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4168 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 4169 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4170 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4171 | Immediate(mirror::Class::kStatusInitialized)); |
| 4172 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4173 | __ Bind(slow_path->GetExitLabel()); |
| 4174 | // No need for memory fence, thanks to the X86 memory model. |
| 4175 | } |
| 4176 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4177 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 4178 | LocationSummary* locations = |
| 4179 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 4180 | locations->SetOut(Location::RequiresRegister()); |
| 4181 | } |
| 4182 | |
| 4183 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 4184 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 4185 | codegen_->AddSlowPath(slow_path); |
| 4186 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4187 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4188 | codegen_->LoadCurrentMethod(out); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4189 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 4190 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4191 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 4192 | __ testl(out, out); |
| 4193 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4194 | __ Bind(slow_path->GetExitLabel()); |
| 4195 | } |
| 4196 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4197 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 4198 | LocationSummary* locations = |
| 4199 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4200 | locations->SetOut(Location::RequiresRegister()); |
| 4201 | } |
| 4202 | |
| 4203 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| 4204 | Address address = Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4205 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), address); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4206 | __ fs()->movl(address, Immediate(0)); |
| 4207 | } |
| 4208 | |
| 4209 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 4210 | LocationSummary* locations = |
| 4211 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4212 | InvokeRuntimeCallingConvention calling_convention; |
| 4213 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4214 | } |
| 4215 | |
| 4216 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| 4217 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pDeliverException))); |
| 4218 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4219 | } |
| 4220 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4221 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4222 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4223 | ? LocationSummary::kNoCall |
| 4224 | : LocationSummary::kCallOnSlowPath; |
| 4225 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4226 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4227 | locations->SetInAt(1, Location::Any()); |
| 4228 | locations->SetOut(Location::RequiresRegister()); |
| 4229 | } |
| 4230 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4231 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4232 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4233 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4234 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4235 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4236 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4237 | Label done, zero; |
| 4238 | SlowPathCodeX86* slow_path = nullptr; |
| 4239 | |
| 4240 | // Return 0 if `obj` is null. |
| 4241 | // TODO: avoid this check if we know obj is not null. |
| 4242 | __ testl(obj, obj); |
| 4243 | __ j(kEqual, &zero); |
| 4244 | __ movl(out, Address(obj, class_offset)); |
| 4245 | // Compare the class of `obj` with `cls`. |
| 4246 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4247 | __ cmpl(out, cls.AsRegister<Register>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4248 | } else { |
| 4249 | DCHECK(cls.IsStackSlot()) << cls; |
| 4250 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 4251 | } |
| 4252 | |
| 4253 | if (instruction->IsClassFinal()) { |
| 4254 | // Classes must be equal for the instanceof to succeed. |
| 4255 | __ j(kNotEqual, &zero); |
| 4256 | __ movl(out, Immediate(1)); |
| 4257 | __ jmp(&done); |
| 4258 | } else { |
| 4259 | // If the classes are not equal, we go into a slow path. |
| 4260 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4261 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4262 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4263 | codegen_->AddSlowPath(slow_path); |
| 4264 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4265 | __ movl(out, Immediate(1)); |
| 4266 | __ jmp(&done); |
| 4267 | } |
| 4268 | __ Bind(&zero); |
| 4269 | __ movl(out, Immediate(0)); |
| 4270 | if (slow_path != nullptr) { |
| 4271 | __ Bind(slow_path->GetExitLabel()); |
| 4272 | } |
| 4273 | __ Bind(&done); |
| 4274 | } |
| 4275 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4276 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| 4277 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4278 | instruction, LocationSummary::kCallOnSlowPath); |
| 4279 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4280 | locations->SetInAt(1, Location::Any()); |
| 4281 | locations->AddTemp(Location::RequiresRegister()); |
| 4282 | } |
| 4283 | |
| 4284 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 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 | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4287 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4288 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4289 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4290 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 4291 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 4292 | codegen_->AddSlowPath(slow_path); |
| 4293 | |
| 4294 | // TODO: avoid this check if we know obj is not null. |
| 4295 | __ testl(obj, obj); |
| 4296 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4297 | __ movl(temp, Address(obj, class_offset)); |
| 4298 | |
| 4299 | // Compare the class of `obj` with `cls`. |
| 4300 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4301 | __ cmpl(temp, cls.AsRegister<Register>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4302 | } else { |
| 4303 | DCHECK(cls.IsStackSlot()) << cls; |
| 4304 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 4305 | } |
| 4306 | |
| 4307 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4308 | __ Bind(slow_path->GetExitLabel()); |
| 4309 | } |
| 4310 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4311 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4312 | LocationSummary* locations = |
| 4313 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4314 | InvokeRuntimeCallingConvention calling_convention; |
| 4315 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4316 | } |
| 4317 | |
| 4318 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4319 | __ fs()->call(Address::Absolute(instruction->IsEnter() |
| 4320 | ? QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLockObject) |
| 4321 | : QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pUnlockObject))); |
| 4322 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4323 | } |
| 4324 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4325 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4326 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4327 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4328 | |
| 4329 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4330 | LocationSummary* locations = |
| 4331 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4332 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4333 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4335 | locations->SetInAt(1, Location::Any()); |
| 4336 | locations->SetOut(Location::SameAsFirstInput()); |
| 4337 | } |
| 4338 | |
| 4339 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 4340 | HandleBitwiseOperation(instruction); |
| 4341 | } |
| 4342 | |
| 4343 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 4344 | HandleBitwiseOperation(instruction); |
| 4345 | } |
| 4346 | |
| 4347 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 4348 | HandleBitwiseOperation(instruction); |
| 4349 | } |
| 4350 | |
| 4351 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4352 | LocationSummary* locations = instruction->GetLocations(); |
| 4353 | Location first = locations->InAt(0); |
| 4354 | Location second = locations->InAt(1); |
| 4355 | DCHECK(first.Equals(locations->Out())); |
| 4356 | |
| 4357 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 4358 | if (second.IsRegister()) { |
| 4359 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4360 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4361 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4362 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4363 | } else { |
| 4364 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4365 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4366 | } |
| 4367 | } else if (second.IsConstant()) { |
| 4368 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4369 | __ andl(first.AsRegister<Register>(), |
| 4370 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4371 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4372 | __ orl(first.AsRegister<Register>(), |
| 4373 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4374 | } else { |
| 4375 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4376 | __ xorl(first.AsRegister<Register>(), |
| 4377 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4378 | } |
| 4379 | } else { |
| 4380 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4381 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4382 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4383 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4384 | } else { |
| 4385 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4386 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4387 | } |
| 4388 | } |
| 4389 | } else { |
| 4390 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 4391 | if (second.IsRegisterPair()) { |
| 4392 | if (instruction->IsAnd()) { |
| 4393 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 4394 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 4395 | } else if (instruction->IsOr()) { |
| 4396 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 4397 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 4398 | } else { |
| 4399 | DCHECK(instruction->IsXor()); |
| 4400 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 4401 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 4402 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4403 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4404 | if (instruction->IsAnd()) { |
| 4405 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 4406 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 4407 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 4408 | } else if (instruction->IsOr()) { |
| 4409 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 4410 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 4411 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 4412 | } else { |
| 4413 | DCHECK(instruction->IsXor()); |
| 4414 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 4415 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 4416 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 4417 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4418 | } else { |
| 4419 | DCHECK(second.IsConstant()) << second; |
| 4420 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4421 | int32_t low_value = Low32Bits(value); |
| 4422 | int32_t high_value = High32Bits(value); |
| 4423 | Immediate low(low_value); |
| 4424 | Immediate high(high_value); |
| 4425 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 4426 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4427 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4428 | if (low_value == 0) { |
| 4429 | __ xorl(first_low, first_low); |
| 4430 | } else if (low_value != -1) { |
| 4431 | __ andl(first_low, low); |
| 4432 | } |
| 4433 | if (high_value == 0) { |
| 4434 | __ xorl(first_high, first_high); |
| 4435 | } else if (high_value != -1) { |
| 4436 | __ andl(first_high, high); |
| 4437 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4438 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4439 | if (low_value != 0) { |
| 4440 | __ orl(first_low, low); |
| 4441 | } |
| 4442 | if (high_value != 0) { |
| 4443 | __ orl(first_high, high); |
| 4444 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4445 | } else { |
| 4446 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4447 | if (low_value != 0) { |
| 4448 | __ xorl(first_low, low); |
| 4449 | } |
| 4450 | if (high_value != 0) { |
| 4451 | __ xorl(first_high, high); |
| 4452 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4453 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4454 | } |
| 4455 | } |
| 4456 | } |
| 4457 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4458 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 4459 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4460 | UNUSED(instruction); |
| 4461 | LOG(FATAL) << "Unreachable"; |
| 4462 | } |
| 4463 | |
| 4464 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 4465 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4466 | UNUSED(instruction); |
| 4467 | LOG(FATAL) << "Unreachable"; |
| 4468 | } |
| 4469 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 4470 | } // namespace x86 |
| 4471 | } // namespace art |