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