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