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