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