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