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