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