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 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 59 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 60 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 62 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 64 | }; |
| 65 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 66 | class DivZeroCheckSlowPathX86 : public SlowPathCodeX86 { |
| 67 | public: |
| 68 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 69 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 70 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 71 | __ Bind(GetEntryLabel()); |
| 72 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowDivZero))); |
Mingyao Yang | 2be4869 | 2015-03-31 17:03:08 -0700 | [diff] [blame] | 73 | RecordPcInfo(codegen, instruction_, instruction_->GetDexPc()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 76 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 77 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 78 | private: |
| 79 | HDivZeroCheck* const instruction_; |
| 80 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 81 | }; |
| 82 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 83 | class DivRemMinusOneSlowPathX86 : public SlowPathCodeX86 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 84 | public: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 85 | 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] | 86 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 87 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 88 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 89 | if (is_div_) { |
| 90 | __ negl(reg_); |
| 91 | } else { |
| 92 | __ movl(reg_, Immediate(0)); |
| 93 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 94 | __ jmp(GetExitLabel()); |
| 95 | } |
| 96 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 98 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | private: |
| 100 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 101 | bool is_div_; |
| 102 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 105 | class BoundsCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 106 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 107 | BoundsCheckSlowPathX86(HBoundsCheck* instruction, |
| 108 | Location index_location, |
| 109 | Location length_location) |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 110 | : instruction_(instruction), |
| 111 | index_location_(index_location), |
| 112 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 113 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 114 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 115 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 116 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 117 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 118 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 119 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 120 | x86_codegen->EmitParallelMoves( |
| 121 | index_location_, |
| 122 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 123 | Primitive::kPrimInt, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 124 | length_location_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 125 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 126 | Primitive::kPrimInt); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 127 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowArrayBounds))); |
Mingyao Yang | 2be4869 | 2015-03-31 17:03:08 -0700 | [diff] [blame] | 128 | RecordPcInfo(codegen, instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 131 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 132 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 134 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 135 | const Location index_location_; |
| 136 | const Location length_location_; |
| 137 | |
| 138 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 139 | }; |
| 140 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 141 | class SuspendCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 143 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 144 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 146 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 147 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 148 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 149 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 150 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pTestSuspend))); |
Mingyao Yang | 2be4869 | 2015-03-31 17:03:08 -0700 | [diff] [blame] | 151 | RecordPcInfo(codegen, instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 152 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 153 | if (successor_ == nullptr) { |
| 154 | __ jmp(GetReturnLabel()); |
| 155 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 156 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 157 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 160 | Label* GetReturnLabel() { |
| 161 | DCHECK(successor_ == nullptr); |
| 162 | return &return_label_; |
| 163 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 164 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 165 | HBasicBlock* GetSuccessor() const { |
| 166 | return successor_; |
| 167 | } |
| 168 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 169 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 170 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | private: |
| 172 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 173 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 174 | Label return_label_; |
| 175 | |
| 176 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 177 | }; |
| 178 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 179 | class LoadStringSlowPathX86 : public SlowPathCodeX86 { |
| 180 | public: |
| 181 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 182 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 183 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 184 | LocationSummary* locations = instruction_->GetLocations(); |
| 185 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 186 | |
| 187 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 188 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 189 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 190 | |
| 191 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 192 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 193 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pResolveString))); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 194 | RecordPcInfo(codegen, instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 195 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 196 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 197 | |
| 198 | __ jmp(GetExitLabel()); |
| 199 | } |
| 200 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 201 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 202 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 203 | private: |
| 204 | HLoadString* const instruction_; |
| 205 | |
| 206 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 207 | }; |
| 208 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 209 | class LoadClassSlowPathX86 : public SlowPathCodeX86 { |
| 210 | public: |
| 211 | LoadClassSlowPathX86(HLoadClass* cls, |
| 212 | HInstruction* at, |
| 213 | uint32_t dex_pc, |
| 214 | bool do_clinit) |
| 215 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 216 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 217 | } |
| 218 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 219 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 220 | LocationSummary* locations = at_->GetLocations(); |
| 221 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 222 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 223 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | |
| 225 | InvokeRuntimeCallingConvention calling_convention; |
| 226 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 227 | __ fs()->call(Address::Absolute(do_clinit_ |
| 228 | ? QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pInitializeStaticStorage) |
| 229 | : QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pInitializeType))); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 230 | RecordPcInfo(codegen, at_, dex_pc_); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 231 | |
| 232 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 233 | Location out = locations->Out(); |
| 234 | if (out.IsValid()) { |
| 235 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 236 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 238 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 239 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 240 | __ jmp(GetExitLabel()); |
| 241 | } |
| 242 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 243 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 244 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 245 | private: |
| 246 | // The class this slow path will load. |
| 247 | HLoadClass* const cls_; |
| 248 | |
| 249 | // The instruction where this slow path is happening. |
| 250 | // (Might be the load class or an initialization check). |
| 251 | HInstruction* const at_; |
| 252 | |
| 253 | // The dex PC of `at_`. |
| 254 | const uint32_t dex_pc_; |
| 255 | |
| 256 | // Whether to initialize the class. |
| 257 | const bool do_clinit_; |
| 258 | |
| 259 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 260 | }; |
| 261 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 262 | class TypeCheckSlowPathX86 : public SlowPathCodeX86 { |
| 263 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 264 | TypeCheckSlowPathX86(HInstruction* instruction, |
| 265 | Location class_to_check, |
| 266 | Location object_class, |
| 267 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 268 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 269 | class_to_check_(class_to_check), |
| 270 | object_class_(object_class), |
| 271 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 272 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 273 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 274 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 275 | DCHECK(instruction_->IsCheckCast() |
| 276 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 277 | |
| 278 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 279 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 280 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 281 | |
| 282 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 283 | // move resolver. |
| 284 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 285 | x86_codegen->EmitParallelMoves( |
| 286 | class_to_check_, |
| 287 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 288 | Primitive::kPrimNot, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 289 | object_class_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 290 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 291 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 292 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 293 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 294 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, |
| 295 | pInstanceofNonTrivial))); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 296 | } else { |
| 297 | DCHECK(instruction_->IsCheckCast()); |
| 298 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pCheckCast))); |
| 299 | } |
| 300 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 301 | RecordPcInfo(codegen, instruction_, dex_pc_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 302 | if (instruction_->IsInstanceOf()) { |
| 303 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 304 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 305 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | |
| 307 | __ jmp(GetExitLabel()); |
| 308 | } |
| 309 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 310 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
| 311 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 313 | HInstruction* const instruction_; |
| 314 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 315 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 316 | const uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | |
| 318 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 319 | }; |
| 320 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 321 | class DeoptimizationSlowPathX86 : public SlowPathCodeX86 { |
| 322 | public: |
| 323 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 324 | : instruction_(instruction) {} |
| 325 | |
| 326 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 327 | __ Bind(GetEntryLabel()); |
| 328 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 329 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pDeoptimize))); |
| 330 | // No need to restore live registers. |
| 331 | DCHECK(instruction_->IsDeoptimize()); |
| 332 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 333 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 334 | codegen->RecordPcInfo(instruction_, dex_pc, this); |
| 335 | } |
| 336 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 337 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 338 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 339 | private: |
| 340 | HInstruction* const instruction_; |
| 341 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 342 | }; |
| 343 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 344 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 345 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 346 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 347 | inline Condition X86SignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 348 | switch (cond) { |
| 349 | case kCondEQ: return kEqual; |
| 350 | case kCondNE: return kNotEqual; |
| 351 | case kCondLT: return kLess; |
| 352 | case kCondLE: return kLessEqual; |
| 353 | case kCondGT: return kGreater; |
| 354 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 355 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 356 | LOG(FATAL) << "Unreachable"; |
| 357 | UNREACHABLE(); |
| 358 | } |
| 359 | |
| 360 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 361 | switch (cond) { |
| 362 | case kCondEQ: return kEqual; |
| 363 | case kCondNE: return kNotEqual; |
| 364 | case kCondLT: return kBelow; |
| 365 | case kCondLE: return kBelowEqual; |
| 366 | case kCondGT: return kAbove; |
| 367 | case kCondGE: return kAboveEqual; |
| 368 | } |
| 369 | LOG(FATAL) << "Unreachable"; |
| 370 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 373 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 374 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 378 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 381 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 382 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 383 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 384 | } |
| 385 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 386 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 387 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 388 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 389 | } |
| 390 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 391 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 392 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 393 | return GetFloatingPointSpillSlotSize(); |
| 394 | } |
| 395 | |
| 396 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 397 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 398 | return GetFloatingPointSpillSlotSize(); |
| 399 | } |
| 400 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 401 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| 402 | const X86InstructionSetFeatures& isa_features, |
| 403 | const CompilerOptions& compiler_options) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 404 | : CodeGenerator(graph, |
| 405 | kNumberOfCpuRegisters, |
| 406 | kNumberOfXmmRegisters, |
| 407 | kNumberOfRegisterPairs, |
| 408 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 409 | arraysize(kCoreCalleeSaves)) |
| 410 | | (1 << kFakeReturnRegister), |
| 411 | 0, |
| 412 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 413 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 414 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 415 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 416 | move_resolver_(graph->GetArena(), this), |
| 417 | isa_features_(isa_features) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 418 | // Use a fake return address register to mimic Quick. |
| 419 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 420 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 421 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 422 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 423 | switch (type) { |
| 424 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 425 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 426 | X86ManagedRegister pair = |
| 427 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 428 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 429 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 430 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 431 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 432 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 433 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | case Primitive::kPrimByte: |
| 437 | case Primitive::kPrimBoolean: |
| 438 | case Primitive::kPrimChar: |
| 439 | case Primitive::kPrimShort: |
| 440 | case Primitive::kPrimInt: |
| 441 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 442 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 443 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 444 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 445 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 446 | X86ManagedRegister current = |
| 447 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 448 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 449 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 450 | } |
| 451 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 452 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 456 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 457 | return Location::FpuRegisterLocation( |
| 458 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 459 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 460 | |
| 461 | case Primitive::kPrimVoid: |
| 462 | LOG(FATAL) << "Unreachable type " << type; |
| 463 | } |
| 464 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 465 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 466 | } |
| 467 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 468 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 469 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 470 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 471 | |
| 472 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 473 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 474 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 475 | if (is_baseline) { |
| 476 | blocked_core_registers_[EBP] = true; |
| 477 | blocked_core_registers_[ESI] = true; |
| 478 | blocked_core_registers_[EDI] = true; |
| 479 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 480 | |
| 481 | UpdateBlockedPairRegisters(); |
| 482 | } |
| 483 | |
| 484 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 485 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 486 | X86ManagedRegister current = |
| 487 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 488 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 489 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 490 | blocked_register_pairs_[i] = true; |
| 491 | } |
| 492 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 493 | } |
| 494 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 495 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 496 | : HGraphVisitor(graph), |
| 497 | assembler_(codegen->GetAssembler()), |
| 498 | codegen_(codegen) {} |
| 499 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 500 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 501 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 502 | } |
| 503 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 504 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 505 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 506 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 507 | bool skip_overflow_check = |
| 508 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 509 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 510 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 511 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 512 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 513 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 516 | if (HasEmptyFrame()) { |
| 517 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 518 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 519 | |
| 520 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 521 | Register reg = kCoreCalleeSaves[i]; |
| 522 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 523 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 524 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 525 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 529 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 530 | __ subl(ESP, Immediate(adjust)); |
| 531 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 532 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 536 | __ cfi().RememberState(); |
| 537 | if (!HasEmptyFrame()) { |
| 538 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 539 | __ addl(ESP, Immediate(adjust)); |
| 540 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 541 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 542 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 543 | Register reg = kCoreCalleeSaves[i]; |
| 544 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 545 | __ popl(reg); |
| 546 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 547 | __ cfi().Restore(DWARFReg(reg)); |
| 548 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 549 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 550 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 551 | __ ret(); |
| 552 | __ cfi().RestoreState(); |
| 553 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 556 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 557 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 560 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 561 | switch (load->GetType()) { |
| 562 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 563 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 564 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 565 | |
| 566 | case Primitive::kPrimInt: |
| 567 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 568 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 569 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 570 | |
| 571 | case Primitive::kPrimBoolean: |
| 572 | case Primitive::kPrimByte: |
| 573 | case Primitive::kPrimChar: |
| 574 | case Primitive::kPrimShort: |
| 575 | case Primitive::kPrimVoid: |
| 576 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 577 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 581 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 582 | } |
| 583 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 584 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 585 | switch (type) { |
| 586 | case Primitive::kPrimBoolean: |
| 587 | case Primitive::kPrimByte: |
| 588 | case Primitive::kPrimChar: |
| 589 | case Primitive::kPrimShort: |
| 590 | case Primitive::kPrimInt: |
| 591 | case Primitive::kPrimNot: |
| 592 | return Location::RegisterLocation(EAX); |
| 593 | |
| 594 | case Primitive::kPrimLong: |
| 595 | return Location::RegisterPairLocation(EAX, EDX); |
| 596 | |
| 597 | case Primitive::kPrimVoid: |
| 598 | return Location::NoLocation(); |
| 599 | |
| 600 | case Primitive::kPrimDouble: |
| 601 | case Primitive::kPrimFloat: |
| 602 | return Location::FpuRegisterLocation(XMM0); |
| 603 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 604 | |
| 605 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 609 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 610 | } |
| 611 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 612 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 613 | switch (type) { |
| 614 | case Primitive::kPrimBoolean: |
| 615 | case Primitive::kPrimByte: |
| 616 | case Primitive::kPrimChar: |
| 617 | case Primitive::kPrimShort: |
| 618 | case Primitive::kPrimInt: |
| 619 | case Primitive::kPrimNot: { |
| 620 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 621 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 622 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 623 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 624 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 625 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 626 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 627 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 628 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 629 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 630 | uint32_t index = gp_index_; |
| 631 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 632 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 633 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 634 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 635 | calling_convention.GetRegisterPairAt(index)); |
| 636 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 637 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 638 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 643 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 644 | stack_index_++; |
| 645 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 646 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 647 | } else { |
| 648 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 653 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 654 | stack_index_ += 2; |
| 655 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 656 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 657 | } else { |
| 658 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 662 | case Primitive::kPrimVoid: |
| 663 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 664 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 665 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 666 | return Location(); |
| 667 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 668 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 669 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 670 | if (source.Equals(destination)) { |
| 671 | return; |
| 672 | } |
| 673 | if (destination.IsRegister()) { |
| 674 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 675 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 676 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 677 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 678 | } else { |
| 679 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 680 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 681 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 682 | } else if (destination.IsFpuRegister()) { |
| 683 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 684 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 685 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 686 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 687 | } else { |
| 688 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 689 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 690 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 691 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 692 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 693 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 694 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 695 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 696 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 697 | } else if (source.IsConstant()) { |
| 698 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 699 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 700 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 701 | } else { |
| 702 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 703 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 704 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 710 | if (source.Equals(destination)) { |
| 711 | return; |
| 712 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 713 | if (destination.IsRegisterPair()) { |
| 714 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 715 | EmitParallelMoves( |
| 716 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 717 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 718 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 719 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 720 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 721 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 722 | } else if (source.IsFpuRegister()) { |
| 723 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 724 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 725 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 726 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 727 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 728 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 729 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 730 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 731 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 732 | if (source.IsFpuRegister()) { |
| 733 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 734 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 735 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 736 | } else { |
| 737 | LOG(FATAL) << "Unimplemented"; |
| 738 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 739 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 740 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 741 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 742 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 743 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 744 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 745 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 746 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 747 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 748 | } else if (source.IsConstant()) { |
| 749 | HConstant* constant = source.GetConstant(); |
| 750 | int64_t value; |
| 751 | if (constant->IsLongConstant()) { |
| 752 | value = constant->AsLongConstant()->GetValue(); |
| 753 | } else { |
| 754 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 755 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 756 | } |
| 757 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 758 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 759 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 760 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 761 | EmitParallelMoves( |
| 762 | Location::StackSlot(source.GetStackIndex()), |
| 763 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 764 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 765 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 766 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 767 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | } |
| 771 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 772 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 773 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 774 | if (instruction->IsCurrentMethod()) { |
| 775 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 776 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 777 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 778 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 779 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 780 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 781 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 782 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 783 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 784 | } else if (location.IsStackSlot()) { |
| 785 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 786 | } else { |
| 787 | DCHECK(location.IsConstant()); |
| 788 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 789 | } |
| 790 | } else if (const_to_move->IsLongConstant()) { |
| 791 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 792 | if (location.IsRegisterPair()) { |
| 793 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 794 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 795 | } else if (location.IsDoubleStackSlot()) { |
| 796 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 797 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 798 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 799 | } else { |
| 800 | DCHECK(location.IsConstant()); |
| 801 | DCHECK_EQ(location.GetConstant(), instruction); |
| 802 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 803 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 804 | } else if (instruction->IsTemporary()) { |
| 805 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 806 | if (temp_location.IsStackSlot()) { |
| 807 | Move32(location, temp_location); |
| 808 | } else { |
| 809 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 810 | Move64(location, temp_location); |
| 811 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 812 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 813 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 814 | switch (instruction->GetType()) { |
| 815 | case Primitive::kPrimBoolean: |
| 816 | case Primitive::kPrimByte: |
| 817 | case Primitive::kPrimChar: |
| 818 | case Primitive::kPrimShort: |
| 819 | case Primitive::kPrimInt: |
| 820 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 821 | case Primitive::kPrimFloat: |
| 822 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 823 | break; |
| 824 | |
| 825 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 826 | case Primitive::kPrimDouble: |
| 827 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 828 | break; |
| 829 | |
| 830 | default: |
| 831 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 832 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 833 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 834 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 835 | switch (instruction->GetType()) { |
| 836 | case Primitive::kPrimBoolean: |
| 837 | case Primitive::kPrimByte: |
| 838 | case Primitive::kPrimChar: |
| 839 | case Primitive::kPrimShort: |
| 840 | case Primitive::kPrimInt: |
| 841 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 842 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 843 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 844 | break; |
| 845 | |
| 846 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 847 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 848 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 852 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 853 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 857 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 858 | DCHECK(!successor->IsExitBlock()); |
| 859 | |
| 860 | HBasicBlock* block = got->GetBlock(); |
| 861 | HInstruction* previous = got->GetPrevious(); |
| 862 | |
| 863 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 864 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 865 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 870 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 871 | } |
| 872 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 873 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 877 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 878 | got->SetLocations(nullptr); |
| 879 | } |
| 880 | |
| 881 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 882 | HandleGoto(got, got->GetSuccessor()); |
| 883 | } |
| 884 | |
| 885 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 886 | try_boundary->SetLocations(nullptr); |
| 887 | } |
| 888 | |
| 889 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 890 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 891 | if (!successor->IsExitBlock()) { |
| 892 | HandleGoto(try_boundary, successor); |
| 893 | } |
| 894 | } |
| 895 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 896 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 897 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 898 | } |
| 899 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 900 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 901 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 904 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 905 | Label* true_label, |
| 906 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 907 | if (cond->IsFPConditionTrueIfNaN()) { |
| 908 | __ j(kUnordered, true_label); |
| 909 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 910 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 911 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 912 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 916 | Label* true_label, |
| 917 | Label* false_label) { |
| 918 | LocationSummary* locations = cond->GetLocations(); |
| 919 | Location left = locations->InAt(0); |
| 920 | Location right = locations->InAt(1); |
| 921 | IfCondition if_cond = cond->GetCondition(); |
| 922 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 923 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 924 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 925 | IfCondition true_high_cond = if_cond; |
| 926 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 927 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 928 | |
| 929 | // Set the conditions for the test, remembering that == needs to be |
| 930 | // decided using the low words. |
| 931 | switch (if_cond) { |
| 932 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 933 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 934 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 935 | break; |
| 936 | case kCondLT: |
| 937 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 938 | break; |
| 939 | case kCondLE: |
| 940 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 941 | break; |
| 942 | case kCondGT: |
| 943 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 944 | break; |
| 945 | case kCondGE: |
| 946 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 947 | break; |
| 948 | } |
| 949 | |
| 950 | if (right.IsConstant()) { |
| 951 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 952 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 953 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 954 | |
| 955 | if (val_high == 0) { |
| 956 | __ testl(left_high, left_high); |
| 957 | } else { |
| 958 | __ cmpl(left_high, Immediate(val_high)); |
| 959 | } |
| 960 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 961 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 962 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 963 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 964 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 965 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 966 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 967 | } |
| 968 | // Must be equal high, so compare the lows. |
| 969 | if (val_low == 0) { |
| 970 | __ testl(left_low, left_low); |
| 971 | } else { |
| 972 | __ cmpl(left_low, Immediate(val_low)); |
| 973 | } |
| 974 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 975 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 976 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 977 | |
| 978 | __ cmpl(left_high, right_high); |
| 979 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 980 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 981 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 982 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 983 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 984 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 985 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 986 | } |
| 987 | // Must be equal high, so compare the lows. |
| 988 | __ cmpl(left_low, right_low); |
| 989 | } |
| 990 | // The last comparison might be unsigned. |
| 991 | __ j(final_condition, true_label); |
| 992 | } |
| 993 | |
| 994 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HIf* if_instr, |
| 995 | HCondition* condition, |
| 996 | Label* true_target, |
| 997 | Label* false_target, |
| 998 | Label* always_true_target) { |
| 999 | LocationSummary* locations = condition->GetLocations(); |
| 1000 | Location left = locations->InAt(0); |
| 1001 | Location right = locations->InAt(1); |
| 1002 | |
| 1003 | // We don't want true_target as a nullptr. |
| 1004 | if (true_target == nullptr) { |
| 1005 | true_target = always_true_target; |
| 1006 | } |
| 1007 | bool falls_through = (false_target == nullptr); |
| 1008 | |
| 1009 | // FP compares don't like null false_targets. |
| 1010 | if (false_target == nullptr) { |
| 1011 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1012 | } |
| 1013 | |
| 1014 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1015 | switch (type) { |
| 1016 | case Primitive::kPrimLong: |
| 1017 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1018 | break; |
| 1019 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1020 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1021 | GenerateFPJumps(condition, true_target, false_target); |
| 1022 | break; |
| 1023 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1024 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1025 | GenerateFPJumps(condition, true_target, false_target); |
| 1026 | break; |
| 1027 | default: |
| 1028 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1029 | } |
| 1030 | |
| 1031 | if (!falls_through) { |
| 1032 | __ jmp(false_target); |
| 1033 | } |
| 1034 | } |
| 1035 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1036 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| 1037 | Label* true_target, |
| 1038 | Label* false_target, |
| 1039 | Label* always_true_target) { |
| 1040 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1041 | if (cond->IsIntConstant()) { |
| 1042 | // Constant condition, statically compared against 1. |
| 1043 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1044 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1045 | if (always_true_target != nullptr) { |
| 1046 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1047 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1048 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1049 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1050 | DCHECK_EQ(cond_value, 0); |
| 1051 | } |
| 1052 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1053 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1054 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1055 | // Moves do not affect the eflags register, so if the condition is |
| 1056 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1057 | // again. We can't use the eflags on long/FP conditions if they are |
| 1058 | // materialized due to the complex branching. |
| 1059 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1060 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1061 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1062 | && (type != Primitive::kPrimLong && !Primitive::IsFloatingPointType(type)); |
| 1063 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1064 | if (!eflags_set) { |
| 1065 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1066 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1067 | if (lhs.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1068 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1069 | } else { |
| 1070 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1071 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1072 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1073 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1074 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1075 | } |
| 1076 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1077 | // Condition has not been materialized, use its inputs as the |
| 1078 | // comparison and its condition as the branch condition. |
| 1079 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1080 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1081 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1082 | // Generate the comparison directly. |
| 1083 | GenerateCompareTestAndBranch(instruction->AsIf(), |
| 1084 | cond->AsCondition(), |
| 1085 | true_target, |
| 1086 | false_target, |
| 1087 | always_true_target); |
| 1088 | return; |
| 1089 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1090 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1091 | Location lhs = cond->GetLocations()->InAt(0); |
| 1092 | Location rhs = cond->GetLocations()->InAt(1); |
| 1093 | // LHS is guaranteed to be in a register (see |
| 1094 | // LocationsBuilderX86::VisitCondition). |
| 1095 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1096 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1097 | } else if (rhs.IsConstant()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame] | 1098 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1099 | if (constant == 0) { |
| 1100 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1101 | } else { |
| 1102 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1103 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1104 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1105 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1106 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1107 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1108 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1109 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1110 | if (false_target != nullptr) { |
| 1111 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1115 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| 1116 | LocationSummary* locations = |
| 1117 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1118 | HInstruction* cond = if_instr->InputAt(0); |
| 1119 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1120 | locations->SetInAt(0, Location::Any()); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| 1125 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1126 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1127 | Label* always_true_target = true_target; |
| 1128 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1129 | if_instr->IfTrueSuccessor())) { |
| 1130 | always_true_target = nullptr; |
| 1131 | } |
| 1132 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1133 | if_instr->IfFalseSuccessor())) { |
| 1134 | false_target = nullptr; |
| 1135 | } |
| 1136 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1137 | } |
| 1138 | |
| 1139 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1140 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1141 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1142 | HInstruction* cond = deoptimize->InputAt(0); |
| 1143 | DCHECK(cond->IsCondition()); |
| 1144 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1145 | locations->SetInAt(0, Location::Any()); |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1150 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) |
| 1151 | DeoptimizationSlowPathX86(deoptimize); |
| 1152 | codegen_->AddSlowPath(slow_path); |
| 1153 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1154 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1155 | } |
| 1156 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1157 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1158 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1161 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1162 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1165 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1166 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1169 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1170 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1171 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1174 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1175 | LocationSummary* locations = |
| 1176 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1177 | switch (store->InputAt(1)->GetType()) { |
| 1178 | case Primitive::kPrimBoolean: |
| 1179 | case Primitive::kPrimByte: |
| 1180 | case Primitive::kPrimChar: |
| 1181 | case Primitive::kPrimShort: |
| 1182 | case Primitive::kPrimInt: |
| 1183 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1184 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1185 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1186 | break; |
| 1187 | |
| 1188 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1189 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1190 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1191 | break; |
| 1192 | |
| 1193 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1194 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->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::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1199 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1202 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1203 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1204 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1205 | // Handle the long/FP comparisons made in instruction simplification. |
| 1206 | switch (cond->InputAt(0)->GetType()) { |
| 1207 | case Primitive::kPrimLong: { |
| 1208 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1209 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1210 | if (cond->NeedsMaterialization()) { |
| 1211 | locations->SetOut(Location::RequiresRegister()); |
| 1212 | } |
| 1213 | break; |
| 1214 | } |
| 1215 | case Primitive::kPrimFloat: |
| 1216 | case Primitive::kPrimDouble: { |
| 1217 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1218 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1219 | if (cond->NeedsMaterialization()) { |
| 1220 | locations->SetOut(Location::RequiresRegister()); |
| 1221 | } |
| 1222 | break; |
| 1223 | } |
| 1224 | default: |
| 1225 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1226 | locations->SetInAt(1, Location::Any()); |
| 1227 | if (cond->NeedsMaterialization()) { |
| 1228 | // We need a byte register. |
| 1229 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1230 | } |
| 1231 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1232 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1235 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1236 | if (!cond->NeedsMaterialization()) { |
| 1237 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1238 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1239 | |
| 1240 | LocationSummary* locations = cond->GetLocations(); |
| 1241 | Location lhs = locations->InAt(0); |
| 1242 | Location rhs = locations->InAt(1); |
| 1243 | Register reg = locations->Out().AsRegister<Register>(); |
| 1244 | Label true_label, false_label; |
| 1245 | |
| 1246 | switch (cond->InputAt(0)->GetType()) { |
| 1247 | default: { |
| 1248 | // Integer case. |
| 1249 | |
| 1250 | // Clear output register: setcc only sets the low byte. |
| 1251 | __ xorl(reg, reg); |
| 1252 | |
| 1253 | if (rhs.IsRegister()) { |
| 1254 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1255 | } else if (rhs.IsConstant()) { |
| 1256 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1257 | if (constant == 0) { |
| 1258 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1259 | } else { |
| 1260 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1261 | } |
| 1262 | } else { |
| 1263 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1264 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1265 | __ setb(X86SignedCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1266 | return; |
| 1267 | } |
| 1268 | case Primitive::kPrimLong: |
| 1269 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1270 | break; |
| 1271 | case Primitive::kPrimFloat: |
| 1272 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1273 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1274 | break; |
| 1275 | case Primitive::kPrimDouble: |
| 1276 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1277 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1278 | break; |
| 1279 | } |
| 1280 | |
| 1281 | // Convert the jumps into the result. |
| 1282 | Label done_label; |
| 1283 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1284 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1285 | __ Bind(&false_label); |
| 1286 | __ xorl(reg, reg); |
| 1287 | __ jmp(&done_label); |
| 1288 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1289 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1290 | __ Bind(&true_label); |
| 1291 | __ movl(reg, Immediate(1)); |
| 1292 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1296 | VisitCondition(comp); |
| 1297 | } |
| 1298 | |
| 1299 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1300 | VisitCondition(comp); |
| 1301 | } |
| 1302 | |
| 1303 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1304 | VisitCondition(comp); |
| 1305 | } |
| 1306 | |
| 1307 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1308 | VisitCondition(comp); |
| 1309 | } |
| 1310 | |
| 1311 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1312 | VisitCondition(comp); |
| 1313 | } |
| 1314 | |
| 1315 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1316 | VisitCondition(comp); |
| 1317 | } |
| 1318 | |
| 1319 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1320 | VisitCondition(comp); |
| 1321 | } |
| 1322 | |
| 1323 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1324 | VisitCondition(comp); |
| 1325 | } |
| 1326 | |
| 1327 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1328 | VisitCondition(comp); |
| 1329 | } |
| 1330 | |
| 1331 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1332 | VisitCondition(comp); |
| 1333 | } |
| 1334 | |
| 1335 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1336 | VisitCondition(comp); |
| 1337 | } |
| 1338 | |
| 1339 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1340 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1344 | LocationSummary* locations = |
| 1345 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1346 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1349 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1350 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1351 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1354 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1355 | LocationSummary* locations = |
| 1356 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1357 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1358 | } |
| 1359 | |
| 1360 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant) { |
| 1361 | // Will be generated at use site. |
| 1362 | UNUSED(constant); |
| 1363 | } |
| 1364 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1365 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1366 | LocationSummary* locations = |
| 1367 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1368 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 1372 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1373 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1376 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1377 | LocationSummary* locations = |
| 1378 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1379 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1380 | } |
| 1381 | |
| 1382 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1383 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1384 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1388 | LocationSummary* locations = |
| 1389 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1390 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1391 | } |
| 1392 | |
| 1393 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1394 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1395 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1398 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1399 | memory_barrier->SetLocations(nullptr); |
| 1400 | } |
| 1401 | |
| 1402 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1403 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1404 | } |
| 1405 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1406 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1407 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1410 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1411 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1412 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1415 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1416 | LocationSummary* locations = |
| 1417 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1418 | switch (ret->InputAt(0)->GetType()) { |
| 1419 | case Primitive::kPrimBoolean: |
| 1420 | case Primitive::kPrimByte: |
| 1421 | case Primitive::kPrimChar: |
| 1422 | case Primitive::kPrimShort: |
| 1423 | case Primitive::kPrimInt: |
| 1424 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1425 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1426 | break; |
| 1427 | |
| 1428 | case Primitive::kPrimLong: |
| 1429 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1430 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1431 | break; |
| 1432 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1433 | case Primitive::kPrimFloat: |
| 1434 | case Primitive::kPrimDouble: |
| 1435 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1436 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1437 | break; |
| 1438 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1439 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1440 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1441 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1444 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1445 | if (kIsDebugBuild) { |
| 1446 | switch (ret->InputAt(0)->GetType()) { |
| 1447 | case Primitive::kPrimBoolean: |
| 1448 | case Primitive::kPrimByte: |
| 1449 | case Primitive::kPrimChar: |
| 1450 | case Primitive::kPrimShort: |
| 1451 | case Primitive::kPrimInt: |
| 1452 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1453 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1454 | break; |
| 1455 | |
| 1456 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1457 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1458 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1459 | break; |
| 1460 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1461 | case Primitive::kPrimFloat: |
| 1462 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1463 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1464 | break; |
| 1465 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1466 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1467 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1468 | } |
| 1469 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1470 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1473 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1474 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1475 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1476 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1477 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1478 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1479 | if (intrinsic.TryDispatch(invoke)) { |
| 1480 | return; |
| 1481 | } |
| 1482 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1483 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1484 | |
| 1485 | if (codegen_->IsBaseline()) { |
| 1486 | // Baseline does not have enough registers if the current method also |
| 1487 | // needs a register. We therefore do not require a register for it, and let |
| 1488 | // the code generation of the invoke handle it. |
| 1489 | LocationSummary* locations = invoke->GetLocations(); |
| 1490 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 1491 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 1492 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 1493 | } |
| 1494 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1495 | } |
| 1496 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1497 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1498 | if (invoke->GetLocations()->Intrinsified()) { |
| 1499 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1500 | intrinsic.Dispatch(invoke); |
| 1501 | return true; |
| 1502 | } |
| 1503 | return false; |
| 1504 | } |
| 1505 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1506 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1507 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1508 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1509 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1510 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1511 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1512 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1513 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1514 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1515 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1516 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1517 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1518 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1522 | HandleInvoke(invoke); |
| 1523 | } |
| 1524 | |
| 1525 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1526 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1527 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1530 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1531 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1532 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1533 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1534 | LocationSummary* locations = invoke->GetLocations(); |
| 1535 | Location receiver = locations->InAt(0); |
| 1536 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1537 | // temp = object->GetClass(); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1538 | DCHECK(receiver.IsRegister()); |
| 1539 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1540 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1541 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1542 | // temp = temp->GetMethodAt(method_offset); |
| 1543 | __ movl(temp, Address(temp, method_offset)); |
| 1544 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1545 | __ call(Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1546 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1547 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1548 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1549 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1552 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1553 | HandleInvoke(invoke); |
| 1554 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1555 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1559 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1560 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1561 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1562 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1563 | LocationSummary* locations = invoke->GetLocations(); |
| 1564 | Location receiver = locations->InAt(0); |
| 1565 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1566 | |
| 1567 | // Set the hidden argument. |
| 1568 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1569 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1570 | |
| 1571 | // temp = object->GetClass(); |
| 1572 | if (receiver.IsStackSlot()) { |
| 1573 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1574 | __ movl(temp, Address(temp, class_offset)); |
| 1575 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1576 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1577 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1578 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1579 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1580 | // temp = temp->GetImtEntryAt(method_offset); |
| 1581 | __ movl(temp, Address(temp, method_offset)); |
| 1582 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1583 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1584 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1585 | |
| 1586 | DCHECK(!codegen_->IsLeafMethod()); |
| 1587 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1588 | } |
| 1589 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1590 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1591 | LocationSummary* locations = |
| 1592 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1593 | switch (neg->GetResultType()) { |
| 1594 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1595 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1596 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1597 | locations->SetOut(Location::SameAsFirstInput()); |
| 1598 | break; |
| 1599 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1600 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1601 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1602 | locations->SetOut(Location::SameAsFirstInput()); |
| 1603 | locations->AddTemp(Location::RequiresRegister()); |
| 1604 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1605 | break; |
| 1606 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1607 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1608 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1609 | locations->SetOut(Location::SameAsFirstInput()); |
| 1610 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1611 | break; |
| 1612 | |
| 1613 | default: |
| 1614 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1619 | LocationSummary* locations = neg->GetLocations(); |
| 1620 | Location out = locations->Out(); |
| 1621 | Location in = locations->InAt(0); |
| 1622 | switch (neg->GetResultType()) { |
| 1623 | case Primitive::kPrimInt: |
| 1624 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1625 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1626 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1627 | break; |
| 1628 | |
| 1629 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1630 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1631 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1632 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1633 | // Negation is similar to subtraction from zero. The least |
| 1634 | // significant byte triggers a borrow when it is different from |
| 1635 | // zero; to take it into account, add 1 to the most significant |
| 1636 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1637 | // operation. |
| 1638 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1639 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1640 | break; |
| 1641 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1642 | case Primitive::kPrimFloat: { |
| 1643 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1644 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1645 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1646 | // Implement float negation with an exclusive or with value |
| 1647 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1648 | // single-precision floating-point number). |
| 1649 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1650 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1651 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1652 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1653 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1654 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1655 | case Primitive::kPrimDouble: { |
| 1656 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1657 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1658 | // Implement double negation with an exclusive or with value |
| 1659 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1660 | // a double-precision floating-point number). |
| 1661 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1662 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1663 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1664 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1665 | |
| 1666 | default: |
| 1667 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1668 | } |
| 1669 | } |
| 1670 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1671 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1672 | Primitive::Type result_type = conversion->GetResultType(); |
| 1673 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1674 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1675 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1676 | // The float-to-long and double-to-long type conversions rely on a |
| 1677 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1678 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1679 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1680 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1681 | ? LocationSummary::kCall |
| 1682 | : LocationSummary::kNoCall; |
| 1683 | LocationSummary* locations = |
| 1684 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1685 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1686 | // The Java language does not allow treating boolean as an integral type but |
| 1687 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1688 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1689 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1690 | case Primitive::kPrimByte: |
| 1691 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1692 | case Primitive::kPrimBoolean: |
| 1693 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1694 | case Primitive::kPrimShort: |
| 1695 | case Primitive::kPrimInt: |
| 1696 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1697 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1698 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1699 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1700 | // the validation of the linear scan implementation |
| 1701 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1702 | break; |
| 1703 | |
| 1704 | default: |
| 1705 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1706 | << " to " << result_type; |
| 1707 | } |
| 1708 | break; |
| 1709 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1710 | case Primitive::kPrimShort: |
| 1711 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1712 | case Primitive::kPrimBoolean: |
| 1713 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1714 | case Primitive::kPrimByte: |
| 1715 | case Primitive::kPrimInt: |
| 1716 | case Primitive::kPrimChar: |
| 1717 | // Processing a Dex `int-to-short' instruction. |
| 1718 | locations->SetInAt(0, Location::Any()); |
| 1719 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1720 | break; |
| 1721 | |
| 1722 | default: |
| 1723 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1724 | << " to " << result_type; |
| 1725 | } |
| 1726 | break; |
| 1727 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1728 | case Primitive::kPrimInt: |
| 1729 | switch (input_type) { |
| 1730 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1731 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1732 | locations->SetInAt(0, Location::Any()); |
| 1733 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1734 | break; |
| 1735 | |
| 1736 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1737 | // Processing a Dex `float-to-int' instruction. |
| 1738 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1739 | locations->SetOut(Location::RequiresRegister()); |
| 1740 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1741 | break; |
| 1742 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1743 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1744 | // Processing a Dex `double-to-int' instruction. |
| 1745 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1746 | locations->SetOut(Location::RequiresRegister()); |
| 1747 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1748 | break; |
| 1749 | |
| 1750 | default: |
| 1751 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1752 | << " to " << result_type; |
| 1753 | } |
| 1754 | break; |
| 1755 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1756 | case Primitive::kPrimLong: |
| 1757 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1758 | case Primitive::kPrimBoolean: |
| 1759 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1760 | case Primitive::kPrimByte: |
| 1761 | case Primitive::kPrimShort: |
| 1762 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1763 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1764 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1765 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1766 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1767 | break; |
| 1768 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1769 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1770 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1771 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1772 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1773 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1774 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1775 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1776 | // The runtime helper puts the result in EAX, EDX. |
| 1777 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1778 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1779 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1780 | |
| 1781 | default: |
| 1782 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1783 | << " to " << result_type; |
| 1784 | } |
| 1785 | break; |
| 1786 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1787 | case Primitive::kPrimChar: |
| 1788 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1789 | case Primitive::kPrimBoolean: |
| 1790 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1791 | case Primitive::kPrimByte: |
| 1792 | case Primitive::kPrimShort: |
| 1793 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1794 | // Processing a Dex `int-to-char' instruction. |
| 1795 | locations->SetInAt(0, Location::Any()); |
| 1796 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1797 | break; |
| 1798 | |
| 1799 | default: |
| 1800 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1801 | << " to " << result_type; |
| 1802 | } |
| 1803 | break; |
| 1804 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1805 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1806 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1807 | case Primitive::kPrimBoolean: |
| 1808 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1809 | case Primitive::kPrimByte: |
| 1810 | case Primitive::kPrimShort: |
| 1811 | case Primitive::kPrimInt: |
| 1812 | case Primitive::kPrimChar: |
| 1813 | // Processing a Dex `int-to-float' instruction. |
| 1814 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1815 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1816 | break; |
| 1817 | |
| 1818 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1819 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1820 | locations->SetInAt(0, Location::Any()); |
| 1821 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1822 | break; |
| 1823 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1824 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1825 | // Processing a Dex `double-to-float' instruction. |
| 1826 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1827 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1828 | break; |
| 1829 | |
| 1830 | default: |
| 1831 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1832 | << " to " << result_type; |
| 1833 | }; |
| 1834 | break; |
| 1835 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1836 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1837 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1838 | case Primitive::kPrimBoolean: |
| 1839 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1840 | case Primitive::kPrimByte: |
| 1841 | case Primitive::kPrimShort: |
| 1842 | case Primitive::kPrimInt: |
| 1843 | case Primitive::kPrimChar: |
| 1844 | // Processing a Dex `int-to-double' instruction. |
| 1845 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1846 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1847 | break; |
| 1848 | |
| 1849 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1850 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1851 | locations->SetInAt(0, Location::Any()); |
| 1852 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1853 | break; |
| 1854 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1855 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1856 | // Processing a Dex `float-to-double' instruction. |
| 1857 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1858 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1859 | break; |
| 1860 | |
| 1861 | default: |
| 1862 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1863 | << " to " << result_type; |
| 1864 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1865 | break; |
| 1866 | |
| 1867 | default: |
| 1868 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1869 | << " to " << result_type; |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1874 | LocationSummary* locations = conversion->GetLocations(); |
| 1875 | Location out = locations->Out(); |
| 1876 | Location in = locations->InAt(0); |
| 1877 | Primitive::Type result_type = conversion->GetResultType(); |
| 1878 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1879 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1880 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1881 | case Primitive::kPrimByte: |
| 1882 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1883 | case Primitive::kPrimBoolean: |
| 1884 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1885 | case Primitive::kPrimShort: |
| 1886 | case Primitive::kPrimInt: |
| 1887 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1888 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1889 | if (in.IsRegister()) { |
| 1890 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1891 | } else { |
| 1892 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1893 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1894 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 1895 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1896 | break; |
| 1897 | |
| 1898 | default: |
| 1899 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1900 | << " to " << result_type; |
| 1901 | } |
| 1902 | break; |
| 1903 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1904 | case Primitive::kPrimShort: |
| 1905 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1906 | case Primitive::kPrimBoolean: |
| 1907 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1908 | case Primitive::kPrimByte: |
| 1909 | case Primitive::kPrimInt: |
| 1910 | case Primitive::kPrimChar: |
| 1911 | // Processing a Dex `int-to-short' instruction. |
| 1912 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1913 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1914 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1915 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1916 | } else { |
| 1917 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1918 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1919 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1920 | } |
| 1921 | break; |
| 1922 | |
| 1923 | default: |
| 1924 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1925 | << " to " << result_type; |
| 1926 | } |
| 1927 | break; |
| 1928 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1929 | case Primitive::kPrimInt: |
| 1930 | switch (input_type) { |
| 1931 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1932 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1933 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1934 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1935 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1936 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1937 | } else { |
| 1938 | DCHECK(in.IsConstant()); |
| 1939 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1940 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1941 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1942 | } |
| 1943 | break; |
| 1944 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1945 | case Primitive::kPrimFloat: { |
| 1946 | // Processing a Dex `float-to-int' instruction. |
| 1947 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1948 | Register output = out.AsRegister<Register>(); |
| 1949 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1950 | Label done, nan; |
| 1951 | |
| 1952 | __ movl(output, Immediate(kPrimIntMax)); |
| 1953 | // temp = int-to-float(output) |
| 1954 | __ cvtsi2ss(temp, output); |
| 1955 | // if input >= temp goto done |
| 1956 | __ comiss(input, temp); |
| 1957 | __ j(kAboveEqual, &done); |
| 1958 | // if input == NaN goto nan |
| 1959 | __ j(kUnordered, &nan); |
| 1960 | // output = float-to-int-truncate(input) |
| 1961 | __ cvttss2si(output, input); |
| 1962 | __ jmp(&done); |
| 1963 | __ Bind(&nan); |
| 1964 | // output = 0 |
| 1965 | __ xorl(output, output); |
| 1966 | __ Bind(&done); |
| 1967 | break; |
| 1968 | } |
| 1969 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1970 | case Primitive::kPrimDouble: { |
| 1971 | // Processing a Dex `double-to-int' instruction. |
| 1972 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1973 | Register output = out.AsRegister<Register>(); |
| 1974 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1975 | Label done, nan; |
| 1976 | |
| 1977 | __ movl(output, Immediate(kPrimIntMax)); |
| 1978 | // temp = int-to-double(output) |
| 1979 | __ cvtsi2sd(temp, output); |
| 1980 | // if input >= temp goto done |
| 1981 | __ comisd(input, temp); |
| 1982 | __ j(kAboveEqual, &done); |
| 1983 | // if input == NaN goto nan |
| 1984 | __ j(kUnordered, &nan); |
| 1985 | // output = double-to-int-truncate(input) |
| 1986 | __ cvttsd2si(output, input); |
| 1987 | __ jmp(&done); |
| 1988 | __ Bind(&nan); |
| 1989 | // output = 0 |
| 1990 | __ xorl(output, output); |
| 1991 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1992 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1993 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1994 | |
| 1995 | default: |
| 1996 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1997 | << " to " << result_type; |
| 1998 | } |
| 1999 | break; |
| 2000 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2001 | case Primitive::kPrimLong: |
| 2002 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2003 | case Primitive::kPrimBoolean: |
| 2004 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2005 | case Primitive::kPrimByte: |
| 2006 | case Primitive::kPrimShort: |
| 2007 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2008 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2009 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2010 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2011 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2012 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2013 | __ cdq(); |
| 2014 | break; |
| 2015 | |
| 2016 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2017 | // Processing a Dex `float-to-long' instruction. |
| 2018 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pF2l))); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2019 | codegen_->RecordPcInfo(conversion, conversion->GetDexPc()); |
| 2020 | break; |
| 2021 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2022 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2023 | // Processing a Dex `double-to-long' instruction. |
| 2024 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pD2l))); |
| 2025 | codegen_->RecordPcInfo(conversion, conversion->GetDexPc()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2026 | break; |
| 2027 | |
| 2028 | default: |
| 2029 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2030 | << " to " << result_type; |
| 2031 | } |
| 2032 | break; |
| 2033 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2034 | case Primitive::kPrimChar: |
| 2035 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2036 | case Primitive::kPrimBoolean: |
| 2037 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2038 | case Primitive::kPrimByte: |
| 2039 | case Primitive::kPrimShort: |
| 2040 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2041 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2042 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2043 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2044 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2045 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2046 | } else { |
| 2047 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2048 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2049 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2050 | } |
| 2051 | break; |
| 2052 | |
| 2053 | default: |
| 2054 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2055 | << " to " << result_type; |
| 2056 | } |
| 2057 | break; |
| 2058 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2059 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2060 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2061 | case Primitive::kPrimBoolean: |
| 2062 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2063 | case Primitive::kPrimByte: |
| 2064 | case Primitive::kPrimShort: |
| 2065 | case Primitive::kPrimInt: |
| 2066 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2067 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2068 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2069 | break; |
| 2070 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2071 | case Primitive::kPrimLong: { |
| 2072 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2073 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2074 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2075 | // Create stack space for the call to |
| 2076 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2077 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2078 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2079 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2080 | __ subl(ESP, Immediate(adjustment)); |
| 2081 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2082 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2083 | // Load the value to the FP stack, using temporaries if needed. |
| 2084 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2085 | |
| 2086 | if (out.IsStackSlot()) { |
| 2087 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2088 | } else { |
| 2089 | __ fstps(Address(ESP, 0)); |
| 2090 | Location stack_temp = Location::StackSlot(0); |
| 2091 | codegen_->Move32(out, stack_temp); |
| 2092 | } |
| 2093 | |
| 2094 | // Remove the temporary stack space we allocated. |
| 2095 | if (adjustment != 0) { |
| 2096 | __ addl(ESP, Immediate(adjustment)); |
| 2097 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2098 | break; |
| 2099 | } |
| 2100 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2101 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2102 | // Processing a Dex `double-to-float' instruction. |
| 2103 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2104 | break; |
| 2105 | |
| 2106 | default: |
| 2107 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2108 | << " to " << result_type; |
| 2109 | }; |
| 2110 | break; |
| 2111 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2112 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2113 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2114 | case Primitive::kPrimBoolean: |
| 2115 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2116 | case Primitive::kPrimByte: |
| 2117 | case Primitive::kPrimShort: |
| 2118 | case Primitive::kPrimInt: |
| 2119 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2120 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2121 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2122 | break; |
| 2123 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2124 | case Primitive::kPrimLong: { |
| 2125 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2126 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2127 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2128 | // Create stack space for the call to |
| 2129 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2130 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2131 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2132 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2133 | __ subl(ESP, Immediate(adjustment)); |
| 2134 | } |
| 2135 | |
| 2136 | // Load the value to the FP stack, using temporaries if needed. |
| 2137 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2138 | |
| 2139 | if (out.IsDoubleStackSlot()) { |
| 2140 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2141 | } else { |
| 2142 | __ fstpl(Address(ESP, 0)); |
| 2143 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2144 | codegen_->Move64(out, stack_temp); |
| 2145 | } |
| 2146 | |
| 2147 | // Remove the temporary stack space we allocated. |
| 2148 | if (adjustment != 0) { |
| 2149 | __ addl(ESP, Immediate(adjustment)); |
| 2150 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | } |
| 2153 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2155 | // Processing a Dex `float-to-double' instruction. |
| 2156 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2157 | break; |
| 2158 | |
| 2159 | default: |
| 2160 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2161 | << " to " << result_type; |
| 2162 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2163 | break; |
| 2164 | |
| 2165 | default: |
| 2166 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2167 | << " to " << result_type; |
| 2168 | } |
| 2169 | } |
| 2170 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2171 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2172 | LocationSummary* locations = |
| 2173 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2174 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2175 | case Primitive::kPrimInt: { |
| 2176 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2177 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2178 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2179 | break; |
| 2180 | } |
| 2181 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2182 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2183 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2184 | locations->SetInAt(1, Location::Any()); |
| 2185 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2186 | break; |
| 2187 | } |
| 2188 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2189 | case Primitive::kPrimFloat: |
| 2190 | case Primitive::kPrimDouble: { |
| 2191 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Calin Juravle | 3173c8a | 2015-02-23 15:53:39 +0000 | [diff] [blame] | 2192 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2193 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2194 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2195 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2196 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2197 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2198 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2199 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2200 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2204 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2205 | Location first = locations->InAt(0); |
| 2206 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2207 | Location out = locations->Out(); |
| 2208 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2209 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2210 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2211 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2212 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2213 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2214 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2215 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2216 | } else { |
| 2217 | __ leal(out.AsRegister<Register>(), Address( |
| 2218 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2219 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2220 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2221 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2222 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2223 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2224 | } else { |
| 2225 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2226 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2227 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2228 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2229 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2230 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2231 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2235 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2236 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2237 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2238 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2239 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2240 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2241 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2242 | } else { |
| 2243 | DCHECK(second.IsConstant()) << second; |
| 2244 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2245 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2246 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2247 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2248 | break; |
| 2249 | } |
| 2250 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2251 | case Primitive::kPrimFloat: { |
| 2252 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2253 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2254 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2255 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | case Primitive::kPrimDouble: { |
| 2259 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2260 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2261 | } |
| 2262 | break; |
| 2263 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2264 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2265 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2266 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2270 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2271 | LocationSummary* locations = |
| 2272 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2273 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2274 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2275 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2276 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2277 | locations->SetInAt(1, Location::Any()); |
| 2278 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2279 | break; |
| 2280 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2281 | case Primitive::kPrimFloat: |
| 2282 | case Primitive::kPrimDouble: { |
| 2283 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2284 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2285 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2286 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2287 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2288 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2289 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2290 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2291 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2295 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2296 | Location first = locations->InAt(0); |
| 2297 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2298 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2299 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2300 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2301 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2302 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2303 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2304 | __ subl(first.AsRegister<Register>(), |
| 2305 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2306 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2307 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2308 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2309 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2313 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2314 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2315 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2316 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2317 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2318 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2319 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2320 | } else { |
| 2321 | DCHECK(second.IsConstant()) << second; |
| 2322 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2323 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2324 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2325 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2326 | break; |
| 2327 | } |
| 2328 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2329 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2330 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2331 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2335 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2336 | break; |
| 2337 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2338 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2339 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2340 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2341 | } |
| 2342 | } |
| 2343 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2344 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2345 | LocationSummary* locations = |
| 2346 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2347 | switch (mul->GetResultType()) { |
| 2348 | case Primitive::kPrimInt: |
| 2349 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2350 | locations->SetInAt(1, Location::Any()); |
| 2351 | locations->SetOut(Location::SameAsFirstInput()); |
| 2352 | break; |
| 2353 | case Primitive::kPrimLong: { |
| 2354 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2355 | locations->SetInAt(1, Location::Any()); |
| 2356 | locations->SetOut(Location::SameAsFirstInput()); |
| 2357 | // Needed for imul on 32bits with 64bits output. |
| 2358 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2359 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2360 | break; |
| 2361 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2362 | case Primitive::kPrimFloat: |
| 2363 | case Primitive::kPrimDouble: { |
| 2364 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2365 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2366 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2367 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2368 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2369 | |
| 2370 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2371 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2376 | LocationSummary* locations = mul->GetLocations(); |
| 2377 | Location first = locations->InAt(0); |
| 2378 | Location second = locations->InAt(1); |
| 2379 | DCHECK(first.Equals(locations->Out())); |
| 2380 | |
| 2381 | switch (mul->GetResultType()) { |
| 2382 | case Primitive::kPrimInt: { |
| 2383 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2384 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2385 | } else if (second.IsConstant()) { |
| 2386 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2387 | __ imull(first.AsRegister<Register>(), imm); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2388 | } else { |
| 2389 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2390 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2391 | } |
| 2392 | break; |
| 2393 | } |
| 2394 | |
| 2395 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2396 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2397 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2398 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2399 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2400 | |
| 2401 | DCHECK_EQ(EAX, eax); |
| 2402 | DCHECK_EQ(EDX, edx); |
| 2403 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2404 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2405 | // output: in1 |
| 2406 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2407 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2408 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2409 | if (second.IsConstant()) { |
| 2410 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2411 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2412 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2413 | int32_t low_value = Low32Bits(value); |
| 2414 | int32_t high_value = High32Bits(value); |
| 2415 | Immediate low(low_value); |
| 2416 | Immediate high(high_value); |
| 2417 | |
| 2418 | __ movl(eax, high); |
| 2419 | // eax <- in1.lo * in2.hi |
| 2420 | __ imull(eax, in1_lo); |
| 2421 | // in1.hi <- in1.hi * in2.lo |
| 2422 | __ imull(in1_hi, low); |
| 2423 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2424 | __ addl(in1_hi, eax); |
| 2425 | // move in2_lo to eax to prepare for double precision |
| 2426 | __ movl(eax, low); |
| 2427 | // edx:eax <- in1.lo * in2.lo |
| 2428 | __ mull(in1_lo); |
| 2429 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2430 | __ addl(in1_hi, edx); |
| 2431 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2432 | __ movl(in1_lo, eax); |
| 2433 | } else if (second.IsRegisterPair()) { |
| 2434 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2435 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2436 | |
| 2437 | __ movl(eax, in2_hi); |
| 2438 | // eax <- in1.lo * in2.hi |
| 2439 | __ imull(eax, in1_lo); |
| 2440 | // in1.hi <- in1.hi * in2.lo |
| 2441 | __ imull(in1_hi, in2_lo); |
| 2442 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2443 | __ addl(in1_hi, eax); |
| 2444 | // move in1_lo to eax to prepare for double precision |
| 2445 | __ movl(eax, in1_lo); |
| 2446 | // edx:eax <- in1.lo * in2.lo |
| 2447 | __ mull(in2_lo); |
| 2448 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2449 | __ addl(in1_hi, edx); |
| 2450 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2451 | __ movl(in1_lo, eax); |
| 2452 | } else { |
| 2453 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2454 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2455 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2456 | |
| 2457 | __ movl(eax, in2_hi); |
| 2458 | // eax <- in1.lo * in2.hi |
| 2459 | __ imull(eax, in1_lo); |
| 2460 | // in1.hi <- in1.hi * in2.lo |
| 2461 | __ imull(in1_hi, in2_lo); |
| 2462 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2463 | __ addl(in1_hi, eax); |
| 2464 | // move in1_lo to eax to prepare for double precision |
| 2465 | __ movl(eax, in1_lo); |
| 2466 | // edx:eax <- in1.lo * in2.lo |
| 2467 | __ mull(in2_lo); |
| 2468 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2469 | __ addl(in1_hi, edx); |
| 2470 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2471 | __ movl(in1_lo, eax); |
| 2472 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2473 | |
| 2474 | break; |
| 2475 | } |
| 2476 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2477 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2478 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2479 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2483 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2484 | break; |
| 2485 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2486 | |
| 2487 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2488 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2489 | } |
| 2490 | } |
| 2491 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2492 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 2493 | uint32_t temp_offset, |
| 2494 | uint32_t stack_adjustment, |
| 2495 | bool is_fp, |
| 2496 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2497 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2498 | DCHECK(!is_wide); |
| 2499 | if (is_fp) { |
| 2500 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2501 | } else { |
| 2502 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2503 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2504 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2505 | DCHECK(is_wide); |
| 2506 | if (is_fp) { |
| 2507 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2508 | } else { |
| 2509 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2510 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2511 | } else { |
| 2512 | // 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] | 2513 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2514 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2515 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2516 | if (is_fp) { |
| 2517 | __ flds(Address(ESP, temp_offset)); |
| 2518 | } else { |
| 2519 | __ filds(Address(ESP, temp_offset)); |
| 2520 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2521 | } else { |
| 2522 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2523 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2524 | if (is_fp) { |
| 2525 | __ fldl(Address(ESP, temp_offset)); |
| 2526 | } else { |
| 2527 | __ fildl(Address(ESP, temp_offset)); |
| 2528 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2529 | } |
| 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2534 | Primitive::Type type = rem->GetResultType(); |
| 2535 | bool is_float = type == Primitive::kPrimFloat; |
| 2536 | size_t elem_size = Primitive::ComponentSize(type); |
| 2537 | LocationSummary* locations = rem->GetLocations(); |
| 2538 | Location first = locations->InAt(0); |
| 2539 | Location second = locations->InAt(1); |
| 2540 | Location out = locations->Out(); |
| 2541 | |
| 2542 | // Create stack space for 2 elements. |
| 2543 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2544 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2545 | |
| 2546 | // 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] | 2547 | const bool is_wide = !is_float; |
| 2548 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 2549 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2550 | |
| 2551 | // Loop doing FPREM until we stabilize. |
| 2552 | Label retry; |
| 2553 | __ Bind(&retry); |
| 2554 | __ fprem(); |
| 2555 | |
| 2556 | // Move FP status to AX. |
| 2557 | __ fstsw(); |
| 2558 | |
| 2559 | // And see if the argument reduction is complete. This is signaled by the |
| 2560 | // C2 FPU flag bit set to 0. |
| 2561 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2562 | __ j(kNotEqual, &retry); |
| 2563 | |
| 2564 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2565 | // Store FP top of stack to real stack. |
| 2566 | if (is_float) { |
| 2567 | __ fsts(Address(ESP, 0)); |
| 2568 | } else { |
| 2569 | __ fstl(Address(ESP, 0)); |
| 2570 | } |
| 2571 | |
| 2572 | // Pop the 2 items from the FP stack. |
| 2573 | __ fucompp(); |
| 2574 | |
| 2575 | // Load the value from the stack into an XMM register. |
| 2576 | DCHECK(out.IsFpuRegister()) << out; |
| 2577 | if (is_float) { |
| 2578 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2579 | } else { |
| 2580 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2581 | } |
| 2582 | |
| 2583 | // And remove the temporary stack space we allocated. |
| 2584 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2585 | } |
| 2586 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2587 | |
| 2588 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2589 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2590 | |
| 2591 | LocationSummary* locations = instruction->GetLocations(); |
| 2592 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2593 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2594 | |
| 2595 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2596 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2597 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2598 | |
| 2599 | DCHECK(imm == 1 || imm == -1); |
| 2600 | |
| 2601 | if (instruction->IsRem()) { |
| 2602 | __ xorl(out_register, out_register); |
| 2603 | } else { |
| 2604 | __ movl(out_register, input_register); |
| 2605 | if (imm == -1) { |
| 2606 | __ negl(out_register); |
| 2607 | } |
| 2608 | } |
| 2609 | } |
| 2610 | |
| 2611 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2612 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2613 | LocationSummary* locations = instruction->GetLocations(); |
| 2614 | |
| 2615 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2616 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2617 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2618 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2619 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2620 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2621 | |
| 2622 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2623 | __ testl(input_register, input_register); |
| 2624 | __ cmovl(kGreaterEqual, num, input_register); |
| 2625 | int shift = CTZ(imm); |
| 2626 | __ sarl(num, Immediate(shift)); |
| 2627 | |
| 2628 | if (imm < 0) { |
| 2629 | __ negl(num); |
| 2630 | } |
| 2631 | |
| 2632 | __ movl(out_register, num); |
| 2633 | } |
| 2634 | |
| 2635 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2636 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2637 | |
| 2638 | LocationSummary* locations = instruction->GetLocations(); |
| 2639 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2640 | |
| 2641 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2642 | Register out = locations->Out().AsRegister<Register>(); |
| 2643 | Register num; |
| 2644 | Register edx; |
| 2645 | |
| 2646 | if (instruction->IsDiv()) { |
| 2647 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2648 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2649 | } else { |
| 2650 | edx = locations->Out().AsRegister<Register>(); |
| 2651 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2652 | } |
| 2653 | |
| 2654 | DCHECK_EQ(EAX, eax); |
| 2655 | DCHECK_EQ(EDX, edx); |
| 2656 | if (instruction->IsDiv()) { |
| 2657 | DCHECK_EQ(EAX, out); |
| 2658 | } else { |
| 2659 | DCHECK_EQ(EDX, out); |
| 2660 | } |
| 2661 | |
| 2662 | int64_t magic; |
| 2663 | int shift; |
| 2664 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2665 | |
| 2666 | Label ndiv; |
| 2667 | Label end; |
| 2668 | // If numerator is 0, the result is 0, no computation needed. |
| 2669 | __ testl(eax, eax); |
| 2670 | __ j(kNotEqual, &ndiv); |
| 2671 | |
| 2672 | __ xorl(out, out); |
| 2673 | __ jmp(&end); |
| 2674 | |
| 2675 | __ Bind(&ndiv); |
| 2676 | |
| 2677 | // Save the numerator. |
| 2678 | __ movl(num, eax); |
| 2679 | |
| 2680 | // EAX = magic |
| 2681 | __ movl(eax, Immediate(magic)); |
| 2682 | |
| 2683 | // EDX:EAX = magic * numerator |
| 2684 | __ imull(num); |
| 2685 | |
| 2686 | if (imm > 0 && magic < 0) { |
| 2687 | // EDX += num |
| 2688 | __ addl(edx, num); |
| 2689 | } else if (imm < 0 && magic > 0) { |
| 2690 | __ subl(edx, num); |
| 2691 | } |
| 2692 | |
| 2693 | // Shift if needed. |
| 2694 | if (shift != 0) { |
| 2695 | __ sarl(edx, Immediate(shift)); |
| 2696 | } |
| 2697 | |
| 2698 | // EDX += 1 if EDX < 0 |
| 2699 | __ movl(eax, edx); |
| 2700 | __ shrl(edx, Immediate(31)); |
| 2701 | __ addl(edx, eax); |
| 2702 | |
| 2703 | if (instruction->IsRem()) { |
| 2704 | __ movl(eax, num); |
| 2705 | __ imull(edx, Immediate(imm)); |
| 2706 | __ subl(eax, edx); |
| 2707 | __ movl(edx, eax); |
| 2708 | } else { |
| 2709 | __ movl(eax, edx); |
| 2710 | } |
| 2711 | __ Bind(&end); |
| 2712 | } |
| 2713 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2714 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2715 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2716 | |
| 2717 | LocationSummary* locations = instruction->GetLocations(); |
| 2718 | Location out = locations->Out(); |
| 2719 | Location first = locations->InAt(0); |
| 2720 | Location second = locations->InAt(1); |
| 2721 | bool is_div = instruction->IsDiv(); |
| 2722 | |
| 2723 | switch (instruction->GetResultType()) { |
| 2724 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2725 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2726 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2727 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2728 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2729 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2730 | |
| 2731 | if (imm == 0) { |
| 2732 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2733 | } else if (imm == 1 || imm == -1) { |
| 2734 | DivRemOneOrMinusOne(instruction); |
| 2735 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2736 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2737 | } else { |
| 2738 | DCHECK(imm <= -2 || imm >= 2); |
| 2739 | GenerateDivRemWithAnyConstant(instruction); |
| 2740 | } |
| 2741 | } else { |
| 2742 | SlowPathCodeX86* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2743 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2744 | is_div); |
| 2745 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2746 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2747 | Register second_reg = second.AsRegister<Register>(); |
| 2748 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2749 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2750 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2751 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2752 | __ cmpl(second_reg, Immediate(-1)); |
| 2753 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2754 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2755 | // edx:eax <- sign-extended of eax |
| 2756 | __ cdq(); |
| 2757 | // eax = quotient, edx = remainder |
| 2758 | __ idivl(second_reg); |
| 2759 | __ Bind(slow_path->GetExitLabel()); |
| 2760 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2761 | break; |
| 2762 | } |
| 2763 | |
| 2764 | case Primitive::kPrimLong: { |
| 2765 | InvokeRuntimeCallingConvention calling_convention; |
| 2766 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2767 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2768 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2769 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2770 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2771 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2772 | |
| 2773 | if (is_div) { |
| 2774 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLdiv))); |
| 2775 | } else { |
| 2776 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLmod))); |
| 2777 | } |
| 2778 | uint32_t dex_pc = is_div |
| 2779 | ? instruction->AsDiv()->GetDexPc() |
| 2780 | : instruction->AsRem()->GetDexPc(); |
| 2781 | codegen_->RecordPcInfo(instruction, dex_pc); |
| 2782 | |
| 2783 | break; |
| 2784 | } |
| 2785 | |
| 2786 | default: |
| 2787 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 2788 | } |
| 2789 | } |
| 2790 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2791 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2792 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2793 | ? LocationSummary::kCall |
| 2794 | : LocationSummary::kNoCall; |
| 2795 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2796 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2797 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2798 | case Primitive::kPrimInt: { |
| 2799 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2800 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2801 | locations->SetOut(Location::SameAsFirstInput()); |
| 2802 | // Intel uses edx:eax as the dividend. |
| 2803 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2804 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2805 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 2806 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2807 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2808 | locations->AddTemp(Location::RequiresRegister()); |
| 2809 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2810 | break; |
| 2811 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2812 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2813 | InvokeRuntimeCallingConvention calling_convention; |
| 2814 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2815 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2816 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2817 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2818 | // Runtime helper puts the result in EAX, EDX. |
| 2819 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2820 | break; |
| 2821 | } |
| 2822 | case Primitive::kPrimFloat: |
| 2823 | case Primitive::kPrimDouble: { |
| 2824 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2825 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2826 | locations->SetOut(Location::SameAsFirstInput()); |
| 2827 | break; |
| 2828 | } |
| 2829 | |
| 2830 | default: |
| 2831 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 2836 | LocationSummary* locations = div->GetLocations(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2837 | Location out = locations->Out(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2838 | Location first = locations->InAt(0); |
| 2839 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2840 | |
| 2841 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2842 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2843 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2844 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | } |
| 2847 | |
| 2848 | case Primitive::kPrimFloat: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2849 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2850 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2851 | break; |
| 2852 | } |
| 2853 | |
| 2854 | case Primitive::kPrimDouble: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2855 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2856 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2857 | break; |
| 2858 | } |
| 2859 | |
| 2860 | default: |
| 2861 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2862 | } |
| 2863 | } |
| 2864 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2865 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2866 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2867 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2868 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 2869 | ? LocationSummary::kCall |
| 2870 | : LocationSummary::kNoCall; |
| 2871 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2872 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2873 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2874 | case Primitive::kPrimInt: { |
| 2875 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2876 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2877 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2878 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2879 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 2880 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2881 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2882 | locations->AddTemp(Location::RequiresRegister()); |
| 2883 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2884 | break; |
| 2885 | } |
| 2886 | case Primitive::kPrimLong: { |
| 2887 | InvokeRuntimeCallingConvention calling_convention; |
| 2888 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2889 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2890 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2891 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2892 | // Runtime helper puts the result in EAX, EDX. |
| 2893 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2894 | break; |
| 2895 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2896 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2897 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2898 | locations->SetInAt(0, Location::Any()); |
| 2899 | locations->SetInAt(1, Location::Any()); |
| 2900 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2901 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2902 | break; |
| 2903 | } |
| 2904 | |
| 2905 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2906 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 2911 | Primitive::Type type = rem->GetResultType(); |
| 2912 | switch (type) { |
| 2913 | case Primitive::kPrimInt: |
| 2914 | case Primitive::kPrimLong: { |
| 2915 | GenerateDivRemIntegral(rem); |
| 2916 | break; |
| 2917 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2918 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2919 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2920 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2921 | break; |
| 2922 | } |
| 2923 | default: |
| 2924 | LOG(FATAL) << "Unexpected rem type " << type; |
| 2925 | } |
| 2926 | } |
| 2927 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2928 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2929 | LocationSummary* locations = |
| 2930 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2931 | switch (instruction->GetType()) { |
| 2932 | case Primitive::kPrimInt: { |
| 2933 | locations->SetInAt(0, Location::Any()); |
| 2934 | break; |
| 2935 | } |
| 2936 | case Primitive::kPrimLong: { |
| 2937 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2938 | if (!instruction->IsConstant()) { |
| 2939 | locations->AddTemp(Location::RequiresRegister()); |
| 2940 | } |
| 2941 | break; |
| 2942 | } |
| 2943 | default: |
| 2944 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2945 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2946 | if (instruction->HasUses()) { |
| 2947 | locations->SetOut(Location::SameAsFirstInput()); |
| 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2952 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 2953 | codegen_->AddSlowPath(slow_path); |
| 2954 | |
| 2955 | LocationSummary* locations = instruction->GetLocations(); |
| 2956 | Location value = locations->InAt(0); |
| 2957 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2958 | switch (instruction->GetType()) { |
| 2959 | case Primitive::kPrimInt: { |
| 2960 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2961 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2962 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2963 | } else if (value.IsStackSlot()) { |
| 2964 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 2965 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2966 | } else { |
| 2967 | DCHECK(value.IsConstant()) << value; |
| 2968 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2969 | __ jmp(slow_path->GetEntryLabel()); |
| 2970 | } |
| 2971 | } |
| 2972 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2973 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2974 | case Primitive::kPrimLong: { |
| 2975 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2976 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2977 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 2978 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 2979 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2980 | } else { |
| 2981 | DCHECK(value.IsConstant()) << value; |
| 2982 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2983 | __ jmp(slow_path->GetEntryLabel()); |
| 2984 | } |
| 2985 | } |
| 2986 | break; |
| 2987 | } |
| 2988 | default: |
| 2989 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2990 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2991 | } |
| 2992 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2993 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 2994 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2995 | |
| 2996 | LocationSummary* locations = |
| 2997 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 2998 | |
| 2999 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3000 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3001 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3002 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3003 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3004 | // The shift count needs to be in CL or a constant. |
| 3005 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3006 | locations->SetOut(Location::SameAsFirstInput()); |
| 3007 | break; |
| 3008 | } |
| 3009 | default: |
| 3010 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3015 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3016 | |
| 3017 | LocationSummary* locations = op->GetLocations(); |
| 3018 | Location first = locations->InAt(0); |
| 3019 | Location second = locations->InAt(1); |
| 3020 | DCHECK(first.Equals(locations->Out())); |
| 3021 | |
| 3022 | switch (op->GetResultType()) { |
| 3023 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3024 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3025 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3026 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3027 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3028 | DCHECK_EQ(ECX, second_reg); |
| 3029 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3030 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3031 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3032 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3033 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3034 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3035 | } |
| 3036 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3037 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3038 | if (shift == 0) { |
| 3039 | return; |
| 3040 | } |
| 3041 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3042 | if (op->IsShl()) { |
| 3043 | __ shll(first_reg, imm); |
| 3044 | } else if (op->IsShr()) { |
| 3045 | __ sarl(first_reg, imm); |
| 3046 | } else { |
| 3047 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3048 | } |
| 3049 | } |
| 3050 | break; |
| 3051 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3052 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3053 | if (second.IsRegister()) { |
| 3054 | Register second_reg = second.AsRegister<Register>(); |
| 3055 | DCHECK_EQ(ECX, second_reg); |
| 3056 | if (op->IsShl()) { |
| 3057 | GenerateShlLong(first, second_reg); |
| 3058 | } else if (op->IsShr()) { |
| 3059 | GenerateShrLong(first, second_reg); |
| 3060 | } else { |
| 3061 | GenerateUShrLong(first, second_reg); |
| 3062 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3063 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3064 | // Shift by a constant. |
| 3065 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3066 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3067 | if (shift != 0) { |
| 3068 | if (op->IsShl()) { |
| 3069 | GenerateShlLong(first, shift); |
| 3070 | } else if (op->IsShr()) { |
| 3071 | GenerateShrLong(first, shift); |
| 3072 | } else { |
| 3073 | GenerateUShrLong(first, shift); |
| 3074 | } |
| 3075 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3076 | } |
| 3077 | break; |
| 3078 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3079 | default: |
| 3080 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3081 | } |
| 3082 | } |
| 3083 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3084 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3085 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3086 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3087 | if (shift == 1) { |
| 3088 | // This is just an addition. |
| 3089 | __ addl(low, low); |
| 3090 | __ adcl(high, high); |
| 3091 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3092 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3093 | codegen_->EmitParallelMoves( |
| 3094 | loc.ToLow(), |
| 3095 | loc.ToHigh(), |
| 3096 | Primitive::kPrimInt, |
| 3097 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3098 | loc.ToLow(), |
| 3099 | Primitive::kPrimInt); |
| 3100 | } else if (shift > 32) { |
| 3101 | // Low part becomes 0. High part is low part << (shift-32). |
| 3102 | __ movl(high, low); |
| 3103 | __ shll(high, Immediate(shift - 32)); |
| 3104 | __ xorl(low, low); |
| 3105 | } else { |
| 3106 | // Between 1 and 31. |
| 3107 | __ shld(high, low, Immediate(shift)); |
| 3108 | __ shll(low, Immediate(shift)); |
| 3109 | } |
| 3110 | } |
| 3111 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3112 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| 3113 | Label done; |
| 3114 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3115 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3116 | __ testl(shifter, Immediate(32)); |
| 3117 | __ j(kEqual, &done); |
| 3118 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3119 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3120 | __ Bind(&done); |
| 3121 | } |
| 3122 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3123 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3124 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3125 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3126 | if (shift == 32) { |
| 3127 | // Need to copy the sign. |
| 3128 | DCHECK_NE(low, high); |
| 3129 | __ movl(low, high); |
| 3130 | __ sarl(high, Immediate(31)); |
| 3131 | } else if (shift > 32) { |
| 3132 | DCHECK_NE(low, high); |
| 3133 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3134 | __ movl(low, high); |
| 3135 | __ sarl(high, Immediate(31)); |
| 3136 | __ sarl(low, Immediate(shift - 32)); |
| 3137 | } else { |
| 3138 | // Between 1 and 31. |
| 3139 | __ shrd(low, high, Immediate(shift)); |
| 3140 | __ sarl(high, Immediate(shift)); |
| 3141 | } |
| 3142 | } |
| 3143 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3144 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| 3145 | Label done; |
| 3146 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3147 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3148 | __ testl(shifter, Immediate(32)); |
| 3149 | __ j(kEqual, &done); |
| 3150 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3151 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3152 | __ Bind(&done); |
| 3153 | } |
| 3154 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3155 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3156 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3157 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3158 | if (shift == 32) { |
| 3159 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3160 | codegen_->EmitParallelMoves( |
| 3161 | loc.ToHigh(), |
| 3162 | loc.ToLow(), |
| 3163 | Primitive::kPrimInt, |
| 3164 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3165 | loc.ToHigh(), |
| 3166 | Primitive::kPrimInt); |
| 3167 | } else if (shift > 32) { |
| 3168 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3169 | __ movl(low, high); |
| 3170 | __ shrl(low, Immediate(shift - 32)); |
| 3171 | __ xorl(high, high); |
| 3172 | } else { |
| 3173 | // Between 1 and 31. |
| 3174 | __ shrd(low, high, Immediate(shift)); |
| 3175 | __ shrl(high, Immediate(shift)); |
| 3176 | } |
| 3177 | } |
| 3178 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3179 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| 3180 | Label done; |
| 3181 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3182 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3183 | __ testl(shifter, Immediate(32)); |
| 3184 | __ j(kEqual, &done); |
| 3185 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3186 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3187 | __ Bind(&done); |
| 3188 | } |
| 3189 | |
| 3190 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3191 | HandleShift(shl); |
| 3192 | } |
| 3193 | |
| 3194 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3195 | HandleShift(shl); |
| 3196 | } |
| 3197 | |
| 3198 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3199 | HandleShift(shr); |
| 3200 | } |
| 3201 | |
| 3202 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3203 | HandleShift(shr); |
| 3204 | } |
| 3205 | |
| 3206 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3207 | HandleShift(ushr); |
| 3208 | } |
| 3209 | |
| 3210 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3211 | HandleShift(ushr); |
| 3212 | } |
| 3213 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3214 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3215 | LocationSummary* locations = |
| 3216 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3217 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3218 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3219 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3220 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 3224 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3225 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3226 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3227 | // of poisoning the reference. |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3228 | __ fs()->call(Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint()))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3229 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3230 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3231 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3232 | } |
| 3233 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3234 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3235 | LocationSummary* locations = |
| 3236 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3237 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3238 | InvokeRuntimeCallingConvention calling_convention; |
| 3239 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3240 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3241 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3245 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3246 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 3247 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3248 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3249 | // of poisoning the reference. |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3250 | __ fs()->call(Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint()))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3251 | |
| 3252 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3253 | DCHECK(!codegen_->IsLeafMethod()); |
| 3254 | } |
| 3255 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3256 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3257 | LocationSummary* locations = |
| 3258 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3259 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3260 | if (location.IsStackSlot()) { |
| 3261 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3262 | } else if (location.IsDoubleStackSlot()) { |
| 3263 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3264 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3265 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3266 | } |
| 3267 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3268 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3269 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3270 | } |
| 3271 | |
| 3272 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3273 | LocationSummary* locations = |
| 3274 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3275 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3276 | } |
| 3277 | |
| 3278 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3279 | } |
| 3280 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3281 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3282 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3283 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3284 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3285 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3286 | } |
| 3287 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3288 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3289 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3290 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3291 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3292 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3293 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3294 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3295 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3296 | break; |
| 3297 | |
| 3298 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3299 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3300 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3301 | break; |
| 3302 | |
| 3303 | default: |
| 3304 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3305 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3306 | } |
| 3307 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3308 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3309 | LocationSummary* locations = |
| 3310 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3311 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3312 | locations->SetOut(Location::SameAsFirstInput()); |
| 3313 | } |
| 3314 | |
| 3315 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3316 | LocationSummary* locations = bool_not->GetLocations(); |
| 3317 | Location in = locations->InAt(0); |
| 3318 | Location out = locations->Out(); |
| 3319 | DCHECK(in.Equals(out)); |
| 3320 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3321 | } |
| 3322 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3323 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3324 | LocationSummary* locations = |
| 3325 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3326 | switch (compare->InputAt(0)->GetType()) { |
| 3327 | case Primitive::kPrimLong: { |
| 3328 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3329 | locations->SetInAt(1, Location::Any()); |
| 3330 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3331 | break; |
| 3332 | } |
| 3333 | case Primitive::kPrimFloat: |
| 3334 | case Primitive::kPrimDouble: { |
| 3335 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3336 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3337 | locations->SetOut(Location::RequiresRegister()); |
| 3338 | break; |
| 3339 | } |
| 3340 | default: |
| 3341 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3342 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3346 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3347 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3348 | Location left = locations->InAt(0); |
| 3349 | Location right = locations->InAt(1); |
| 3350 | |
| 3351 | Label less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3352 | switch (compare->InputAt(0)->GetType()) { |
| 3353 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3354 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 3355 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 3356 | int32_t val_low = 0; |
| 3357 | int32_t val_high = 0; |
| 3358 | bool right_is_const = false; |
| 3359 | |
| 3360 | if (right.IsConstant()) { |
| 3361 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 3362 | right_is_const = true; |
| 3363 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 3364 | val_low = Low32Bits(val); |
| 3365 | val_high = High32Bits(val); |
| 3366 | } |
| 3367 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3368 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3369 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3370 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3371 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3372 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3373 | DCHECK(right_is_const) << right; |
| 3374 | if (val_high == 0) { |
| 3375 | __ testl(left_high, left_high); |
| 3376 | } else { |
| 3377 | __ cmpl(left_high, Immediate(val_high)); |
| 3378 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3379 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3380 | __ j(kLess, &less); // Signed compare. |
| 3381 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3382 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3383 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3384 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3385 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3386 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3387 | DCHECK(right_is_const) << right; |
| 3388 | if (val_low == 0) { |
| 3389 | __ testl(left_low, left_low); |
| 3390 | } else { |
| 3391 | __ cmpl(left_low, Immediate(val_low)); |
| 3392 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3393 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3394 | break; |
| 3395 | } |
| 3396 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3397 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3398 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3399 | break; |
| 3400 | } |
| 3401 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3402 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3403 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3404 | break; |
| 3405 | } |
| 3406 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3407 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3408 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3409 | __ movl(out, Immediate(0)); |
| 3410 | __ j(kEqual, &done); |
| 3411 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3412 | |
| 3413 | __ Bind(&greater); |
| 3414 | __ movl(out, Immediate(1)); |
| 3415 | __ jmp(&done); |
| 3416 | |
| 3417 | __ Bind(&less); |
| 3418 | __ movl(out, Immediate(-1)); |
| 3419 | |
| 3420 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3421 | } |
| 3422 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3423 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3424 | LocationSummary* locations = |
| 3425 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3426 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3427 | locations->SetInAt(i, Location::Any()); |
| 3428 | } |
| 3429 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3433 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3434 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3435 | } |
| 3436 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3437 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3438 | /* |
| 3439 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3440 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3441 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3442 | */ |
| 3443 | switch (kind) { |
| 3444 | case MemBarrierKind::kAnyAny: { |
| 3445 | __ mfence(); |
| 3446 | break; |
| 3447 | } |
| 3448 | case MemBarrierKind::kAnyStore: |
| 3449 | case MemBarrierKind::kLoadAny: |
| 3450 | case MemBarrierKind::kStoreStore: { |
| 3451 | // nop |
| 3452 | break; |
| 3453 | } |
| 3454 | default: |
| 3455 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3456 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3457 | } |
| 3458 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3459 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3460 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 3461 | Location temp) { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3462 | // TODO: Implement all kinds of calls: |
| 3463 | // 1) boot -> boot |
| 3464 | // 2) app -> boot |
| 3465 | // 3) app -> app |
| 3466 | // |
| 3467 | // 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] | 3468 | |
| 3469 | if (invoke->IsStringInit()) { |
| 3470 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 3471 | Register reg = temp.AsRegister<Register>(); |
| 3472 | __ fs()->movl(reg, Address::Absolute(invoke->GetStringInitOffset())); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3473 | // (temp + offset_of_quick_compiled_code)() |
| 3474 | __ call(Address( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 3475 | reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 3476 | } else if (invoke->IsRecursive()) { |
| 3477 | __ call(GetFrameEntryLabel()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3478 | } else { |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 3479 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3480 | |
| 3481 | Register method_reg; |
| 3482 | Register reg = temp.AsRegister<Register>(); |
| 3483 | if (current_method.IsRegister()) { |
| 3484 | method_reg = current_method.AsRegister<Register>(); |
Nicolas Geoffray | c345f14 | 2015-06-04 17:17:32 +0000 | [diff] [blame] | 3485 | } else { |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 3486 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 3487 | DCHECK(!current_method.IsValid()); |
| 3488 | method_reg = reg; |
| 3489 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
Nicolas Geoffray | c345f14 | 2015-06-04 17:17:32 +0000 | [diff] [blame] | 3490 | } |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 3491 | // temp = temp->dex_cache_resolved_methods_; |
| 3492 | __ movl(reg, Address(method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 3493 | // temp = temp[index_in_cache] |
| 3494 | __ movl(reg, Address(reg, |
| 3495 | CodeGenerator::GetCachePointerOffset(invoke->GetDexMethodIndex()))); |
| 3496 | // (temp + offset_of_quick_compiled_code)() |
| 3497 | __ call(Address(reg, |
| 3498 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3502 | } |
| 3503 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3504 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 3505 | Register card, |
| 3506 | Register object, |
| 3507 | Register value, |
| 3508 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3509 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3510 | if (value_can_be_null) { |
| 3511 | __ testl(value, value); |
| 3512 | __ j(kEqual, &is_null); |
| 3513 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3514 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3515 | __ movl(temp, object); |
| 3516 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3517 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3518 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3519 | if (value_can_be_null) { |
| 3520 | __ Bind(&is_null); |
| 3521 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3522 | } |
| 3523 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3524 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3525 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3526 | LocationSummary* locations = |
| 3527 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3528 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3529 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3530 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3531 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3532 | } else { |
| 3533 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3534 | // the object's location. |
| 3535 | locations->SetOut(Location::RequiresRegister(), |
| 3536 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3537 | : Location::kNoOutputOverlap); |
| 3538 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3539 | |
| 3540 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3541 | // Long values can be loaded atomically into an XMM using movsd. |
| 3542 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3543 | // and then copy the XMM into the output 32bits at a time). |
| 3544 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3545 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3546 | } |
| 3547 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3548 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3549 | const FieldInfo& field_info) { |
| 3550 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3551 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3552 | LocationSummary* locations = instruction->GetLocations(); |
| 3553 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3554 | Location out = locations->Out(); |
| 3555 | bool is_volatile = field_info.IsVolatile(); |
| 3556 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3557 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3558 | |
| 3559 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3560 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3561 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3562 | break; |
| 3563 | } |
| 3564 | |
| 3565 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3566 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3567 | break; |
| 3568 | } |
| 3569 | |
| 3570 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3571 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3572 | break; |
| 3573 | } |
| 3574 | |
| 3575 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3576 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3577 | break; |
| 3578 | } |
| 3579 | |
| 3580 | case Primitive::kPrimInt: |
| 3581 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3582 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3583 | break; |
| 3584 | } |
| 3585 | |
| 3586 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3587 | if (is_volatile) { |
| 3588 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3589 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3590 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3591 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3592 | __ psrlq(temp, Immediate(32)); |
| 3593 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3594 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3595 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3596 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3597 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3598 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3599 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3600 | break; |
| 3601 | } |
| 3602 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3603 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3604 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3605 | break; |
| 3606 | } |
| 3607 | |
| 3608 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3609 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3610 | break; |
| 3611 | } |
| 3612 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3613 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3614 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3615 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3616 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3617 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3618 | // Longs are handled in the switch. |
| 3619 | if (field_type != Primitive::kPrimLong) { |
| 3620 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3621 | } |
| 3622 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3623 | if (is_volatile) { |
| 3624 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3625 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3626 | |
| 3627 | if (field_type == Primitive::kPrimNot) { |
| 3628 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3629 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3630 | } |
| 3631 | |
| 3632 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3633 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3634 | |
| 3635 | LocationSummary* locations = |
| 3636 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3637 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3638 | bool is_volatile = field_info.IsVolatile(); |
| 3639 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3640 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3641 | || (field_type == Primitive::kPrimByte); |
| 3642 | |
| 3643 | // The register allocator does not support multiple |
| 3644 | // inputs that die at entry with one in a specific register. |
| 3645 | if (is_byte_type) { |
| 3646 | // Ensure the value is in a byte register. |
| 3647 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3648 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3649 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3650 | } else { |
| 3651 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3652 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3653 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3654 | // Temporary registers for the write barrier. |
| 3655 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3656 | // Ensure the card is in a byte register. |
| 3657 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3658 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3659 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3660 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3661 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3662 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3663 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3664 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3665 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3666 | } |
| 3667 | } |
| 3668 | |
| 3669 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3670 | const FieldInfo& field_info, |
| 3671 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3672 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3673 | |
| 3674 | LocationSummary* locations = instruction->GetLocations(); |
| 3675 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3676 | Location value = locations->InAt(1); |
| 3677 | bool is_volatile = field_info.IsVolatile(); |
| 3678 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3679 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3680 | bool needs_write_barrier = |
| 3681 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3682 | |
| 3683 | if (is_volatile) { |
| 3684 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3685 | } |
| 3686 | |
| 3687 | switch (field_type) { |
| 3688 | case Primitive::kPrimBoolean: |
| 3689 | case Primitive::kPrimByte: { |
| 3690 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 3691 | break; |
| 3692 | } |
| 3693 | |
| 3694 | case Primitive::kPrimShort: |
| 3695 | case Primitive::kPrimChar: { |
| 3696 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 3697 | break; |
| 3698 | } |
| 3699 | |
| 3700 | case Primitive::kPrimInt: |
| 3701 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3702 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3703 | // Note that in the case where `value` is a null reference, |
| 3704 | // we do not enter this block, as the reference does not |
| 3705 | // need poisoning. |
| 3706 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3707 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3708 | __ movl(temp, value.AsRegister<Register>()); |
| 3709 | __ PoisonHeapReference(temp); |
| 3710 | __ movl(Address(base, offset), temp); |
| 3711 | } else { |
| 3712 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 3713 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3714 | break; |
| 3715 | } |
| 3716 | |
| 3717 | case Primitive::kPrimLong: { |
| 3718 | if (is_volatile) { |
| 3719 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3720 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 3721 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 3722 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 3723 | __ punpckldq(temp1, temp2); |
| 3724 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3725 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3726 | } else { |
| 3727 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3728 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3729 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 3730 | } |
| 3731 | break; |
| 3732 | } |
| 3733 | |
| 3734 | case Primitive::kPrimFloat: { |
| 3735 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3736 | break; |
| 3737 | } |
| 3738 | |
| 3739 | case Primitive::kPrimDouble: { |
| 3740 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3741 | break; |
| 3742 | } |
| 3743 | |
| 3744 | case Primitive::kPrimVoid: |
| 3745 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3746 | UNREACHABLE(); |
| 3747 | } |
| 3748 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3749 | // Longs are handled in the switch. |
| 3750 | if (field_type != Primitive::kPrimLong) { |
| 3751 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3752 | } |
| 3753 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3754 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3755 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3756 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3757 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3760 | if (is_volatile) { |
| 3761 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3762 | } |
| 3763 | } |
| 3764 | |
| 3765 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3766 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3767 | } |
| 3768 | |
| 3769 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3770 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3771 | } |
| 3772 | |
| 3773 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3774 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3775 | } |
| 3776 | |
| 3777 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3778 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3782 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3783 | } |
| 3784 | |
| 3785 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3786 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3790 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3791 | } |
| 3792 | |
| 3793 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3794 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3798 | LocationSummary* locations = |
| 3799 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3800 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3801 | ? Location::RequiresRegister() |
| 3802 | : Location::Any(); |
| 3803 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3804 | if (instruction->HasUses()) { |
| 3805 | locations->SetOut(Location::SameAsFirstInput()); |
| 3806 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3807 | } |
| 3808 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3809 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3810 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3811 | return; |
| 3812 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3813 | LocationSummary* locations = instruction->GetLocations(); |
| 3814 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3815 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3816 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 3817 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3818 | } |
| 3819 | |
| 3820 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3821 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3822 | codegen_->AddSlowPath(slow_path); |
| 3823 | |
| 3824 | LocationSummary* locations = instruction->GetLocations(); |
| 3825 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3826 | |
| 3827 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 3828 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3829 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3830 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3831 | } else { |
| 3832 | DCHECK(obj.IsConstant()) << obj; |
| 3833 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 3834 | __ jmp(slow_path->GetEntryLabel()); |
| 3835 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3836 | } |
| 3837 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3838 | } |
| 3839 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3840 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| 3841 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3842 | GenerateImplicitNullCheck(instruction); |
| 3843 | } else { |
| 3844 | GenerateExplicitNullCheck(instruction); |
| 3845 | } |
| 3846 | } |
| 3847 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3848 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3849 | LocationSummary* locations = |
| 3850 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3851 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3852 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3853 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3854 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3855 | } else { |
| 3856 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3857 | // the array's location. |
| 3858 | locations->SetOut(Location::RequiresRegister(), |
| 3859 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3860 | : Location::kNoOutputOverlap); |
| 3861 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3862 | } |
| 3863 | |
| 3864 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 3865 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3866 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3867 | Location index = locations->InAt(1); |
| 3868 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3869 | Primitive::Type type = instruction->GetType(); |
| 3870 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3871 | case Primitive::kPrimBoolean: { |
| 3872 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3873 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3874 | if (index.IsConstant()) { |
| 3875 | __ movzxb(out, Address(obj, |
| 3876 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3877 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3878 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3879 | } |
| 3880 | break; |
| 3881 | } |
| 3882 | |
| 3883 | case Primitive::kPrimByte: { |
| 3884 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3885 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3886 | if (index.IsConstant()) { |
| 3887 | __ movsxb(out, Address(obj, |
| 3888 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3889 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3890 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3891 | } |
| 3892 | break; |
| 3893 | } |
| 3894 | |
| 3895 | case Primitive::kPrimShort: { |
| 3896 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3897 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3898 | if (index.IsConstant()) { |
| 3899 | __ movsxw(out, Address(obj, |
| 3900 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3901 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3902 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3903 | } |
| 3904 | break; |
| 3905 | } |
| 3906 | |
| 3907 | case Primitive::kPrimChar: { |
| 3908 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3909 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3910 | if (index.IsConstant()) { |
| 3911 | __ movzxw(out, Address(obj, |
| 3912 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3913 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3914 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3915 | } |
| 3916 | break; |
| 3917 | } |
| 3918 | |
| 3919 | case Primitive::kPrimInt: |
| 3920 | case Primitive::kPrimNot: { |
| 3921 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3922 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3923 | if (index.IsConstant()) { |
| 3924 | __ movl(out, Address(obj, |
| 3925 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3926 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3927 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3928 | } |
| 3929 | break; |
| 3930 | } |
| 3931 | |
| 3932 | case Primitive::kPrimLong: { |
| 3933 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3934 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3935 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3936 | if (index.IsConstant()) { |
| 3937 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3938 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3939 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3940 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3941 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3942 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3943 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3944 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3945 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3946 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3947 | } |
| 3948 | break; |
| 3949 | } |
| 3950 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 3951 | case Primitive::kPrimFloat: { |
| 3952 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3953 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 3954 | if (index.IsConstant()) { |
| 3955 | __ movss(out, Address(obj, |
| 3956 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3957 | } else { |
| 3958 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 3959 | } |
| 3960 | break; |
| 3961 | } |
| 3962 | |
| 3963 | case Primitive::kPrimDouble: { |
| 3964 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3965 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 3966 | if (index.IsConstant()) { |
| 3967 | __ movsd(out, Address(obj, |
| 3968 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3969 | } else { |
| 3970 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 3971 | } |
| 3972 | break; |
| 3973 | } |
| 3974 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3975 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3976 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3977 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3978 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3979 | |
| 3980 | if (type != Primitive::kPrimLong) { |
| 3981 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3982 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3983 | |
| 3984 | if (type == Primitive::kPrimNot) { |
| 3985 | Register out = locations->Out().AsRegister<Register>(); |
| 3986 | __ MaybeUnpoisonHeapReference(out); |
| 3987 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 3991 | // This location builder might end up asking to up to four registers, which is |
| 3992 | // not currently possible for baseline. The situation in which we need four |
| 3993 | // registers cannot be met by baseline though, because it has not run any |
| 3994 | // optimization. |
| 3995 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3996 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3997 | bool needs_write_barrier = |
| 3998 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3999 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4000 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4001 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4002 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4003 | instruction, |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4004 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4005 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4006 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4007 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4008 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4009 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4010 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4011 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4012 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4013 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4014 | // 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] | 4015 | // In case of a byte operation, the register allocator does not support multiple |
| 4016 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4017 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4018 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4019 | if (is_byte_type) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4020 | // Ensure the value is in a byte register. |
| 4021 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4022 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 4023 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4024 | } else { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4025 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4026 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4027 | if (needs_write_barrier) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4028 | // Temporary registers for the write barrier. |
| 4029 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4030 | // Ensure the card is in a byte register. |
| 4031 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4032 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4033 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4034 | } |
| 4035 | |
| 4036 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4037 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4038 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4039 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4040 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4041 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4042 | bool needs_runtime_call = locations->WillCall(); |
| 4043 | bool needs_write_barrier = |
| 4044 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4045 | |
| 4046 | switch (value_type) { |
| 4047 | case Primitive::kPrimBoolean: |
| 4048 | case Primitive::kPrimByte: { |
| 4049 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4050 | if (index.IsConstant()) { |
| 4051 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4052 | if (value.IsRegister()) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4053 | __ movb(Address(obj, offset), value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4054 | } else { |
| 4055 | __ movb(Address(obj, offset), |
| 4056 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4057 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4058 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4059 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4060 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4061 | value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4062 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4063 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4064 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4065 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4066 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4067 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4068 | break; |
| 4069 | } |
| 4070 | |
| 4071 | case Primitive::kPrimShort: |
| 4072 | case Primitive::kPrimChar: { |
| 4073 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4074 | if (index.IsConstant()) { |
| 4075 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4076 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4077 | __ movw(Address(obj, offset), value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4078 | } else { |
| 4079 | __ movw(Address(obj, offset), |
| 4080 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4081 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4082 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4083 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4084 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
| 4085 | value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4086 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4087 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4088 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4089 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4090 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4091 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4092 | break; |
| 4093 | } |
| 4094 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4095 | case Primitive::kPrimInt: |
| 4096 | case Primitive::kPrimNot: { |
| 4097 | if (!needs_runtime_call) { |
| 4098 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4099 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4100 | size_t offset = |
| 4101 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4102 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4103 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4104 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4105 | __ movl(temp, value.AsRegister<Register>()); |
| 4106 | __ PoisonHeapReference(temp); |
| 4107 | __ movl(Address(obj, offset), temp); |
| 4108 | } else { |
| 4109 | __ movl(Address(obj, offset), value.AsRegister<Register>()); |
| 4110 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4111 | } else { |
| 4112 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4113 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4114 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4115 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4116 | // Note: if heap poisoning is enabled, no need to poison |
| 4117 | // (negate) `v` if it is a reference, as it would be null. |
| 4118 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4119 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4120 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4121 | DCHECK(index.IsRegister()) << index; |
| 4122 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4123 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4124 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4125 | __ movl(temp, value.AsRegister<Register>()); |
| 4126 | __ PoisonHeapReference(temp); |
| 4127 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), temp); |
| 4128 | } else { |
| 4129 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4130 | value.AsRegister<Register>()); |
| 4131 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4132 | } else { |
| 4133 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4134 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4135 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4136 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4137 | // Note: if heap poisoning is enabled, no need to poison |
| 4138 | // (negate) `v` if it is a reference, as it would be null. |
| 4139 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4140 | } |
| 4141 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4142 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4143 | |
| 4144 | if (needs_write_barrier) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4145 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4146 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4147 | codegen_->MarkGCCard( |
| 4148 | temp, card, obj, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4149 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4150 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4151 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4152 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4153 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4154 | // of poisoning the reference. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4155 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject))); |
| 4156 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4157 | } |
| 4158 | break; |
| 4159 | } |
| 4160 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4161 | case Primitive::kPrimLong: { |
| 4162 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4163 | if (index.IsConstant()) { |
| 4164 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4165 | if (value.IsRegisterPair()) { |
| 4166 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4167 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4168 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4169 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4170 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4171 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4172 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4173 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4174 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 4175 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4176 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4177 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4178 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4179 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4180 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4181 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4182 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4183 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4184 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4185 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4186 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4187 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4188 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4189 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4190 | Immediate(High32Bits(val))); |
| 4191 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4192 | } |
| 4193 | break; |
| 4194 | } |
| 4195 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4196 | case Primitive::kPrimFloat: { |
| 4197 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4198 | DCHECK(value.IsFpuRegister()); |
| 4199 | if (index.IsConstant()) { |
| 4200 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4201 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4202 | } else { |
| 4203 | __ movss(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4204 | value.AsFpuRegister<XmmRegister>()); |
| 4205 | } |
| 4206 | break; |
| 4207 | } |
| 4208 | |
| 4209 | case Primitive::kPrimDouble: { |
| 4210 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4211 | DCHECK(value.IsFpuRegister()); |
| 4212 | if (index.IsConstant()) { |
| 4213 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4214 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4215 | } else { |
| 4216 | __ movsd(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
| 4217 | value.AsFpuRegister<XmmRegister>()); |
| 4218 | } |
| 4219 | break; |
| 4220 | } |
| 4221 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4222 | case Primitive::kPrimVoid: |
| 4223 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4224 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4225 | } |
| 4226 | } |
| 4227 | |
| 4228 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 4229 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4230 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4231 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 4235 | LocationSummary* locations = instruction->GetLocations(); |
| 4236 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4237 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4238 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4239 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4240 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4244 | LocationSummary* locations = |
| 4245 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4246 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4247 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4248 | if (instruction->HasUses()) { |
| 4249 | locations->SetOut(Location::SameAsFirstInput()); |
| 4250 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4254 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4255 | Location index_loc = locations->InAt(0); |
| 4256 | Location length_loc = locations->InAt(1); |
| 4257 | SlowPathCodeX86* slow_path = |
| 4258 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction, index_loc, length_loc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4259 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4260 | if (length_loc.IsConstant()) { |
| 4261 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4262 | if (index_loc.IsConstant()) { |
| 4263 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4264 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4265 | if (index < 0 || index >= length) { |
| 4266 | codegen_->AddSlowPath(slow_path); |
| 4267 | __ jmp(slow_path->GetEntryLabel()); |
| 4268 | } else { |
| 4269 | // Some optimization after BCE may have generated this, and we should not |
| 4270 | // generate a bounds check if it is a valid range. |
| 4271 | } |
| 4272 | return; |
| 4273 | } |
| 4274 | |
| 4275 | // We have to reverse the jump condition because the length is the constant. |
| 4276 | Register index_reg = index_loc.AsRegister<Register>(); |
| 4277 | __ cmpl(index_reg, Immediate(length)); |
| 4278 | codegen_->AddSlowPath(slow_path); |
| 4279 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4280 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4281 | Register length = length_loc.AsRegister<Register>(); |
| 4282 | if (index_loc.IsConstant()) { |
| 4283 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4284 | __ cmpl(length, Immediate(value)); |
| 4285 | } else { |
| 4286 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 4287 | } |
| 4288 | codegen_->AddSlowPath(slow_path); |
| 4289 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4290 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4291 | } |
| 4292 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4293 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 4294 | temp->SetLocations(nullptr); |
| 4295 | } |
| 4296 | |
| 4297 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 4298 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4299 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4300 | } |
| 4301 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4302 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4303 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4304 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4308 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4309 | } |
| 4310 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4311 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4312 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4313 | } |
| 4314 | |
| 4315 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4316 | HBasicBlock* block = instruction->GetBlock(); |
| 4317 | if (block->GetLoopInformation() != nullptr) { |
| 4318 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4319 | // The back edge will generate the suspend check. |
| 4320 | return; |
| 4321 | } |
| 4322 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4323 | // The goto will generate the suspend check. |
| 4324 | return; |
| 4325 | } |
| 4326 | GenerateSuspendCheck(instruction, nullptr); |
| 4327 | } |
| 4328 | |
| 4329 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4330 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4331 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4332 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 4333 | if (slow_path == nullptr) { |
| 4334 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 4335 | instruction->SetSlowPath(slow_path); |
| 4336 | codegen_->AddSlowPath(slow_path); |
| 4337 | if (successor != nullptr) { |
| 4338 | DCHECK(successor->IsLoopHeader()); |
| 4339 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4340 | } |
| 4341 | } else { |
| 4342 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4343 | } |
| 4344 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4345 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4346 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4347 | if (successor == nullptr) { |
| 4348 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4349 | __ Bind(slow_path->GetReturnLabel()); |
| 4350 | } else { |
| 4351 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4352 | __ jmp(slow_path->GetEntryLabel()); |
| 4353 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4354 | } |
| 4355 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4356 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 4357 | return codegen_->GetAssembler(); |
| 4358 | } |
| 4359 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4360 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4361 | ScratchRegisterScope ensure_scratch( |
| 4362 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4363 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4364 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4365 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4366 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4370 | ScratchRegisterScope ensure_scratch( |
| 4371 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4372 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4373 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4374 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4375 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 4376 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 4377 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 4381 | MoveOperands* move = moves_.Get(index); |
| 4382 | Location source = move->GetSource(); |
| 4383 | Location destination = move->GetDestination(); |
| 4384 | |
| 4385 | if (source.IsRegister()) { |
| 4386 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4387 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4388 | } else { |
| 4389 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4390 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4391 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4392 | } else if (source.IsFpuRegister()) { |
| 4393 | if (destination.IsFpuRegister()) { |
| 4394 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4395 | } else if (destination.IsStackSlot()) { |
| 4396 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4397 | } else { |
| 4398 | DCHECK(destination.IsDoubleStackSlot()); |
| 4399 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4400 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4401 | } else if (source.IsStackSlot()) { |
| 4402 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4403 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4404 | } else if (destination.IsFpuRegister()) { |
| 4405 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4406 | } else { |
| 4407 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4408 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4409 | } |
| 4410 | } else if (source.IsDoubleStackSlot()) { |
| 4411 | if (destination.IsFpuRegister()) { |
| 4412 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 4413 | } else { |
| 4414 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4415 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4416 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4417 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4418 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4419 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4420 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4421 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4422 | if (value == 0) { |
| 4423 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4424 | } else { |
| 4425 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 4426 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4427 | } else { |
| 4428 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4429 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4430 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4431 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4432 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4433 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4434 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4435 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4436 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4437 | if (value == 0) { |
| 4438 | // Easy handling of 0.0. |
| 4439 | __ xorps(dest, dest); |
| 4440 | } else { |
| 4441 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4442 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4443 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4444 | __ movl(temp, Immediate(value)); |
| 4445 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4446 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4447 | } else { |
| 4448 | DCHECK(destination.IsStackSlot()) << destination; |
| 4449 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 4450 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4451 | } else if (constant->IsLongConstant()) { |
| 4452 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4453 | int32_t low_value = Low32Bits(value); |
| 4454 | int32_t high_value = High32Bits(value); |
| 4455 | Immediate low(low_value); |
| 4456 | Immediate high(high_value); |
| 4457 | if (destination.IsDoubleStackSlot()) { |
| 4458 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4459 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4460 | } else { |
| 4461 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 4462 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 4463 | } |
| 4464 | } else { |
| 4465 | DCHECK(constant->IsDoubleConstant()); |
| 4466 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4467 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4468 | int32_t low_value = Low32Bits(value); |
| 4469 | int32_t high_value = High32Bits(value); |
| 4470 | Immediate low(low_value); |
| 4471 | Immediate high(high_value); |
| 4472 | if (destination.IsFpuRegister()) { |
| 4473 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4474 | if (value == 0) { |
| 4475 | // Easy handling of 0.0. |
| 4476 | __ xorpd(dest, dest); |
| 4477 | } else { |
| 4478 | __ pushl(high); |
| 4479 | __ pushl(low); |
| 4480 | __ movsd(dest, Address(ESP, 0)); |
| 4481 | __ addl(ESP, Immediate(8)); |
| 4482 | } |
| 4483 | } else { |
| 4484 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4485 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4486 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4487 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4488 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4489 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4490 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4491 | } |
| 4492 | } |
| 4493 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4494 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4495 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4496 | ScratchRegisterScope ensure_scratch( |
| 4497 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4498 | |
| 4499 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4500 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4501 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4502 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4503 | } |
| 4504 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4505 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4506 | ScratchRegisterScope ensure_scratch( |
| 4507 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4508 | |
| 4509 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4510 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4511 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4512 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4513 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4514 | } |
| 4515 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4516 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4517 | ScratchRegisterScope ensure_scratch1( |
| 4518 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4519 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4520 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4521 | ScratchRegisterScope ensure_scratch2( |
| 4522 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4523 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4524 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4525 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4526 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4527 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4528 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4529 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 4533 | MoveOperands* move = moves_.Get(index); |
| 4534 | Location source = move->GetSource(); |
| 4535 | Location destination = move->GetDestination(); |
| 4536 | |
| 4537 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame^] | 4538 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 4539 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4540 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4541 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4542 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4543 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4544 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4545 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4546 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4547 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4548 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4549 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4550 | // Use XOR Swap algorithm to avoid a temporary. |
| 4551 | DCHECK_NE(source.reg(), destination.reg()); |
| 4552 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4553 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4554 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4555 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4556 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4557 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4558 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4559 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4560 | // Take advantage of the 16 bytes in the XMM register. |
| 4561 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4562 | Address stack(ESP, destination.GetStackIndex()); |
| 4563 | // Load the double into the high doubleword. |
| 4564 | __ movhpd(reg, stack); |
| 4565 | |
| 4566 | // Store the low double into the destination. |
| 4567 | __ movsd(stack, reg); |
| 4568 | |
| 4569 | // Move the high double to the low double. |
| 4570 | __ psrldq(reg, Immediate(8)); |
| 4571 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4572 | // Take advantage of the 16 bytes in the XMM register. |
| 4573 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4574 | Address stack(ESP, source.GetStackIndex()); |
| 4575 | // Load the double into the high doubleword. |
| 4576 | __ movhpd(reg, stack); |
| 4577 | |
| 4578 | // Store the low double into the destination. |
| 4579 | __ movsd(stack, reg); |
| 4580 | |
| 4581 | // Move the high double to the low double. |
| 4582 | __ psrldq(reg, Immediate(8)); |
| 4583 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4584 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4585 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4586 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4587 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4588 | } |
| 4589 | } |
| 4590 | |
| 4591 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4592 | __ pushl(static_cast<Register>(reg)); |
| 4593 | } |
| 4594 | |
| 4595 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4596 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4597 | } |
| 4598 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4599 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4600 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4601 | ? LocationSummary::kCallOnSlowPath |
| 4602 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4603 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4604 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4605 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4606 | locations->SetOut(Location::RequiresRegister()); |
| 4607 | } |
| 4608 | |
| 4609 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4610 | LocationSummary* locations = cls->GetLocations(); |
| 4611 | Register out = locations->Out().AsRegister<Register>(); |
| 4612 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4613 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4614 | DCHECK(!cls->CanCallRuntime()); |
| 4615 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4616 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4617 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4618 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4619 | __ movl(out, Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4620 | current_method, ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4621 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4622 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4623 | |
| 4624 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4625 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4626 | codegen_->AddSlowPath(slow_path); |
| 4627 | __ testl(out, out); |
| 4628 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4629 | if (cls->MustGenerateClinitCheck()) { |
| 4630 | GenerateClassInitializationCheck(slow_path, out); |
| 4631 | } else { |
| 4632 | __ Bind(slow_path->GetExitLabel()); |
| 4633 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4634 | } |
| 4635 | } |
| 4636 | |
| 4637 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 4638 | LocationSummary* locations = |
| 4639 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4640 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4641 | if (check->HasUses()) { |
| 4642 | locations->SetOut(Location::SameAsFirstInput()); |
| 4643 | } |
| 4644 | } |
| 4645 | |
| 4646 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4647 | // We assume the class to not be null. |
| 4648 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4649 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4650 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4651 | GenerateClassInitializationCheck(slow_path, |
| 4652 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4653 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4654 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4655 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 4656 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4657 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4658 | Immediate(mirror::Class::kStatusInitialized)); |
| 4659 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4660 | __ Bind(slow_path->GetExitLabel()); |
| 4661 | // No need for memory fence, thanks to the X86 memory model. |
| 4662 | } |
| 4663 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4664 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 4665 | LocationSummary* locations = |
| 4666 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4667 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4668 | locations->SetOut(Location::RequiresRegister()); |
| 4669 | } |
| 4670 | |
| 4671 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 4672 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 4673 | codegen_->AddSlowPath(slow_path); |
| 4674 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4675 | LocationSummary* locations = load->GetLocations(); |
| 4676 | Register out = locations->Out().AsRegister<Register>(); |
| 4677 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4678 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4679 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4680 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4681 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4682 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4683 | __ testl(out, out); |
| 4684 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4685 | __ Bind(slow_path->GetExitLabel()); |
| 4686 | } |
| 4687 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4688 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 4689 | LocationSummary* locations = |
| 4690 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4691 | locations->SetOut(Location::RequiresRegister()); |
| 4692 | } |
| 4693 | |
| 4694 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| 4695 | Address address = Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4696 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), address); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4697 | __ fs()->movl(address, Immediate(0)); |
| 4698 | } |
| 4699 | |
| 4700 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 4701 | LocationSummary* locations = |
| 4702 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4703 | InvokeRuntimeCallingConvention calling_convention; |
| 4704 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4705 | } |
| 4706 | |
| 4707 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| 4708 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pDeliverException))); |
| 4709 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4710 | } |
| 4711 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4712 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4713 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4714 | ? LocationSummary::kNoCall |
| 4715 | : LocationSummary::kCallOnSlowPath; |
| 4716 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4717 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4718 | locations->SetInAt(1, Location::Any()); |
| 4719 | locations->SetOut(Location::RequiresRegister()); |
| 4720 | } |
| 4721 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4722 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4723 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4724 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4725 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4726 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4727 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4728 | Label done, zero; |
| 4729 | SlowPathCodeX86* slow_path = nullptr; |
| 4730 | |
| 4731 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4732 | // Avoid null check if we know obj is not null. |
| 4733 | if (instruction->MustDoNullCheck()) { |
| 4734 | __ testl(obj, obj); |
| 4735 | __ j(kEqual, &zero); |
| 4736 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4737 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4738 | __ movl(out, Address(obj, class_offset)); |
| 4739 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4740 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4741 | __ cmpl(out, cls.AsRegister<Register>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4742 | } else { |
| 4743 | DCHECK(cls.IsStackSlot()) << cls; |
| 4744 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 4745 | } |
| 4746 | |
| 4747 | if (instruction->IsClassFinal()) { |
| 4748 | // Classes must be equal for the instanceof to succeed. |
| 4749 | __ j(kNotEqual, &zero); |
| 4750 | __ movl(out, Immediate(1)); |
| 4751 | __ jmp(&done); |
| 4752 | } else { |
| 4753 | // If the classes are not equal, we go into a slow path. |
| 4754 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4755 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4756 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4757 | codegen_->AddSlowPath(slow_path); |
| 4758 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4759 | __ movl(out, Immediate(1)); |
| 4760 | __ jmp(&done); |
| 4761 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4762 | |
| 4763 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4764 | __ Bind(&zero); |
| 4765 | __ movl(out, Immediate(0)); |
| 4766 | } |
| 4767 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4768 | if (slow_path != nullptr) { |
| 4769 | __ Bind(slow_path->GetExitLabel()); |
| 4770 | } |
| 4771 | __ Bind(&done); |
| 4772 | } |
| 4773 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4774 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| 4775 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4776 | instruction, LocationSummary::kCallOnSlowPath); |
| 4777 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4778 | locations->SetInAt(1, Location::Any()); |
| 4779 | locations->AddTemp(Location::RequiresRegister()); |
| 4780 | } |
| 4781 | |
| 4782 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 4783 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4784 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4785 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4786 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4787 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4788 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 4789 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 4790 | codegen_->AddSlowPath(slow_path); |
| 4791 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4792 | // Avoid null check if we know obj is not null. |
| 4793 | if (instruction->MustDoNullCheck()) { |
| 4794 | __ testl(obj, obj); |
| 4795 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4796 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4797 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4798 | __ movl(temp, Address(obj, class_offset)); |
| 4799 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4800 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4801 | __ cmpl(temp, cls.AsRegister<Register>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4802 | } else { |
| 4803 | DCHECK(cls.IsStackSlot()) << cls; |
| 4804 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 4805 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4806 | // The checkcast succeeds if the classes are equal (fast path). |
| 4807 | // Otherwise, we need to go into the slow path to check the types. |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4808 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4809 | __ Bind(slow_path->GetExitLabel()); |
| 4810 | } |
| 4811 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4812 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4813 | LocationSummary* locations = |
| 4814 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4815 | InvokeRuntimeCallingConvention calling_convention; |
| 4816 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4817 | } |
| 4818 | |
| 4819 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4820 | __ fs()->call(Address::Absolute(instruction->IsEnter() |
| 4821 | ? QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLockObject) |
| 4822 | : QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pUnlockObject))); |
| 4823 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4824 | } |
| 4825 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4826 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4827 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4828 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4829 | |
| 4830 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4831 | LocationSummary* locations = |
| 4832 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4833 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4834 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4835 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4836 | locations->SetInAt(1, Location::Any()); |
| 4837 | locations->SetOut(Location::SameAsFirstInput()); |
| 4838 | } |
| 4839 | |
| 4840 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 4841 | HandleBitwiseOperation(instruction); |
| 4842 | } |
| 4843 | |
| 4844 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 4845 | HandleBitwiseOperation(instruction); |
| 4846 | } |
| 4847 | |
| 4848 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 4849 | HandleBitwiseOperation(instruction); |
| 4850 | } |
| 4851 | |
| 4852 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4853 | LocationSummary* locations = instruction->GetLocations(); |
| 4854 | Location first = locations->InAt(0); |
| 4855 | Location second = locations->InAt(1); |
| 4856 | DCHECK(first.Equals(locations->Out())); |
| 4857 | |
| 4858 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 4859 | if (second.IsRegister()) { |
| 4860 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4861 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4862 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4863 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4864 | } else { |
| 4865 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4866 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4867 | } |
| 4868 | } else if (second.IsConstant()) { |
| 4869 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4870 | __ andl(first.AsRegister<Register>(), |
| 4871 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4872 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4873 | __ orl(first.AsRegister<Register>(), |
| 4874 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4875 | } else { |
| 4876 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4877 | __ xorl(first.AsRegister<Register>(), |
| 4878 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4879 | } |
| 4880 | } else { |
| 4881 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4882 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4883 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4884 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4885 | } else { |
| 4886 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4887 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4888 | } |
| 4889 | } |
| 4890 | } else { |
| 4891 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 4892 | if (second.IsRegisterPair()) { |
| 4893 | if (instruction->IsAnd()) { |
| 4894 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 4895 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 4896 | } else if (instruction->IsOr()) { |
| 4897 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 4898 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 4899 | } else { |
| 4900 | DCHECK(instruction->IsXor()); |
| 4901 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 4902 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 4903 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4904 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4905 | if (instruction->IsAnd()) { |
| 4906 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 4907 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 4908 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 4909 | } else if (instruction->IsOr()) { |
| 4910 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 4911 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 4912 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 4913 | } else { |
| 4914 | DCHECK(instruction->IsXor()); |
| 4915 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 4916 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 4917 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 4918 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4919 | } else { |
| 4920 | DCHECK(second.IsConstant()) << second; |
| 4921 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4922 | int32_t low_value = Low32Bits(value); |
| 4923 | int32_t high_value = High32Bits(value); |
| 4924 | Immediate low(low_value); |
| 4925 | Immediate high(high_value); |
| 4926 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 4927 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4928 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4929 | if (low_value == 0) { |
| 4930 | __ xorl(first_low, first_low); |
| 4931 | } else if (low_value != -1) { |
| 4932 | __ andl(first_low, low); |
| 4933 | } |
| 4934 | if (high_value == 0) { |
| 4935 | __ xorl(first_high, first_high); |
| 4936 | } else if (high_value != -1) { |
| 4937 | __ andl(first_high, high); |
| 4938 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4939 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4940 | if (low_value != 0) { |
| 4941 | __ orl(first_low, low); |
| 4942 | } |
| 4943 | if (high_value != 0) { |
| 4944 | __ orl(first_high, high); |
| 4945 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4946 | } else { |
| 4947 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4948 | if (low_value != 0) { |
| 4949 | __ xorl(first_low, low); |
| 4950 | } |
| 4951 | if (high_value != 0) { |
| 4952 | __ xorl(first_high, high); |
| 4953 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4954 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4955 | } |
| 4956 | } |
| 4957 | } |
| 4958 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4959 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 4960 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4961 | UNUSED(instruction); |
| 4962 | LOG(FATAL) << "Unreachable"; |
| 4963 | } |
| 4964 | |
| 4965 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 4966 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4967 | UNUSED(instruction); |
| 4968 | LOG(FATAL) << "Unreachable"; |
| 4969 | } |
| 4970 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4971 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 4972 | DCHECK(codegen_->IsBaseline()); |
| 4973 | LocationSummary* locations = |
| 4974 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4975 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 4976 | } |
| 4977 | |
| 4978 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 4979 | DCHECK(codegen_->IsBaseline()); |
| 4980 | // Will be generated at use site. |
| 4981 | } |
| 4982 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4983 | #undef __ |
| 4984 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 4985 | } // namespace x86 |
| 4986 | } // namespace art |