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