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