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