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())-> |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 48 | #define QUICK_ENTRY_POINT(x) Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x)) |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 49 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 50 | class NullCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 51 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 52 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 54 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 55 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 57 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 58 | instruction_, |
| 59 | instruction_->GetDexPc(), |
| 60 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 63 | bool IsFatal() const OVERRIDE { return true; } |
| 64 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 65 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 66 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 67 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 68 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 70 | }; |
| 71 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 72 | class DivZeroCheckSlowPathX86 : public SlowPathCodeX86 { |
| 73 | public: |
| 74 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 75 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 76 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 77 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 78 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 79 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 80 | instruction_, |
| 81 | instruction_->GetDexPc(), |
| 82 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 85 | bool IsFatal() const OVERRIDE { return true; } |
| 86 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 87 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 88 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | private: |
| 90 | HDivZeroCheck* const instruction_; |
| 91 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 92 | }; |
| 93 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 94 | class DivRemMinusOneSlowPathX86 : public SlowPathCodeX86 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 96 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 98 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 100 | if (is_div_) { |
| 101 | __ negl(reg_); |
| 102 | } else { |
| 103 | __ movl(reg_, Immediate(0)); |
| 104 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | __ jmp(GetExitLabel()); |
| 106 | } |
| 107 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 108 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 109 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | private: |
| 111 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 112 | bool is_div_; |
| 113 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 116 | class BoundsCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 117 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 118 | BoundsCheckSlowPathX86(HBoundsCheck* instruction, |
| 119 | Location index_location, |
| 120 | Location length_location) |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 121 | : instruction_(instruction), |
| 122 | index_location_(index_location), |
| 123 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 124 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 125 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 126 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 127 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 128 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 129 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 130 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 131 | x86_codegen->EmitParallelMoves( |
| 132 | index_location_, |
| 133 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 134 | Primitive::kPrimInt, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 135 | length_location_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 136 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 137 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 138 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 139 | instruction_, |
| 140 | instruction_->GetDexPc(), |
| 141 | this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 142 | } |
| 143 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 144 | bool IsFatal() const OVERRIDE { return true; } |
| 145 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 146 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 147 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 148 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 149 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 150 | const Location index_location_; |
| 151 | const Location length_location_; |
| 152 | |
| 153 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 154 | }; |
| 155 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 156 | class SuspendCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 157 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 158 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 159 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 160 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 161 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 162 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 164 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 165 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 166 | instruction_, |
| 167 | instruction_->GetDexPc(), |
| 168 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 169 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 170 | if (successor_ == nullptr) { |
| 171 | __ jmp(GetReturnLabel()); |
| 172 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 173 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 174 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 177 | Label* GetReturnLabel() { |
| 178 | DCHECK(successor_ == nullptr); |
| 179 | return &return_label_; |
| 180 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 181 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 182 | HBasicBlock* GetSuccessor() const { |
| 183 | return successor_; |
| 184 | } |
| 185 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 186 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 187 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 188 | private: |
| 189 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 190 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 191 | Label return_label_; |
| 192 | |
| 193 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 194 | }; |
| 195 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 196 | class LoadStringSlowPathX86 : public SlowPathCodeX86 { |
| 197 | public: |
| 198 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 199 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 200 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 201 | LocationSummary* locations = instruction_->GetLocations(); |
| 202 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 203 | |
| 204 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 205 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 206 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 207 | |
| 208 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 209 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 210 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 211 | instruction_, |
| 212 | instruction_->GetDexPc(), |
| 213 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 214 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 215 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 216 | |
| 217 | __ jmp(GetExitLabel()); |
| 218 | } |
| 219 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 220 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 221 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 222 | private: |
| 223 | HLoadString* const instruction_; |
| 224 | |
| 225 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 226 | }; |
| 227 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | class LoadClassSlowPathX86 : public SlowPathCodeX86 { |
| 229 | public: |
| 230 | LoadClassSlowPathX86(HLoadClass* cls, |
| 231 | HInstruction* at, |
| 232 | uint32_t dex_pc, |
| 233 | bool do_clinit) |
| 234 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 235 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 236 | } |
| 237 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 238 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 239 | LocationSummary* locations = at_->GetLocations(); |
| 240 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 241 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 242 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 243 | |
| 244 | InvokeRuntimeCallingConvention calling_convention; |
| 245 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 246 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 247 | : QUICK_ENTRY_POINT(pInitializeType), |
| 248 | at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 249 | |
| 250 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 251 | Location out = locations->Out(); |
| 252 | if (out.IsValid()) { |
| 253 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 254 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 255 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 256 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 257 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | __ jmp(GetExitLabel()); |
| 259 | } |
| 260 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 261 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 262 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 263 | private: |
| 264 | // The class this slow path will load. |
| 265 | HLoadClass* const cls_; |
| 266 | |
| 267 | // The instruction where this slow path is happening. |
| 268 | // (Might be the load class or an initialization check). |
| 269 | HInstruction* const at_; |
| 270 | |
| 271 | // The dex PC of `at_`. |
| 272 | const uint32_t dex_pc_; |
| 273 | |
| 274 | // Whether to initialize the class. |
| 275 | const bool do_clinit_; |
| 276 | |
| 277 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 278 | }; |
| 279 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 280 | class TypeCheckSlowPathX86 : public SlowPathCodeX86 { |
| 281 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 282 | TypeCheckSlowPathX86(HInstruction* instruction, |
| 283 | Location class_to_check, |
| 284 | Location object_class, |
| 285 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 286 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 287 | class_to_check_(class_to_check), |
| 288 | object_class_(object_class), |
| 289 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 290 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 291 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 292 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 293 | DCHECK(instruction_->IsCheckCast() |
| 294 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 295 | |
| 296 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 297 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 298 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | |
| 300 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 301 | // move resolver. |
| 302 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 303 | x86_codegen->EmitParallelMoves( |
| 304 | class_to_check_, |
| 305 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 306 | Primitive::kPrimNot, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 307 | object_class_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 308 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 309 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 310 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 311 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 312 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 313 | instruction_, |
| 314 | instruction_->GetDexPc(), |
| 315 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 316 | } else { |
| 317 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 318 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 319 | instruction_, |
| 320 | instruction_->GetDexPc(), |
| 321 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 324 | RecordPcInfo(codegen, instruction_, dex_pc_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 325 | if (instruction_->IsInstanceOf()) { |
| 326 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 327 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 328 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | |
| 330 | __ jmp(GetExitLabel()); |
| 331 | } |
| 332 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 333 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
| 334 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 335 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 336 | HInstruction* const instruction_; |
| 337 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 339 | const uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | |
| 341 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 342 | }; |
| 343 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 344 | class DeoptimizationSlowPathX86 : public SlowPathCodeX86 { |
| 345 | public: |
| 346 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 347 | : instruction_(instruction) {} |
| 348 | |
| 349 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 350 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 351 | __ Bind(GetEntryLabel()); |
| 352 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 353 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 354 | instruction_, |
| 355 | instruction_->GetDexPc(), |
| 356 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 357 | // No need to restore live registers. |
| 358 | DCHECK(instruction_->IsDeoptimize()); |
| 359 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 360 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 361 | codegen->RecordPcInfo(instruction_, dex_pc, this); |
| 362 | } |
| 363 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 364 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 365 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 366 | private: |
| 367 | HInstruction* const instruction_; |
| 368 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 369 | }; |
| 370 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 371 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 372 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 373 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 374 | inline Condition X86SignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 375 | switch (cond) { |
| 376 | case kCondEQ: return kEqual; |
| 377 | case kCondNE: return kNotEqual; |
| 378 | case kCondLT: return kLess; |
| 379 | case kCondLE: return kLessEqual; |
| 380 | case kCondGT: return kGreater; |
| 381 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 382 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 383 | LOG(FATAL) << "Unreachable"; |
| 384 | UNREACHABLE(); |
| 385 | } |
| 386 | |
| 387 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 388 | switch (cond) { |
| 389 | case kCondEQ: return kEqual; |
| 390 | case kCondNE: return kNotEqual; |
| 391 | case kCondLT: return kBelow; |
| 392 | case kCondLE: return kBelowEqual; |
| 393 | case kCondGT: return kAbove; |
| 394 | case kCondGE: return kAboveEqual; |
| 395 | } |
| 396 | LOG(FATAL) << "Unreachable"; |
| 397 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 400 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 401 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 405 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 406 | } |
| 407 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 408 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 409 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 410 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 413 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 414 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 415 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 416 | } |
| 417 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 418 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 419 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 420 | return GetFloatingPointSpillSlotSize(); |
| 421 | } |
| 422 | |
| 423 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 424 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 425 | return GetFloatingPointSpillSlotSize(); |
| 426 | } |
| 427 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 428 | void CodeGeneratorX86::InvokeRuntime(Address entry_point, |
| 429 | HInstruction* instruction, |
| 430 | uint32_t dex_pc, |
| 431 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 432 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 433 | __ fs()->call(entry_point); |
| 434 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 435 | } |
| 436 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 437 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| 438 | const X86InstructionSetFeatures& isa_features, |
| 439 | const CompilerOptions& compiler_options) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 440 | : CodeGenerator(graph, |
| 441 | kNumberOfCpuRegisters, |
| 442 | kNumberOfXmmRegisters, |
| 443 | kNumberOfRegisterPairs, |
| 444 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 445 | arraysize(kCoreCalleeSaves)) |
| 446 | | (1 << kFakeReturnRegister), |
| 447 | 0, |
| 448 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 449 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 450 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 451 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 452 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame^] | 453 | isa_features_(isa_features) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 454 | // Use a fake return address register to mimic Quick. |
| 455 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 456 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 457 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 458 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 459 | switch (type) { |
| 460 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 461 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 462 | X86ManagedRegister pair = |
| 463 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 464 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 465 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 466 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 467 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 468 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 469 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | case Primitive::kPrimByte: |
| 473 | case Primitive::kPrimBoolean: |
| 474 | case Primitive::kPrimChar: |
| 475 | case Primitive::kPrimShort: |
| 476 | case Primitive::kPrimInt: |
| 477 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 478 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 479 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 480 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 481 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 482 | X86ManagedRegister current = |
| 483 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 484 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 485 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 486 | } |
| 487 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 488 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 492 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 493 | return Location::FpuRegisterLocation( |
| 494 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 495 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 496 | |
| 497 | case Primitive::kPrimVoid: |
| 498 | LOG(FATAL) << "Unreachable type " << type; |
| 499 | } |
| 500 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 501 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 502 | } |
| 503 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 504 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 505 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 506 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 507 | |
| 508 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 509 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 510 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 511 | if (is_baseline) { |
| 512 | blocked_core_registers_[EBP] = true; |
| 513 | blocked_core_registers_[ESI] = true; |
| 514 | blocked_core_registers_[EDI] = true; |
| 515 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 516 | |
| 517 | UpdateBlockedPairRegisters(); |
| 518 | } |
| 519 | |
| 520 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 521 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 522 | X86ManagedRegister current = |
| 523 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 524 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 525 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 526 | blocked_register_pairs_[i] = true; |
| 527 | } |
| 528 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 531 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 532 | : HGraphVisitor(graph), |
| 533 | assembler_(codegen->GetAssembler()), |
| 534 | codegen_(codegen) {} |
| 535 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 536 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 537 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 538 | } |
| 539 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 540 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 541 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 542 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 543 | bool skip_overflow_check = |
| 544 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 545 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 546 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 547 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 548 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 549 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 550 | } |
| 551 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 552 | if (HasEmptyFrame()) { |
| 553 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 554 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 555 | |
| 556 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 557 | Register reg = kCoreCalleeSaves[i]; |
| 558 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 559 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 560 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 561 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 565 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 566 | __ subl(ESP, Immediate(adjust)); |
| 567 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 568 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 572 | __ cfi().RememberState(); |
| 573 | if (!HasEmptyFrame()) { |
| 574 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 575 | __ addl(ESP, Immediate(adjust)); |
| 576 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 577 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 578 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 579 | Register reg = kCoreCalleeSaves[i]; |
| 580 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 581 | __ popl(reg); |
| 582 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 583 | __ cfi().Restore(DWARFReg(reg)); |
| 584 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 585 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 586 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 587 | __ ret(); |
| 588 | __ cfi().RestoreState(); |
| 589 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 592 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 593 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 596 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 597 | switch (load->GetType()) { |
| 598 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 599 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 600 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 601 | |
| 602 | case Primitive::kPrimInt: |
| 603 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 604 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 605 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 606 | |
| 607 | case Primitive::kPrimBoolean: |
| 608 | case Primitive::kPrimByte: |
| 609 | case Primitive::kPrimChar: |
| 610 | case Primitive::kPrimShort: |
| 611 | case Primitive::kPrimVoid: |
| 612 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 613 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 617 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 618 | } |
| 619 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 620 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 621 | switch (type) { |
| 622 | case Primitive::kPrimBoolean: |
| 623 | case Primitive::kPrimByte: |
| 624 | case Primitive::kPrimChar: |
| 625 | case Primitive::kPrimShort: |
| 626 | case Primitive::kPrimInt: |
| 627 | case Primitive::kPrimNot: |
| 628 | return Location::RegisterLocation(EAX); |
| 629 | |
| 630 | case Primitive::kPrimLong: |
| 631 | return Location::RegisterPairLocation(EAX, EDX); |
| 632 | |
| 633 | case Primitive::kPrimVoid: |
| 634 | return Location::NoLocation(); |
| 635 | |
| 636 | case Primitive::kPrimDouble: |
| 637 | case Primitive::kPrimFloat: |
| 638 | return Location::FpuRegisterLocation(XMM0); |
| 639 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 640 | |
| 641 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 645 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 646 | } |
| 647 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 648 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 649 | switch (type) { |
| 650 | case Primitive::kPrimBoolean: |
| 651 | case Primitive::kPrimByte: |
| 652 | case Primitive::kPrimChar: |
| 653 | case Primitive::kPrimShort: |
| 654 | case Primitive::kPrimInt: |
| 655 | case Primitive::kPrimNot: { |
| 656 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 657 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 658 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 659 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 660 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 661 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 662 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 663 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 664 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 665 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 666 | uint32_t index = gp_index_; |
| 667 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 668 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 669 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 670 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 671 | calling_convention.GetRegisterPairAt(index)); |
| 672 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 673 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 674 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 679 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 680 | stack_index_++; |
| 681 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 682 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 683 | } else { |
| 684 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 689 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 690 | stack_index_ += 2; |
| 691 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 692 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 693 | } else { |
| 694 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 698 | case Primitive::kPrimVoid: |
| 699 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 700 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 701 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 702 | return Location(); |
| 703 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 704 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 705 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 706 | if (source.Equals(destination)) { |
| 707 | return; |
| 708 | } |
| 709 | if (destination.IsRegister()) { |
| 710 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 711 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 712 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 713 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 714 | } else { |
| 715 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 716 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 717 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 718 | } else if (destination.IsFpuRegister()) { |
| 719 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 720 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 721 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 722 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 723 | } else { |
| 724 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 725 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 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.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 729 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 730 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 731 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 732 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 733 | } else if (source.IsConstant()) { |
| 734 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 735 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 736 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 737 | } else { |
| 738 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 739 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 740 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 746 | if (source.Equals(destination)) { |
| 747 | return; |
| 748 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 749 | if (destination.IsRegisterPair()) { |
| 750 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 751 | EmitParallelMoves( |
| 752 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 753 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 754 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 755 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 756 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 757 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 758 | } else if (source.IsFpuRegister()) { |
| 759 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 760 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 761 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 762 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 763 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 764 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 765 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 766 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 767 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 768 | if (source.IsFpuRegister()) { |
| 769 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 770 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 771 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 772 | } else { |
| 773 | LOG(FATAL) << "Unimplemented"; |
| 774 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 775 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 776 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 777 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 778 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 779 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 780 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 781 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 782 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 783 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 784 | } else if (source.IsConstant()) { |
| 785 | HConstant* constant = source.GetConstant(); |
| 786 | int64_t value; |
| 787 | if (constant->IsLongConstant()) { |
| 788 | value = constant->AsLongConstant()->GetValue(); |
| 789 | } else { |
| 790 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 791 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 792 | } |
| 793 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 794 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 795 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 796 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 797 | EmitParallelMoves( |
| 798 | Location::StackSlot(source.GetStackIndex()), |
| 799 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 800 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 801 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 802 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 803 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 808 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 809 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 810 | if (instruction->IsCurrentMethod()) { |
| 811 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 812 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 813 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 814 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 815 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 816 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 817 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 818 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 819 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 820 | } else if (location.IsStackSlot()) { |
| 821 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 822 | } else { |
| 823 | DCHECK(location.IsConstant()); |
| 824 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 825 | } |
| 826 | } else if (const_to_move->IsLongConstant()) { |
| 827 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 828 | if (location.IsRegisterPair()) { |
| 829 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 830 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 831 | } else if (location.IsDoubleStackSlot()) { |
| 832 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 833 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 834 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 835 | } else { |
| 836 | DCHECK(location.IsConstant()); |
| 837 | DCHECK_EQ(location.GetConstant(), instruction); |
| 838 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 839 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 840 | } else if (instruction->IsTemporary()) { |
| 841 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 842 | if (temp_location.IsStackSlot()) { |
| 843 | Move32(location, temp_location); |
| 844 | } else { |
| 845 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 846 | Move64(location, temp_location); |
| 847 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 848 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 849 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 850 | switch (instruction->GetType()) { |
| 851 | case Primitive::kPrimBoolean: |
| 852 | case Primitive::kPrimByte: |
| 853 | case Primitive::kPrimChar: |
| 854 | case Primitive::kPrimShort: |
| 855 | case Primitive::kPrimInt: |
| 856 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 857 | case Primitive::kPrimFloat: |
| 858 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 859 | break; |
| 860 | |
| 861 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 862 | case Primitive::kPrimDouble: |
| 863 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | default: |
| 867 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 868 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 869 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 870 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 871 | switch (instruction->GetType()) { |
| 872 | case Primitive::kPrimBoolean: |
| 873 | case Primitive::kPrimByte: |
| 874 | case Primitive::kPrimChar: |
| 875 | case Primitive::kPrimShort: |
| 876 | case Primitive::kPrimInt: |
| 877 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 878 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 879 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 880 | break; |
| 881 | |
| 882 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 883 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 884 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 885 | break; |
| 886 | |
| 887 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 888 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 889 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 893 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 894 | DCHECK(!successor->IsExitBlock()); |
| 895 | |
| 896 | HBasicBlock* block = got->GetBlock(); |
| 897 | HInstruction* previous = got->GetPrevious(); |
| 898 | |
| 899 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 900 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 901 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 902 | return; |
| 903 | } |
| 904 | |
| 905 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 906 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 907 | } |
| 908 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 909 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 913 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 914 | got->SetLocations(nullptr); |
| 915 | } |
| 916 | |
| 917 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 918 | HandleGoto(got, got->GetSuccessor()); |
| 919 | } |
| 920 | |
| 921 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 922 | try_boundary->SetLocations(nullptr); |
| 923 | } |
| 924 | |
| 925 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 926 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 927 | if (!successor->IsExitBlock()) { |
| 928 | HandleGoto(try_boundary, successor); |
| 929 | } |
| 930 | } |
| 931 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 932 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 933 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 936 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 937 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 938 | } |
| 939 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 940 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 941 | Label* true_label, |
| 942 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 943 | if (cond->IsFPConditionTrueIfNaN()) { |
| 944 | __ j(kUnordered, true_label); |
| 945 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 946 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 947 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 948 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 952 | Label* true_label, |
| 953 | Label* false_label) { |
| 954 | LocationSummary* locations = cond->GetLocations(); |
| 955 | Location left = locations->InAt(0); |
| 956 | Location right = locations->InAt(1); |
| 957 | IfCondition if_cond = cond->GetCondition(); |
| 958 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 959 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 960 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 961 | IfCondition true_high_cond = if_cond; |
| 962 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 963 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 964 | |
| 965 | // Set the conditions for the test, remembering that == needs to be |
| 966 | // decided using the low words. |
| 967 | switch (if_cond) { |
| 968 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 969 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 970 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 971 | break; |
| 972 | case kCondLT: |
| 973 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 974 | break; |
| 975 | case kCondLE: |
| 976 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 977 | break; |
| 978 | case kCondGT: |
| 979 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 980 | break; |
| 981 | case kCondGE: |
| 982 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 983 | break; |
| 984 | } |
| 985 | |
| 986 | if (right.IsConstant()) { |
| 987 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 988 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 989 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 990 | |
| 991 | if (val_high == 0) { |
| 992 | __ testl(left_high, left_high); |
| 993 | } else { |
| 994 | __ cmpl(left_high, Immediate(val_high)); |
| 995 | } |
| 996 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 997 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 998 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 999 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1000 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1001 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1002 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1003 | } |
| 1004 | // Must be equal high, so compare the lows. |
| 1005 | if (val_low == 0) { |
| 1006 | __ testl(left_low, left_low); |
| 1007 | } else { |
| 1008 | __ cmpl(left_low, Immediate(val_low)); |
| 1009 | } |
| 1010 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1011 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1012 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1013 | |
| 1014 | __ cmpl(left_high, right_high); |
| 1015 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1016 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1017 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1018 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1019 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1020 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1021 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1022 | } |
| 1023 | // Must be equal high, so compare the lows. |
| 1024 | __ cmpl(left_low, right_low); |
| 1025 | } |
| 1026 | // The last comparison might be unsigned. |
| 1027 | __ j(final_condition, true_label); |
| 1028 | } |
| 1029 | |
| 1030 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1031 | HCondition* condition, |
| 1032 | Label* true_target, |
| 1033 | Label* false_target, |
| 1034 | Label* always_true_target) { |
| 1035 | LocationSummary* locations = condition->GetLocations(); |
| 1036 | Location left = locations->InAt(0); |
| 1037 | Location right = locations->InAt(1); |
| 1038 | |
| 1039 | // We don't want true_target as a nullptr. |
| 1040 | if (true_target == nullptr) { |
| 1041 | true_target = always_true_target; |
| 1042 | } |
| 1043 | bool falls_through = (false_target == nullptr); |
| 1044 | |
| 1045 | // FP compares don't like null false_targets. |
| 1046 | if (false_target == nullptr) { |
| 1047 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1048 | } |
| 1049 | |
| 1050 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1051 | switch (type) { |
| 1052 | case Primitive::kPrimLong: |
| 1053 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1054 | break; |
| 1055 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1056 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1057 | GenerateFPJumps(condition, true_target, false_target); |
| 1058 | break; |
| 1059 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1060 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1061 | GenerateFPJumps(condition, true_target, false_target); |
| 1062 | break; |
| 1063 | default: |
| 1064 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1065 | } |
| 1066 | |
| 1067 | if (!falls_through) { |
| 1068 | __ jmp(false_target); |
| 1069 | } |
| 1070 | } |
| 1071 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1072 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| 1073 | Label* true_target, |
| 1074 | Label* false_target, |
| 1075 | Label* always_true_target) { |
| 1076 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1077 | if (cond->IsIntConstant()) { |
| 1078 | // Constant condition, statically compared against 1. |
| 1079 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1080 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1081 | if (always_true_target != nullptr) { |
| 1082 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1083 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1084 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1085 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1086 | DCHECK_EQ(cond_value, 0); |
| 1087 | } |
| 1088 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1089 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1090 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1091 | // Moves do not affect the eflags register, so if the condition is |
| 1092 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1093 | // again. We can't use the eflags on long/FP conditions if they are |
| 1094 | // materialized due to the complex branching. |
| 1095 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1096 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1097 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1098 | && (type != Primitive::kPrimLong && !Primitive::IsFloatingPointType(type)); |
| 1099 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1100 | if (!eflags_set) { |
| 1101 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1102 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1103 | if (lhs.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1104 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1105 | } else { |
| 1106 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1107 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1108 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1109 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1110 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1111 | } |
| 1112 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1113 | // Condition has not been materialized, use its inputs as the |
| 1114 | // comparison and its condition as the branch condition. |
| 1115 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1116 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1117 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1118 | // Generate the comparison directly. |
| 1119 | GenerateCompareTestAndBranch(instruction->AsIf(), |
| 1120 | cond->AsCondition(), |
| 1121 | true_target, |
| 1122 | false_target, |
| 1123 | always_true_target); |
| 1124 | return; |
| 1125 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1126 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1127 | Location lhs = cond->GetLocations()->InAt(0); |
| 1128 | Location rhs = cond->GetLocations()->InAt(1); |
| 1129 | // LHS is guaranteed to be in a register (see |
| 1130 | // LocationsBuilderX86::VisitCondition). |
| 1131 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1132 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1133 | } else if (rhs.IsConstant()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame] | 1134 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1135 | if (constant == 0) { |
| 1136 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1137 | } else { |
| 1138 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1139 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1140 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1141 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1142 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1143 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1144 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1145 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1146 | if (false_target != nullptr) { |
| 1147 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1151 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| 1152 | LocationSummary* locations = |
| 1153 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1154 | HInstruction* cond = if_instr->InputAt(0); |
| 1155 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1156 | locations->SetInAt(0, Location::Any()); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| 1161 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1162 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1163 | Label* always_true_target = true_target; |
| 1164 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1165 | if_instr->IfTrueSuccessor())) { |
| 1166 | always_true_target = nullptr; |
| 1167 | } |
| 1168 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1169 | if_instr->IfFalseSuccessor())) { |
| 1170 | false_target = nullptr; |
| 1171 | } |
| 1172 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1173 | } |
| 1174 | |
| 1175 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1176 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1177 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1178 | HInstruction* cond = deoptimize->InputAt(0); |
| 1179 | DCHECK(cond->IsCondition()); |
| 1180 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1181 | locations->SetInAt(0, Location::Any()); |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1186 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) |
| 1187 | DeoptimizationSlowPathX86(deoptimize); |
| 1188 | codegen_->AddSlowPath(slow_path); |
| 1189 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1190 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1191 | } |
| 1192 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1193 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1194 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1197 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1198 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1201 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1202 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1205 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1206 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1207 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1210 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1211 | LocationSummary* locations = |
| 1212 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1213 | switch (store->InputAt(1)->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: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1220 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1221 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1222 | break; |
| 1223 | |
| 1224 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1225 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1226 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1227 | break; |
| 1228 | |
| 1229 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1230 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1231 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1234 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1235 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1238 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1239 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1240 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1241 | // Handle the long/FP comparisons made in instruction simplification. |
| 1242 | switch (cond->InputAt(0)->GetType()) { |
| 1243 | case Primitive::kPrimLong: { |
| 1244 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1245 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1246 | if (cond->NeedsMaterialization()) { |
| 1247 | locations->SetOut(Location::RequiresRegister()); |
| 1248 | } |
| 1249 | break; |
| 1250 | } |
| 1251 | case Primitive::kPrimFloat: |
| 1252 | case Primitive::kPrimDouble: { |
| 1253 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1254 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1255 | if (cond->NeedsMaterialization()) { |
| 1256 | locations->SetOut(Location::RequiresRegister()); |
| 1257 | } |
| 1258 | break; |
| 1259 | } |
| 1260 | default: |
| 1261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1262 | locations->SetInAt(1, Location::Any()); |
| 1263 | if (cond->NeedsMaterialization()) { |
| 1264 | // We need a byte register. |
| 1265 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1266 | } |
| 1267 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1268 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1271 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1272 | if (!cond->NeedsMaterialization()) { |
| 1273 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1274 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 | |
| 1276 | LocationSummary* locations = cond->GetLocations(); |
| 1277 | Location lhs = locations->InAt(0); |
| 1278 | Location rhs = locations->InAt(1); |
| 1279 | Register reg = locations->Out().AsRegister<Register>(); |
| 1280 | Label true_label, false_label; |
| 1281 | |
| 1282 | switch (cond->InputAt(0)->GetType()) { |
| 1283 | default: { |
| 1284 | // Integer case. |
| 1285 | |
| 1286 | // Clear output register: setcc only sets the low byte. |
| 1287 | __ xorl(reg, reg); |
| 1288 | |
| 1289 | if (rhs.IsRegister()) { |
| 1290 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1291 | } else if (rhs.IsConstant()) { |
| 1292 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1293 | if (constant == 0) { |
| 1294 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1295 | } else { |
| 1296 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1297 | } |
| 1298 | } else { |
| 1299 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1300 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1301 | __ setb(X86SignedCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1302 | return; |
| 1303 | } |
| 1304 | case Primitive::kPrimLong: |
| 1305 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1306 | break; |
| 1307 | case Primitive::kPrimFloat: |
| 1308 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1309 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1310 | break; |
| 1311 | case Primitive::kPrimDouble: |
| 1312 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1313 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1314 | break; |
| 1315 | } |
| 1316 | |
| 1317 | // Convert the jumps into the result. |
| 1318 | Label done_label; |
| 1319 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1320 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1321 | __ Bind(&false_label); |
| 1322 | __ xorl(reg, reg); |
| 1323 | __ jmp(&done_label); |
| 1324 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1325 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1326 | __ Bind(&true_label); |
| 1327 | __ movl(reg, Immediate(1)); |
| 1328 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1332 | VisitCondition(comp); |
| 1333 | } |
| 1334 | |
| 1335 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1336 | VisitCondition(comp); |
| 1337 | } |
| 1338 | |
| 1339 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1340 | VisitCondition(comp); |
| 1341 | } |
| 1342 | |
| 1343 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1344 | VisitCondition(comp); |
| 1345 | } |
| 1346 | |
| 1347 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1348 | VisitCondition(comp); |
| 1349 | } |
| 1350 | |
| 1351 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1352 | VisitCondition(comp); |
| 1353 | } |
| 1354 | |
| 1355 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1356 | VisitCondition(comp); |
| 1357 | } |
| 1358 | |
| 1359 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1360 | VisitCondition(comp); |
| 1361 | } |
| 1362 | |
| 1363 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1364 | VisitCondition(comp); |
| 1365 | } |
| 1366 | |
| 1367 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1368 | VisitCondition(comp); |
| 1369 | } |
| 1370 | |
| 1371 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1372 | VisitCondition(comp); |
| 1373 | } |
| 1374 | |
| 1375 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1376 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1380 | LocationSummary* locations = |
| 1381 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1382 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1385 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1386 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1387 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1390 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1391 | LocationSummary* locations = |
| 1392 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1393 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1394 | } |
| 1395 | |
| 1396 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant) { |
| 1397 | // Will be generated at use site. |
| 1398 | UNUSED(constant); |
| 1399 | } |
| 1400 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1401 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1402 | LocationSummary* locations = |
| 1403 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1404 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 1408 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1409 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1412 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1413 | LocationSummary* locations = |
| 1414 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1415 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1416 | } |
| 1417 | |
| 1418 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1419 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1420 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1424 | LocationSummary* locations = |
| 1425 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1426 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1427 | } |
| 1428 | |
| 1429 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1430 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1431 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1432 | } |
| 1433 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1434 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1435 | memory_barrier->SetLocations(nullptr); |
| 1436 | } |
| 1437 | |
| 1438 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1439 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1440 | } |
| 1441 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1442 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1443 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1446 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1447 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1448 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1451 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1452 | LocationSummary* locations = |
| 1453 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1454 | switch (ret->InputAt(0)->GetType()) { |
| 1455 | case Primitive::kPrimBoolean: |
| 1456 | case Primitive::kPrimByte: |
| 1457 | case Primitive::kPrimChar: |
| 1458 | case Primitive::kPrimShort: |
| 1459 | case Primitive::kPrimInt: |
| 1460 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1461 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1462 | break; |
| 1463 | |
| 1464 | case Primitive::kPrimLong: |
| 1465 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1466 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1467 | break; |
| 1468 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1469 | case Primitive::kPrimFloat: |
| 1470 | case Primitive::kPrimDouble: |
| 1471 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1472 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1473 | break; |
| 1474 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1475 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1476 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1477 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1480 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1481 | if (kIsDebugBuild) { |
| 1482 | switch (ret->InputAt(0)->GetType()) { |
| 1483 | case Primitive::kPrimBoolean: |
| 1484 | case Primitive::kPrimByte: |
| 1485 | case Primitive::kPrimChar: |
| 1486 | case Primitive::kPrimShort: |
| 1487 | case Primitive::kPrimInt: |
| 1488 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1489 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1490 | break; |
| 1491 | |
| 1492 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1493 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1494 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1495 | break; |
| 1496 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1497 | case Primitive::kPrimFloat: |
| 1498 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1499 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1500 | break; |
| 1501 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1502 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1503 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1504 | } |
| 1505 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1506 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1509 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1510 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1511 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1512 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1513 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1514 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1515 | if (intrinsic.TryDispatch(invoke)) { |
| 1516 | return; |
| 1517 | } |
| 1518 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1519 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1520 | |
| 1521 | if (codegen_->IsBaseline()) { |
| 1522 | // Baseline does not have enough registers if the current method also |
| 1523 | // needs a register. We therefore do not require a register for it, and let |
| 1524 | // the code generation of the invoke handle it. |
| 1525 | LocationSummary* locations = invoke->GetLocations(); |
| 1526 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 1527 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 1528 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 1529 | } |
| 1530 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1531 | } |
| 1532 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1533 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1534 | if (invoke->GetLocations()->Intrinsified()) { |
| 1535 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1536 | intrinsic.Dispatch(invoke); |
| 1537 | return true; |
| 1538 | } |
| 1539 | return false; |
| 1540 | } |
| 1541 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1542 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1543 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1544 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1545 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1546 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1547 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1548 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1549 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1550 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1551 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1552 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1553 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1554 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1558 | HandleInvoke(invoke); |
| 1559 | } |
| 1560 | |
| 1561 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1562 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1563 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1566 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1567 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1568 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1569 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1570 | LocationSummary* locations = invoke->GetLocations(); |
| 1571 | Location receiver = locations->InAt(0); |
| 1572 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1573 | // temp = object->GetClass(); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1574 | DCHECK(receiver.IsRegister()); |
| 1575 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1576 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1577 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1578 | // temp = temp->GetMethodAt(method_offset); |
| 1579 | __ movl(temp, Address(temp, method_offset)); |
| 1580 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1581 | __ call(Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1582 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1583 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1584 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1585 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1588 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1589 | HandleInvoke(invoke); |
| 1590 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1591 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1595 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1596 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1597 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1598 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1599 | LocationSummary* locations = invoke->GetLocations(); |
| 1600 | Location receiver = locations->InAt(0); |
| 1601 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1602 | |
| 1603 | // Set the hidden argument. |
| 1604 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1605 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1606 | |
| 1607 | // temp = object->GetClass(); |
| 1608 | if (receiver.IsStackSlot()) { |
| 1609 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1610 | __ movl(temp, Address(temp, class_offset)); |
| 1611 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1612 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1613 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1614 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1615 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1616 | // temp = temp->GetImtEntryAt(method_offset); |
| 1617 | __ movl(temp, Address(temp, method_offset)); |
| 1618 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1619 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1620 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1621 | |
| 1622 | DCHECK(!codegen_->IsLeafMethod()); |
| 1623 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1624 | } |
| 1625 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1626 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1627 | LocationSummary* locations = |
| 1628 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1629 | switch (neg->GetResultType()) { |
| 1630 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1631 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1632 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1633 | locations->SetOut(Location::SameAsFirstInput()); |
| 1634 | break; |
| 1635 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1636 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1637 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1638 | locations->SetOut(Location::SameAsFirstInput()); |
| 1639 | locations->AddTemp(Location::RequiresRegister()); |
| 1640 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1641 | break; |
| 1642 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1643 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1644 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1645 | locations->SetOut(Location::SameAsFirstInput()); |
| 1646 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1647 | break; |
| 1648 | |
| 1649 | default: |
| 1650 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1655 | LocationSummary* locations = neg->GetLocations(); |
| 1656 | Location out = locations->Out(); |
| 1657 | Location in = locations->InAt(0); |
| 1658 | switch (neg->GetResultType()) { |
| 1659 | case Primitive::kPrimInt: |
| 1660 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1661 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1662 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1663 | break; |
| 1664 | |
| 1665 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1666 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1667 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1668 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1669 | // Negation is similar to subtraction from zero. The least |
| 1670 | // significant byte triggers a borrow when it is different from |
| 1671 | // zero; to take it into account, add 1 to the most significant |
| 1672 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1673 | // operation. |
| 1674 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1675 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1676 | break; |
| 1677 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1678 | case Primitive::kPrimFloat: { |
| 1679 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1680 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1681 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1682 | // Implement float negation with an exclusive or with value |
| 1683 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1684 | // single-precision floating-point number). |
| 1685 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1686 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1687 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1688 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1689 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1690 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1691 | case Primitive::kPrimDouble: { |
| 1692 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1693 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1694 | // Implement double negation with an exclusive or with value |
| 1695 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1696 | // a double-precision floating-point number). |
| 1697 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1698 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1699 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1700 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1701 | |
| 1702 | default: |
| 1703 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1704 | } |
| 1705 | } |
| 1706 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1707 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1708 | Primitive::Type result_type = conversion->GetResultType(); |
| 1709 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1710 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1711 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1712 | // The float-to-long and double-to-long type conversions rely on a |
| 1713 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1714 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1715 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1716 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1717 | ? LocationSummary::kCall |
| 1718 | : LocationSummary::kNoCall; |
| 1719 | LocationSummary* locations = |
| 1720 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1721 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1722 | // The Java language does not allow treating boolean as an integral type but |
| 1723 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1724 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1725 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1726 | case Primitive::kPrimByte: |
| 1727 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1728 | case Primitive::kPrimBoolean: |
| 1729 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1730 | case Primitive::kPrimShort: |
| 1731 | case Primitive::kPrimInt: |
| 1732 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1733 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1734 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1735 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1736 | // the validation of the linear scan implementation |
| 1737 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1738 | break; |
| 1739 | |
| 1740 | default: |
| 1741 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1742 | << " to " << result_type; |
| 1743 | } |
| 1744 | break; |
| 1745 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1746 | case Primitive::kPrimShort: |
| 1747 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1748 | case Primitive::kPrimBoolean: |
| 1749 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1750 | case Primitive::kPrimByte: |
| 1751 | case Primitive::kPrimInt: |
| 1752 | case Primitive::kPrimChar: |
| 1753 | // Processing a Dex `int-to-short' instruction. |
| 1754 | locations->SetInAt(0, Location::Any()); |
| 1755 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1756 | break; |
| 1757 | |
| 1758 | default: |
| 1759 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1760 | << " to " << result_type; |
| 1761 | } |
| 1762 | break; |
| 1763 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1764 | case Primitive::kPrimInt: |
| 1765 | switch (input_type) { |
| 1766 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1767 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1768 | locations->SetInAt(0, Location::Any()); |
| 1769 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1770 | break; |
| 1771 | |
| 1772 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1773 | // Processing a Dex `float-to-int' instruction. |
| 1774 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1775 | locations->SetOut(Location::RequiresRegister()); |
| 1776 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1777 | break; |
| 1778 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1779 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1780 | // Processing a Dex `double-to-int' instruction. |
| 1781 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1782 | locations->SetOut(Location::RequiresRegister()); |
| 1783 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1784 | break; |
| 1785 | |
| 1786 | default: |
| 1787 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1788 | << " to " << result_type; |
| 1789 | } |
| 1790 | break; |
| 1791 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1792 | case Primitive::kPrimLong: |
| 1793 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1794 | case Primitive::kPrimBoolean: |
| 1795 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1796 | case Primitive::kPrimByte: |
| 1797 | case Primitive::kPrimShort: |
| 1798 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1799 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1800 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1801 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1802 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1803 | break; |
| 1804 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1805 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1806 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1807 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1808 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1809 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1810 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1811 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1812 | // The runtime helper puts the result in EAX, EDX. |
| 1813 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1814 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1815 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1816 | |
| 1817 | default: |
| 1818 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1819 | << " to " << result_type; |
| 1820 | } |
| 1821 | break; |
| 1822 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1823 | case Primitive::kPrimChar: |
| 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 | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1827 | case Primitive::kPrimByte: |
| 1828 | case Primitive::kPrimShort: |
| 1829 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1830 | // Processing a Dex `int-to-char' instruction. |
| 1831 | locations->SetInAt(0, Location::Any()); |
| 1832 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1833 | break; |
| 1834 | |
| 1835 | default: |
| 1836 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1837 | << " to " << result_type; |
| 1838 | } |
| 1839 | break; |
| 1840 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1841 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1842 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1843 | case Primitive::kPrimBoolean: |
| 1844 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1845 | case Primitive::kPrimByte: |
| 1846 | case Primitive::kPrimShort: |
| 1847 | case Primitive::kPrimInt: |
| 1848 | case Primitive::kPrimChar: |
| 1849 | // Processing a Dex `int-to-float' instruction. |
| 1850 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1851 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1852 | break; |
| 1853 | |
| 1854 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1855 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1856 | locations->SetInAt(0, Location::Any()); |
| 1857 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1858 | break; |
| 1859 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1860 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1861 | // Processing a Dex `double-to-float' instruction. |
| 1862 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1863 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1864 | break; |
| 1865 | |
| 1866 | default: |
| 1867 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1868 | << " to " << result_type; |
| 1869 | }; |
| 1870 | break; |
| 1871 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1872 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1873 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1874 | case Primitive::kPrimBoolean: |
| 1875 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1876 | case Primitive::kPrimByte: |
| 1877 | case Primitive::kPrimShort: |
| 1878 | case Primitive::kPrimInt: |
| 1879 | case Primitive::kPrimChar: |
| 1880 | // Processing a Dex `int-to-double' instruction. |
| 1881 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1882 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1883 | break; |
| 1884 | |
| 1885 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1886 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1887 | locations->SetInAt(0, Location::Any()); |
| 1888 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1889 | break; |
| 1890 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1891 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1892 | // Processing a Dex `float-to-double' instruction. |
| 1893 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1894 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1895 | break; |
| 1896 | |
| 1897 | default: |
| 1898 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1899 | << " to " << result_type; |
| 1900 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1901 | break; |
| 1902 | |
| 1903 | default: |
| 1904 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1905 | << " to " << result_type; |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1910 | LocationSummary* locations = conversion->GetLocations(); |
| 1911 | Location out = locations->Out(); |
| 1912 | Location in = locations->InAt(0); |
| 1913 | Primitive::Type result_type = conversion->GetResultType(); |
| 1914 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1915 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1916 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1917 | case Primitive::kPrimByte: |
| 1918 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1919 | case Primitive::kPrimBoolean: |
| 1920 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1921 | case Primitive::kPrimShort: |
| 1922 | case Primitive::kPrimInt: |
| 1923 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1924 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1925 | if (in.IsRegister()) { |
| 1926 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1927 | } else { |
| 1928 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1929 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1930 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 1931 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1932 | break; |
| 1933 | |
| 1934 | default: |
| 1935 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1936 | << " to " << result_type; |
| 1937 | } |
| 1938 | break; |
| 1939 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1940 | case Primitive::kPrimShort: |
| 1941 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1942 | case Primitive::kPrimBoolean: |
| 1943 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1944 | case Primitive::kPrimByte: |
| 1945 | case Primitive::kPrimInt: |
| 1946 | case Primitive::kPrimChar: |
| 1947 | // Processing a Dex `int-to-short' instruction. |
| 1948 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1949 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1950 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1951 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1952 | } else { |
| 1953 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1954 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1955 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1956 | } |
| 1957 | break; |
| 1958 | |
| 1959 | default: |
| 1960 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1961 | << " to " << result_type; |
| 1962 | } |
| 1963 | break; |
| 1964 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1965 | case Primitive::kPrimInt: |
| 1966 | switch (input_type) { |
| 1967 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1968 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1969 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1970 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1971 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1972 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1973 | } else { |
| 1974 | DCHECK(in.IsConstant()); |
| 1975 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1976 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1977 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1978 | } |
| 1979 | break; |
| 1980 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1981 | case Primitive::kPrimFloat: { |
| 1982 | // Processing a Dex `float-to-int' instruction. |
| 1983 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1984 | Register output = out.AsRegister<Register>(); |
| 1985 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1986 | Label done, nan; |
| 1987 | |
| 1988 | __ movl(output, Immediate(kPrimIntMax)); |
| 1989 | // temp = int-to-float(output) |
| 1990 | __ cvtsi2ss(temp, output); |
| 1991 | // if input >= temp goto done |
| 1992 | __ comiss(input, temp); |
| 1993 | __ j(kAboveEqual, &done); |
| 1994 | // if input == NaN goto nan |
| 1995 | __ j(kUnordered, &nan); |
| 1996 | // output = float-to-int-truncate(input) |
| 1997 | __ cvttss2si(output, input); |
| 1998 | __ jmp(&done); |
| 1999 | __ Bind(&nan); |
| 2000 | // output = 0 |
| 2001 | __ xorl(output, output); |
| 2002 | __ Bind(&done); |
| 2003 | break; |
| 2004 | } |
| 2005 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2006 | case Primitive::kPrimDouble: { |
| 2007 | // Processing a Dex `double-to-int' instruction. |
| 2008 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2009 | Register output = out.AsRegister<Register>(); |
| 2010 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2011 | Label done, nan; |
| 2012 | |
| 2013 | __ movl(output, Immediate(kPrimIntMax)); |
| 2014 | // temp = int-to-double(output) |
| 2015 | __ cvtsi2sd(temp, output); |
| 2016 | // if input >= temp goto done |
| 2017 | __ comisd(input, temp); |
| 2018 | __ j(kAboveEqual, &done); |
| 2019 | // if input == NaN goto nan |
| 2020 | __ j(kUnordered, &nan); |
| 2021 | // output = double-to-int-truncate(input) |
| 2022 | __ cvttsd2si(output, input); |
| 2023 | __ jmp(&done); |
| 2024 | __ Bind(&nan); |
| 2025 | // output = 0 |
| 2026 | __ xorl(output, output); |
| 2027 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2028 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2029 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2030 | |
| 2031 | default: |
| 2032 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2033 | << " to " << result_type; |
| 2034 | } |
| 2035 | break; |
| 2036 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2037 | case Primitive::kPrimLong: |
| 2038 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2039 | case Primitive::kPrimBoolean: |
| 2040 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2041 | case Primitive::kPrimByte: |
| 2042 | case Primitive::kPrimShort: |
| 2043 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2044 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2045 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2046 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2047 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2048 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2049 | __ cdq(); |
| 2050 | break; |
| 2051 | |
| 2052 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2053 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2054 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2055 | conversion, |
| 2056 | conversion->GetDexPc(), |
| 2057 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2058 | break; |
| 2059 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2060 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2061 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2062 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2063 | conversion, |
| 2064 | conversion->GetDexPc(), |
| 2065 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2066 | break; |
| 2067 | |
| 2068 | default: |
| 2069 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2070 | << " to " << result_type; |
| 2071 | } |
| 2072 | break; |
| 2073 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2074 | case Primitive::kPrimChar: |
| 2075 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2076 | case Primitive::kPrimBoolean: |
| 2077 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2078 | case Primitive::kPrimByte: |
| 2079 | case Primitive::kPrimShort: |
| 2080 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2081 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2082 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2083 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2084 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2085 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2086 | } else { |
| 2087 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2088 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2089 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2090 | } |
| 2091 | break; |
| 2092 | |
| 2093 | default: |
| 2094 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2095 | << " to " << result_type; |
| 2096 | } |
| 2097 | break; |
| 2098 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2099 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2100 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2101 | case Primitive::kPrimBoolean: |
| 2102 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2103 | case Primitive::kPrimByte: |
| 2104 | case Primitive::kPrimShort: |
| 2105 | case Primitive::kPrimInt: |
| 2106 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2107 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2108 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2109 | break; |
| 2110 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2111 | case Primitive::kPrimLong: { |
| 2112 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2113 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2114 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2115 | // Create stack space for the call to |
| 2116 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2117 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2118 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2119 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2120 | __ subl(ESP, Immediate(adjustment)); |
| 2121 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2122 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2123 | // Load the value to the FP stack, using temporaries if needed. |
| 2124 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2125 | |
| 2126 | if (out.IsStackSlot()) { |
| 2127 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2128 | } else { |
| 2129 | __ fstps(Address(ESP, 0)); |
| 2130 | Location stack_temp = Location::StackSlot(0); |
| 2131 | codegen_->Move32(out, stack_temp); |
| 2132 | } |
| 2133 | |
| 2134 | // Remove the temporary stack space we allocated. |
| 2135 | if (adjustment != 0) { |
| 2136 | __ addl(ESP, Immediate(adjustment)); |
| 2137 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2138 | break; |
| 2139 | } |
| 2140 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2141 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2142 | // Processing a Dex `double-to-float' instruction. |
| 2143 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2144 | break; |
| 2145 | |
| 2146 | default: |
| 2147 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2148 | << " to " << result_type; |
| 2149 | }; |
| 2150 | break; |
| 2151 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2152 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2153 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimBoolean: |
| 2155 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2156 | case Primitive::kPrimByte: |
| 2157 | case Primitive::kPrimShort: |
| 2158 | case Primitive::kPrimInt: |
| 2159 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2160 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2161 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2162 | break; |
| 2163 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2164 | case Primitive::kPrimLong: { |
| 2165 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2166 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2167 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2168 | // Create stack space for the call to |
| 2169 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2170 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2171 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2172 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2173 | __ subl(ESP, Immediate(adjustment)); |
| 2174 | } |
| 2175 | |
| 2176 | // Load the value to the FP stack, using temporaries if needed. |
| 2177 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2178 | |
| 2179 | if (out.IsDoubleStackSlot()) { |
| 2180 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2181 | } else { |
| 2182 | __ fstpl(Address(ESP, 0)); |
| 2183 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2184 | codegen_->Move64(out, stack_temp); |
| 2185 | } |
| 2186 | |
| 2187 | // Remove the temporary stack space we allocated. |
| 2188 | if (adjustment != 0) { |
| 2189 | __ addl(ESP, Immediate(adjustment)); |
| 2190 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2191 | break; |
| 2192 | } |
| 2193 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2194 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2195 | // Processing a Dex `float-to-double' instruction. |
| 2196 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2197 | break; |
| 2198 | |
| 2199 | default: |
| 2200 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2201 | << " to " << result_type; |
| 2202 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2203 | break; |
| 2204 | |
| 2205 | default: |
| 2206 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2207 | << " to " << result_type; |
| 2208 | } |
| 2209 | } |
| 2210 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2211 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2212 | LocationSummary* locations = |
| 2213 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2214 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2215 | case Primitive::kPrimInt: { |
| 2216 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2217 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2218 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2219 | break; |
| 2220 | } |
| 2221 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2222 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2223 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2224 | locations->SetInAt(1, Location::Any()); |
| 2225 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2226 | break; |
| 2227 | } |
| 2228 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2229 | case Primitive::kPrimFloat: |
| 2230 | case Primitive::kPrimDouble: { |
| 2231 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Calin Juravle | 3173c8a | 2015-02-23 15:53:39 +0000 | [diff] [blame] | 2232 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2233 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2234 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2235 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2236 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2237 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2238 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2239 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2240 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2244 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2245 | Location first = locations->InAt(0); |
| 2246 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2247 | Location out = locations->Out(); |
| 2248 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2249 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2250 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2251 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2252 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2253 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2254 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2255 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2256 | } else { |
| 2257 | __ leal(out.AsRegister<Register>(), Address( |
| 2258 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2259 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2260 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2261 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2262 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2263 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2264 | } else { |
| 2265 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2266 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2267 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2268 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2269 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2270 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2271 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2275 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2276 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2277 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2278 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2279 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2280 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2281 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2282 | } else { |
| 2283 | DCHECK(second.IsConstant()) << second; |
| 2284 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2285 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2286 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2287 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2288 | break; |
| 2289 | } |
| 2290 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2291 | case Primitive::kPrimFloat: { |
| 2292 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2293 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2294 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2295 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | case Primitive::kPrimDouble: { |
| 2299 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2300 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2301 | } |
| 2302 | break; |
| 2303 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2304 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2305 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2306 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2307 | } |
| 2308 | } |
| 2309 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2310 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2311 | LocationSummary* locations = |
| 2312 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2313 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2314 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2315 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2316 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2317 | locations->SetInAt(1, Location::Any()); |
| 2318 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2319 | break; |
| 2320 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2321 | case Primitive::kPrimFloat: |
| 2322 | case Primitive::kPrimDouble: { |
| 2323 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2324 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2325 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2326 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2327 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2328 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2329 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2330 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2331 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2335 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2336 | Location first = locations->InAt(0); |
| 2337 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2338 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2339 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2340 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2341 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2342 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2343 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2344 | __ subl(first.AsRegister<Register>(), |
| 2345 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2346 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2347 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2348 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2349 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2353 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2354 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2355 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2356 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2357 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2358 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2359 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2360 | } else { |
| 2361 | DCHECK(second.IsConstant()) << second; |
| 2362 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2363 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2364 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2365 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2366 | break; |
| 2367 | } |
| 2368 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2369 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2370 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2371 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2375 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2376 | break; |
| 2377 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2378 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2379 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2380 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2381 | } |
| 2382 | } |
| 2383 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2384 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2385 | LocationSummary* locations = |
| 2386 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2387 | switch (mul->GetResultType()) { |
| 2388 | case Primitive::kPrimInt: |
| 2389 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2390 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2391 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2392 | // Can use 3 operand multiply. |
| 2393 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2394 | } else { |
| 2395 | locations->SetOut(Location::SameAsFirstInput()); |
| 2396 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2397 | break; |
| 2398 | case Primitive::kPrimLong: { |
| 2399 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2400 | locations->SetInAt(1, Location::Any()); |
| 2401 | locations->SetOut(Location::SameAsFirstInput()); |
| 2402 | // Needed for imul on 32bits with 64bits output. |
| 2403 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2404 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2405 | break; |
| 2406 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2407 | case Primitive::kPrimFloat: |
| 2408 | case Primitive::kPrimDouble: { |
| 2409 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2410 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2411 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2412 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2413 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2414 | |
| 2415 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2416 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2421 | LocationSummary* locations = mul->GetLocations(); |
| 2422 | Location first = locations->InAt(0); |
| 2423 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2424 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2425 | |
| 2426 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2427 | case Primitive::kPrimInt: |
| 2428 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2429 | // problems where the output may not be the same as the first operand. |
| 2430 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2431 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2432 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2433 | } else if (second.IsRegister()) { |
| 2434 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2435 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2436 | } else { |
| 2437 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2438 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2439 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2440 | } |
| 2441 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2442 | |
| 2443 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2444 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2445 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2446 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2447 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2448 | |
| 2449 | DCHECK_EQ(EAX, eax); |
| 2450 | DCHECK_EQ(EDX, edx); |
| 2451 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2452 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2453 | // output: in1 |
| 2454 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2455 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2456 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2457 | if (second.IsConstant()) { |
| 2458 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2459 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2460 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2461 | int32_t low_value = Low32Bits(value); |
| 2462 | int32_t high_value = High32Bits(value); |
| 2463 | Immediate low(low_value); |
| 2464 | Immediate high(high_value); |
| 2465 | |
| 2466 | __ movl(eax, high); |
| 2467 | // eax <- in1.lo * in2.hi |
| 2468 | __ imull(eax, in1_lo); |
| 2469 | // in1.hi <- in1.hi * in2.lo |
| 2470 | __ imull(in1_hi, low); |
| 2471 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2472 | __ addl(in1_hi, eax); |
| 2473 | // move in2_lo to eax to prepare for double precision |
| 2474 | __ movl(eax, low); |
| 2475 | // edx:eax <- in1.lo * in2.lo |
| 2476 | __ mull(in1_lo); |
| 2477 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2478 | __ addl(in1_hi, edx); |
| 2479 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2480 | __ movl(in1_lo, eax); |
| 2481 | } else if (second.IsRegisterPair()) { |
| 2482 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2483 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2484 | |
| 2485 | __ movl(eax, in2_hi); |
| 2486 | // eax <- in1.lo * in2.hi |
| 2487 | __ imull(eax, in1_lo); |
| 2488 | // in1.hi <- in1.hi * in2.lo |
| 2489 | __ imull(in1_hi, in2_lo); |
| 2490 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2491 | __ addl(in1_hi, eax); |
| 2492 | // move in1_lo to eax to prepare for double precision |
| 2493 | __ movl(eax, in1_lo); |
| 2494 | // edx:eax <- in1.lo * in2.lo |
| 2495 | __ mull(in2_lo); |
| 2496 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2497 | __ addl(in1_hi, edx); |
| 2498 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2499 | __ movl(in1_lo, eax); |
| 2500 | } else { |
| 2501 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2502 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2503 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2504 | |
| 2505 | __ movl(eax, in2_hi); |
| 2506 | // eax <- in1.lo * in2.hi |
| 2507 | __ imull(eax, in1_lo); |
| 2508 | // in1.hi <- in1.hi * in2.lo |
| 2509 | __ imull(in1_hi, in2_lo); |
| 2510 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2511 | __ addl(in1_hi, eax); |
| 2512 | // move in1_lo to eax to prepare for double precision |
| 2513 | __ movl(eax, in1_lo); |
| 2514 | // edx:eax <- in1.lo * in2.lo |
| 2515 | __ mull(in2_lo); |
| 2516 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2517 | __ addl(in1_hi, edx); |
| 2518 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2519 | __ movl(in1_lo, eax); |
| 2520 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2521 | |
| 2522 | break; |
| 2523 | } |
| 2524 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2525 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2526 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2527 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2531 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2532 | break; |
| 2533 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2534 | |
| 2535 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2536 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2537 | } |
| 2538 | } |
| 2539 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2540 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 2541 | uint32_t temp_offset, |
| 2542 | uint32_t stack_adjustment, |
| 2543 | bool is_fp, |
| 2544 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2545 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2546 | DCHECK(!is_wide); |
| 2547 | if (is_fp) { |
| 2548 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2549 | } else { |
| 2550 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2551 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2552 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2553 | DCHECK(is_wide); |
| 2554 | if (is_fp) { |
| 2555 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2556 | } else { |
| 2557 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2558 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2559 | } else { |
| 2560 | // 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] | 2561 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2562 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2563 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2564 | if (is_fp) { |
| 2565 | __ flds(Address(ESP, temp_offset)); |
| 2566 | } else { |
| 2567 | __ filds(Address(ESP, temp_offset)); |
| 2568 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2569 | } else { |
| 2570 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2571 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2572 | if (is_fp) { |
| 2573 | __ fldl(Address(ESP, temp_offset)); |
| 2574 | } else { |
| 2575 | __ fildl(Address(ESP, temp_offset)); |
| 2576 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2577 | } |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2582 | Primitive::Type type = rem->GetResultType(); |
| 2583 | bool is_float = type == Primitive::kPrimFloat; |
| 2584 | size_t elem_size = Primitive::ComponentSize(type); |
| 2585 | LocationSummary* locations = rem->GetLocations(); |
| 2586 | Location first = locations->InAt(0); |
| 2587 | Location second = locations->InAt(1); |
| 2588 | Location out = locations->Out(); |
| 2589 | |
| 2590 | // Create stack space for 2 elements. |
| 2591 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2592 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2593 | |
| 2594 | // 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] | 2595 | const bool is_wide = !is_float; |
| 2596 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 2597 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2598 | |
| 2599 | // Loop doing FPREM until we stabilize. |
| 2600 | Label retry; |
| 2601 | __ Bind(&retry); |
| 2602 | __ fprem(); |
| 2603 | |
| 2604 | // Move FP status to AX. |
| 2605 | __ fstsw(); |
| 2606 | |
| 2607 | // And see if the argument reduction is complete. This is signaled by the |
| 2608 | // C2 FPU flag bit set to 0. |
| 2609 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2610 | __ j(kNotEqual, &retry); |
| 2611 | |
| 2612 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2613 | // Store FP top of stack to real stack. |
| 2614 | if (is_float) { |
| 2615 | __ fsts(Address(ESP, 0)); |
| 2616 | } else { |
| 2617 | __ fstl(Address(ESP, 0)); |
| 2618 | } |
| 2619 | |
| 2620 | // Pop the 2 items from the FP stack. |
| 2621 | __ fucompp(); |
| 2622 | |
| 2623 | // Load the value from the stack into an XMM register. |
| 2624 | DCHECK(out.IsFpuRegister()) << out; |
| 2625 | if (is_float) { |
| 2626 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2627 | } else { |
| 2628 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2629 | } |
| 2630 | |
| 2631 | // And remove the temporary stack space we allocated. |
| 2632 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2633 | } |
| 2634 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2635 | |
| 2636 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2637 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2638 | |
| 2639 | LocationSummary* locations = instruction->GetLocations(); |
| 2640 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2641 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2642 | |
| 2643 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2644 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2645 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2646 | |
| 2647 | DCHECK(imm == 1 || imm == -1); |
| 2648 | |
| 2649 | if (instruction->IsRem()) { |
| 2650 | __ xorl(out_register, out_register); |
| 2651 | } else { |
| 2652 | __ movl(out_register, input_register); |
| 2653 | if (imm == -1) { |
| 2654 | __ negl(out_register); |
| 2655 | } |
| 2656 | } |
| 2657 | } |
| 2658 | |
| 2659 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2660 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2661 | LocationSummary* locations = instruction->GetLocations(); |
| 2662 | |
| 2663 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2664 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2665 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2666 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2667 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2668 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2669 | |
| 2670 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2671 | __ testl(input_register, input_register); |
| 2672 | __ cmovl(kGreaterEqual, num, input_register); |
| 2673 | int shift = CTZ(imm); |
| 2674 | __ sarl(num, Immediate(shift)); |
| 2675 | |
| 2676 | if (imm < 0) { |
| 2677 | __ negl(num); |
| 2678 | } |
| 2679 | |
| 2680 | __ movl(out_register, num); |
| 2681 | } |
| 2682 | |
| 2683 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2684 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2685 | |
| 2686 | LocationSummary* locations = instruction->GetLocations(); |
| 2687 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2688 | |
| 2689 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2690 | Register out = locations->Out().AsRegister<Register>(); |
| 2691 | Register num; |
| 2692 | Register edx; |
| 2693 | |
| 2694 | if (instruction->IsDiv()) { |
| 2695 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2696 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2697 | } else { |
| 2698 | edx = locations->Out().AsRegister<Register>(); |
| 2699 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2700 | } |
| 2701 | |
| 2702 | DCHECK_EQ(EAX, eax); |
| 2703 | DCHECK_EQ(EDX, edx); |
| 2704 | if (instruction->IsDiv()) { |
| 2705 | DCHECK_EQ(EAX, out); |
| 2706 | } else { |
| 2707 | DCHECK_EQ(EDX, out); |
| 2708 | } |
| 2709 | |
| 2710 | int64_t magic; |
| 2711 | int shift; |
| 2712 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2713 | |
| 2714 | Label ndiv; |
| 2715 | Label end; |
| 2716 | // If numerator is 0, the result is 0, no computation needed. |
| 2717 | __ testl(eax, eax); |
| 2718 | __ j(kNotEqual, &ndiv); |
| 2719 | |
| 2720 | __ xorl(out, out); |
| 2721 | __ jmp(&end); |
| 2722 | |
| 2723 | __ Bind(&ndiv); |
| 2724 | |
| 2725 | // Save the numerator. |
| 2726 | __ movl(num, eax); |
| 2727 | |
| 2728 | // EAX = magic |
| 2729 | __ movl(eax, Immediate(magic)); |
| 2730 | |
| 2731 | // EDX:EAX = magic * numerator |
| 2732 | __ imull(num); |
| 2733 | |
| 2734 | if (imm > 0 && magic < 0) { |
| 2735 | // EDX += num |
| 2736 | __ addl(edx, num); |
| 2737 | } else if (imm < 0 && magic > 0) { |
| 2738 | __ subl(edx, num); |
| 2739 | } |
| 2740 | |
| 2741 | // Shift if needed. |
| 2742 | if (shift != 0) { |
| 2743 | __ sarl(edx, Immediate(shift)); |
| 2744 | } |
| 2745 | |
| 2746 | // EDX += 1 if EDX < 0 |
| 2747 | __ movl(eax, edx); |
| 2748 | __ shrl(edx, Immediate(31)); |
| 2749 | __ addl(edx, eax); |
| 2750 | |
| 2751 | if (instruction->IsRem()) { |
| 2752 | __ movl(eax, num); |
| 2753 | __ imull(edx, Immediate(imm)); |
| 2754 | __ subl(eax, edx); |
| 2755 | __ movl(edx, eax); |
| 2756 | } else { |
| 2757 | __ movl(eax, edx); |
| 2758 | } |
| 2759 | __ Bind(&end); |
| 2760 | } |
| 2761 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2762 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2763 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2764 | |
| 2765 | LocationSummary* locations = instruction->GetLocations(); |
| 2766 | Location out = locations->Out(); |
| 2767 | Location first = locations->InAt(0); |
| 2768 | Location second = locations->InAt(1); |
| 2769 | bool is_div = instruction->IsDiv(); |
| 2770 | |
| 2771 | switch (instruction->GetResultType()) { |
| 2772 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2773 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2774 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2775 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2776 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2777 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2778 | |
| 2779 | if (imm == 0) { |
| 2780 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2781 | } else if (imm == 1 || imm == -1) { |
| 2782 | DivRemOneOrMinusOne(instruction); |
| 2783 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2784 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2785 | } else { |
| 2786 | DCHECK(imm <= -2 || imm >= 2); |
| 2787 | GenerateDivRemWithAnyConstant(instruction); |
| 2788 | } |
| 2789 | } else { |
| 2790 | SlowPathCodeX86* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2791 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2792 | is_div); |
| 2793 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2794 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2795 | Register second_reg = second.AsRegister<Register>(); |
| 2796 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2797 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2798 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2799 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2800 | __ cmpl(second_reg, Immediate(-1)); |
| 2801 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2802 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2803 | // edx:eax <- sign-extended of eax |
| 2804 | __ cdq(); |
| 2805 | // eax = quotient, edx = remainder |
| 2806 | __ idivl(second_reg); |
| 2807 | __ Bind(slow_path->GetExitLabel()); |
| 2808 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2809 | break; |
| 2810 | } |
| 2811 | |
| 2812 | case Primitive::kPrimLong: { |
| 2813 | InvokeRuntimeCallingConvention calling_convention; |
| 2814 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2815 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2816 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2817 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2818 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2819 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2820 | |
| 2821 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2822 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2823 | instruction, |
| 2824 | instruction->GetDexPc(), |
| 2825 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2826 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2827 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 2828 | instruction, |
| 2829 | instruction->GetDexPc(), |
| 2830 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2831 | } |
| 2832 | uint32_t dex_pc = is_div |
| 2833 | ? instruction->AsDiv()->GetDexPc() |
| 2834 | : instruction->AsRem()->GetDexPc(); |
| 2835 | codegen_->RecordPcInfo(instruction, dex_pc); |
| 2836 | |
| 2837 | break; |
| 2838 | } |
| 2839 | |
| 2840 | default: |
| 2841 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 2842 | } |
| 2843 | } |
| 2844 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2845 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2846 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2847 | ? LocationSummary::kCall |
| 2848 | : LocationSummary::kNoCall; |
| 2849 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2850 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2851 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2852 | case Primitive::kPrimInt: { |
| 2853 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2854 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2855 | locations->SetOut(Location::SameAsFirstInput()); |
| 2856 | // Intel uses edx:eax as the dividend. |
| 2857 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2858 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2859 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 2860 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2861 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2862 | locations->AddTemp(Location::RequiresRegister()); |
| 2863 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2864 | break; |
| 2865 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2866 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2867 | InvokeRuntimeCallingConvention calling_convention; |
| 2868 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2869 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2870 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2871 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2872 | // Runtime helper puts the result in EAX, EDX. |
| 2873 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2874 | break; |
| 2875 | } |
| 2876 | case Primitive::kPrimFloat: |
| 2877 | case Primitive::kPrimDouble: { |
| 2878 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2879 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2880 | locations->SetOut(Location::SameAsFirstInput()); |
| 2881 | break; |
| 2882 | } |
| 2883 | |
| 2884 | default: |
| 2885 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2886 | } |
| 2887 | } |
| 2888 | |
| 2889 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 2890 | LocationSummary* locations = div->GetLocations(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2891 | Location out = locations->Out(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2892 | Location first = locations->InAt(0); |
| 2893 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2894 | |
| 2895 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2896 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2897 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2898 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2899 | break; |
| 2900 | } |
| 2901 | |
| 2902 | case Primitive::kPrimFloat: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2903 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2904 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2905 | break; |
| 2906 | } |
| 2907 | |
| 2908 | case Primitive::kPrimDouble: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2909 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2910 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2911 | break; |
| 2912 | } |
| 2913 | |
| 2914 | default: |
| 2915 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2916 | } |
| 2917 | } |
| 2918 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2919 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2920 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2921 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2922 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 2923 | ? LocationSummary::kCall |
| 2924 | : LocationSummary::kNoCall; |
| 2925 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2926 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2927 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2928 | case Primitive::kPrimInt: { |
| 2929 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2930 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2931 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2932 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2933 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 2934 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2935 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2936 | locations->AddTemp(Location::RequiresRegister()); |
| 2937 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2938 | break; |
| 2939 | } |
| 2940 | case Primitive::kPrimLong: { |
| 2941 | InvokeRuntimeCallingConvention calling_convention; |
| 2942 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2943 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2944 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2945 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2946 | // Runtime helper puts the result in EAX, EDX. |
| 2947 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2948 | break; |
| 2949 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2950 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2951 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2952 | locations->SetInAt(0, Location::Any()); |
| 2953 | locations->SetInAt(1, Location::Any()); |
| 2954 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2955 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2956 | break; |
| 2957 | } |
| 2958 | |
| 2959 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2960 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 2965 | Primitive::Type type = rem->GetResultType(); |
| 2966 | switch (type) { |
| 2967 | case Primitive::kPrimInt: |
| 2968 | case Primitive::kPrimLong: { |
| 2969 | GenerateDivRemIntegral(rem); |
| 2970 | break; |
| 2971 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2972 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2973 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2974 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2975 | break; |
| 2976 | } |
| 2977 | default: |
| 2978 | LOG(FATAL) << "Unexpected rem type " << type; |
| 2979 | } |
| 2980 | } |
| 2981 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2982 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2983 | LocationSummary* locations = |
| 2984 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2985 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 2986 | case Primitive::kPrimByte: |
| 2987 | case Primitive::kPrimChar: |
| 2988 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2989 | case Primitive::kPrimInt: { |
| 2990 | locations->SetInAt(0, Location::Any()); |
| 2991 | break; |
| 2992 | } |
| 2993 | case Primitive::kPrimLong: { |
| 2994 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2995 | if (!instruction->IsConstant()) { |
| 2996 | locations->AddTemp(Location::RequiresRegister()); |
| 2997 | } |
| 2998 | break; |
| 2999 | } |
| 3000 | default: |
| 3001 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3002 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3003 | if (instruction->HasUses()) { |
| 3004 | locations->SetOut(Location::SameAsFirstInput()); |
| 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3009 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 3010 | codegen_->AddSlowPath(slow_path); |
| 3011 | |
| 3012 | LocationSummary* locations = instruction->GetLocations(); |
| 3013 | Location value = locations->InAt(0); |
| 3014 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3015 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3016 | case Primitive::kPrimByte: |
| 3017 | case Primitive::kPrimChar: |
| 3018 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3019 | case Primitive::kPrimInt: { |
| 3020 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3021 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3022 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3023 | } else if (value.IsStackSlot()) { |
| 3024 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3025 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3026 | } else { |
| 3027 | DCHECK(value.IsConstant()) << value; |
| 3028 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3029 | __ jmp(slow_path->GetEntryLabel()); |
| 3030 | } |
| 3031 | } |
| 3032 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3033 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3034 | case Primitive::kPrimLong: { |
| 3035 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3036 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3037 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3038 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3039 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3040 | } else { |
| 3041 | DCHECK(value.IsConstant()) << value; |
| 3042 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3043 | __ jmp(slow_path->GetEntryLabel()); |
| 3044 | } |
| 3045 | } |
| 3046 | break; |
| 3047 | } |
| 3048 | default: |
| 3049 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3050 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3051 | } |
| 3052 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3053 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3054 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3055 | |
| 3056 | LocationSummary* locations = |
| 3057 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3058 | |
| 3059 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3060 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3061 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3062 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3063 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3064 | // The shift count needs to be in CL or a constant. |
| 3065 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3066 | locations->SetOut(Location::SameAsFirstInput()); |
| 3067 | break; |
| 3068 | } |
| 3069 | default: |
| 3070 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3071 | } |
| 3072 | } |
| 3073 | |
| 3074 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3075 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3076 | |
| 3077 | LocationSummary* locations = op->GetLocations(); |
| 3078 | Location first = locations->InAt(0); |
| 3079 | Location second = locations->InAt(1); |
| 3080 | DCHECK(first.Equals(locations->Out())); |
| 3081 | |
| 3082 | switch (op->GetResultType()) { |
| 3083 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3084 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3085 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3086 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3087 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3088 | DCHECK_EQ(ECX, second_reg); |
| 3089 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3090 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3091 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3092 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3093 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3094 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3095 | } |
| 3096 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3097 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3098 | if (shift == 0) { |
| 3099 | return; |
| 3100 | } |
| 3101 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3102 | if (op->IsShl()) { |
| 3103 | __ shll(first_reg, imm); |
| 3104 | } else if (op->IsShr()) { |
| 3105 | __ sarl(first_reg, imm); |
| 3106 | } else { |
| 3107 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3108 | } |
| 3109 | } |
| 3110 | break; |
| 3111 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3112 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3113 | if (second.IsRegister()) { |
| 3114 | Register second_reg = second.AsRegister<Register>(); |
| 3115 | DCHECK_EQ(ECX, second_reg); |
| 3116 | if (op->IsShl()) { |
| 3117 | GenerateShlLong(first, second_reg); |
| 3118 | } else if (op->IsShr()) { |
| 3119 | GenerateShrLong(first, second_reg); |
| 3120 | } else { |
| 3121 | GenerateUShrLong(first, second_reg); |
| 3122 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3123 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3124 | // Shift by a constant. |
| 3125 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3126 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3127 | if (shift != 0) { |
| 3128 | if (op->IsShl()) { |
| 3129 | GenerateShlLong(first, shift); |
| 3130 | } else if (op->IsShr()) { |
| 3131 | GenerateShrLong(first, shift); |
| 3132 | } else { |
| 3133 | GenerateUShrLong(first, shift); |
| 3134 | } |
| 3135 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3136 | } |
| 3137 | break; |
| 3138 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3139 | default: |
| 3140 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3141 | } |
| 3142 | } |
| 3143 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3144 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3145 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3146 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3147 | if (shift == 1) { |
| 3148 | // This is just an addition. |
| 3149 | __ addl(low, low); |
| 3150 | __ adcl(high, high); |
| 3151 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3152 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3153 | codegen_->EmitParallelMoves( |
| 3154 | loc.ToLow(), |
| 3155 | loc.ToHigh(), |
| 3156 | Primitive::kPrimInt, |
| 3157 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3158 | loc.ToLow(), |
| 3159 | Primitive::kPrimInt); |
| 3160 | } else if (shift > 32) { |
| 3161 | // Low part becomes 0. High part is low part << (shift-32). |
| 3162 | __ movl(high, low); |
| 3163 | __ shll(high, Immediate(shift - 32)); |
| 3164 | __ xorl(low, low); |
| 3165 | } else { |
| 3166 | // Between 1 and 31. |
| 3167 | __ shld(high, low, Immediate(shift)); |
| 3168 | __ shll(low, Immediate(shift)); |
| 3169 | } |
| 3170 | } |
| 3171 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3172 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| 3173 | Label done; |
| 3174 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3175 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3176 | __ testl(shifter, Immediate(32)); |
| 3177 | __ j(kEqual, &done); |
| 3178 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3179 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3180 | __ Bind(&done); |
| 3181 | } |
| 3182 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3183 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3184 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3185 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3186 | if (shift == 32) { |
| 3187 | // Need to copy the sign. |
| 3188 | DCHECK_NE(low, high); |
| 3189 | __ movl(low, high); |
| 3190 | __ sarl(high, Immediate(31)); |
| 3191 | } else if (shift > 32) { |
| 3192 | DCHECK_NE(low, high); |
| 3193 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3194 | __ movl(low, high); |
| 3195 | __ sarl(high, Immediate(31)); |
| 3196 | __ sarl(low, Immediate(shift - 32)); |
| 3197 | } else { |
| 3198 | // Between 1 and 31. |
| 3199 | __ shrd(low, high, Immediate(shift)); |
| 3200 | __ sarl(high, Immediate(shift)); |
| 3201 | } |
| 3202 | } |
| 3203 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3204 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| 3205 | Label done; |
| 3206 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3207 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3208 | __ testl(shifter, Immediate(32)); |
| 3209 | __ j(kEqual, &done); |
| 3210 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3211 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3212 | __ Bind(&done); |
| 3213 | } |
| 3214 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3215 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3216 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3217 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3218 | if (shift == 32) { |
| 3219 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3220 | codegen_->EmitParallelMoves( |
| 3221 | loc.ToHigh(), |
| 3222 | loc.ToLow(), |
| 3223 | Primitive::kPrimInt, |
| 3224 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3225 | loc.ToHigh(), |
| 3226 | Primitive::kPrimInt); |
| 3227 | } else if (shift > 32) { |
| 3228 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3229 | __ movl(low, high); |
| 3230 | __ shrl(low, Immediate(shift - 32)); |
| 3231 | __ xorl(high, high); |
| 3232 | } else { |
| 3233 | // Between 1 and 31. |
| 3234 | __ shrd(low, high, Immediate(shift)); |
| 3235 | __ shrl(high, Immediate(shift)); |
| 3236 | } |
| 3237 | } |
| 3238 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3239 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| 3240 | Label done; |
| 3241 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3242 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3243 | __ testl(shifter, Immediate(32)); |
| 3244 | __ j(kEqual, &done); |
| 3245 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3246 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3247 | __ Bind(&done); |
| 3248 | } |
| 3249 | |
| 3250 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3251 | HandleShift(shl); |
| 3252 | } |
| 3253 | |
| 3254 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3255 | HandleShift(shl); |
| 3256 | } |
| 3257 | |
| 3258 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3259 | HandleShift(shr); |
| 3260 | } |
| 3261 | |
| 3262 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3263 | HandleShift(shr); |
| 3264 | } |
| 3265 | |
| 3266 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3267 | HandleShift(ushr); |
| 3268 | } |
| 3269 | |
| 3270 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3271 | HandleShift(ushr); |
| 3272 | } |
| 3273 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3274 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3275 | LocationSummary* locations = |
| 3276 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3277 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3278 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3279 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3280 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 3284 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3285 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3286 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3287 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3288 | codegen_->InvokeRuntime( |
| 3289 | Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint())), |
| 3290 | instruction, |
| 3291 | instruction->GetDexPc(), |
| 3292 | nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3293 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3294 | } |
| 3295 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3296 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3297 | LocationSummary* locations = |
| 3298 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3299 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3300 | InvokeRuntimeCallingConvention calling_convention; |
| 3301 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3302 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3303 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3307 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3308 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 3309 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3310 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3311 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3312 | codegen_->InvokeRuntime( |
| 3313 | Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint())), |
| 3314 | instruction, |
| 3315 | instruction->GetDexPc(), |
| 3316 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3317 | DCHECK(!codegen_->IsLeafMethod()); |
| 3318 | } |
| 3319 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3320 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3321 | LocationSummary* locations = |
| 3322 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3323 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3324 | if (location.IsStackSlot()) { |
| 3325 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3326 | } else if (location.IsDoubleStackSlot()) { |
| 3327 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3328 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3329 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3330 | } |
| 3331 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3332 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3333 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3334 | } |
| 3335 | |
| 3336 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3337 | LocationSummary* locations = |
| 3338 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3339 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3340 | } |
| 3341 | |
| 3342 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3343 | } |
| 3344 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3345 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3346 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3347 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3348 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3349 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3350 | } |
| 3351 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3352 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3353 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3354 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3355 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3356 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3357 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3358 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3359 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3360 | break; |
| 3361 | |
| 3362 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3363 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3364 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3365 | break; |
| 3366 | |
| 3367 | default: |
| 3368 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3369 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3370 | } |
| 3371 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3372 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3373 | LocationSummary* locations = |
| 3374 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3375 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3376 | locations->SetOut(Location::SameAsFirstInput()); |
| 3377 | } |
| 3378 | |
| 3379 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3380 | LocationSummary* locations = bool_not->GetLocations(); |
| 3381 | Location in = locations->InAt(0); |
| 3382 | Location out = locations->Out(); |
| 3383 | DCHECK(in.Equals(out)); |
| 3384 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3385 | } |
| 3386 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3387 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3388 | LocationSummary* locations = |
| 3389 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3390 | switch (compare->InputAt(0)->GetType()) { |
| 3391 | case Primitive::kPrimLong: { |
| 3392 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3393 | locations->SetInAt(1, Location::Any()); |
| 3394 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3395 | break; |
| 3396 | } |
| 3397 | case Primitive::kPrimFloat: |
| 3398 | case Primitive::kPrimDouble: { |
| 3399 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3400 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3401 | locations->SetOut(Location::RequiresRegister()); |
| 3402 | break; |
| 3403 | } |
| 3404 | default: |
| 3405 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3406 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3410 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3411 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3412 | Location left = locations->InAt(0); |
| 3413 | Location right = locations->InAt(1); |
| 3414 | |
| 3415 | Label less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3416 | switch (compare->InputAt(0)->GetType()) { |
| 3417 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3418 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 3419 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 3420 | int32_t val_low = 0; |
| 3421 | int32_t val_high = 0; |
| 3422 | bool right_is_const = false; |
| 3423 | |
| 3424 | if (right.IsConstant()) { |
| 3425 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 3426 | right_is_const = true; |
| 3427 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 3428 | val_low = Low32Bits(val); |
| 3429 | val_high = High32Bits(val); |
| 3430 | } |
| 3431 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3432 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3433 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3434 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3435 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3436 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3437 | DCHECK(right_is_const) << right; |
| 3438 | if (val_high == 0) { |
| 3439 | __ testl(left_high, left_high); |
| 3440 | } else { |
| 3441 | __ cmpl(left_high, Immediate(val_high)); |
| 3442 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3443 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3444 | __ j(kLess, &less); // Signed compare. |
| 3445 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3446 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3447 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3448 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3449 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3450 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3451 | DCHECK(right_is_const) << right; |
| 3452 | if (val_low == 0) { |
| 3453 | __ testl(left_low, left_low); |
| 3454 | } else { |
| 3455 | __ cmpl(left_low, Immediate(val_low)); |
| 3456 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3457 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3458 | break; |
| 3459 | } |
| 3460 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3461 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3462 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3463 | break; |
| 3464 | } |
| 3465 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3466 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3467 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3468 | break; |
| 3469 | } |
| 3470 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3471 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3472 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3473 | __ movl(out, Immediate(0)); |
| 3474 | __ j(kEqual, &done); |
| 3475 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3476 | |
| 3477 | __ Bind(&greater); |
| 3478 | __ movl(out, Immediate(1)); |
| 3479 | __ jmp(&done); |
| 3480 | |
| 3481 | __ Bind(&less); |
| 3482 | __ movl(out, Immediate(-1)); |
| 3483 | |
| 3484 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3485 | } |
| 3486 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3487 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3488 | LocationSummary* locations = |
| 3489 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3490 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3491 | locations->SetInAt(i, Location::Any()); |
| 3492 | } |
| 3493 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3497 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3498 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3499 | } |
| 3500 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3501 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3502 | /* |
| 3503 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3504 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3505 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3506 | */ |
| 3507 | switch (kind) { |
| 3508 | case MemBarrierKind::kAnyAny: { |
| 3509 | __ mfence(); |
| 3510 | break; |
| 3511 | } |
| 3512 | case MemBarrierKind::kAnyStore: |
| 3513 | case MemBarrierKind::kLoadAny: |
| 3514 | case MemBarrierKind::kStoreStore: { |
| 3515 | // nop |
| 3516 | break; |
| 3517 | } |
| 3518 | default: |
| 3519 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3520 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3521 | } |
| 3522 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3523 | |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame^] | 3524 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 3525 | Location temp) { |
| 3526 | // TODO: Implement all kinds of calls: |
| 3527 | // 1) boot -> boot |
| 3528 | // 2) app -> boot |
| 3529 | // 3) app -> app |
| 3530 | // |
| 3531 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3532 | |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame^] | 3533 | if (invoke->IsStringInit()) { |
| 3534 | // temp = thread->string_init_entrypoint |
| 3535 | Register reg = temp.AsRegister<Register>(); |
| 3536 | __ fs()->movl(reg, Address::Absolute(invoke->GetStringInitOffset())); |
| 3537 | // (temp + offset_of_quick_compiled_code)() |
| 3538 | __ call(Address( |
| 3539 | reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 3540 | } else if (invoke->IsRecursive()) { |
| 3541 | __ call(GetFrameEntryLabel()); |
| 3542 | } else { |
| 3543 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3544 | |
| 3545 | Register method_reg; |
| 3546 | Register reg = temp.AsRegister<Register>(); |
| 3547 | if (current_method.IsRegister()) { |
| 3548 | method_reg = current_method.AsRegister<Register>(); |
| 3549 | } else { |
| 3550 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 3551 | DCHECK(!current_method.IsValid()); |
| 3552 | method_reg = reg; |
| 3553 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3554 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame^] | 3555 | // temp = temp->dex_cache_resolved_methods_; |
| 3556 | __ movl(reg, Address(method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 3557 | // temp = temp[index_in_cache] |
| 3558 | __ movl(reg, Address(reg, |
| 3559 | CodeGenerator::GetCachePointerOffset(invoke->GetDexMethodIndex()))); |
| 3560 | // (temp + offset_of_quick_compiled_code)() |
| 3561 | __ call(Address(reg, |
| 3562 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3566 | } |
| 3567 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3568 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 3569 | Register card, |
| 3570 | Register object, |
| 3571 | Register value, |
| 3572 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3573 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3574 | if (value_can_be_null) { |
| 3575 | __ testl(value, value); |
| 3576 | __ j(kEqual, &is_null); |
| 3577 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3578 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3579 | __ movl(temp, object); |
| 3580 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3581 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3582 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3583 | if (value_can_be_null) { |
| 3584 | __ Bind(&is_null); |
| 3585 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3586 | } |
| 3587 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3588 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3589 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3590 | LocationSummary* locations = |
| 3591 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3592 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3593 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3594 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3595 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3596 | } else { |
| 3597 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3598 | // the object's location. |
| 3599 | locations->SetOut(Location::RequiresRegister(), |
| 3600 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3601 | : Location::kNoOutputOverlap); |
| 3602 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3603 | |
| 3604 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3605 | // Long values can be loaded atomically into an XMM using movsd. |
| 3606 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3607 | // and then copy the XMM into the output 32bits at a time). |
| 3608 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3609 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3610 | } |
| 3611 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3612 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3613 | const FieldInfo& field_info) { |
| 3614 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3615 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3616 | LocationSummary* locations = instruction->GetLocations(); |
| 3617 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3618 | Location out = locations->Out(); |
| 3619 | bool is_volatile = field_info.IsVolatile(); |
| 3620 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3621 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3622 | |
| 3623 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3624 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3625 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3626 | break; |
| 3627 | } |
| 3628 | |
| 3629 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3630 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3631 | break; |
| 3632 | } |
| 3633 | |
| 3634 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3635 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3636 | break; |
| 3637 | } |
| 3638 | |
| 3639 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3640 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3641 | break; |
| 3642 | } |
| 3643 | |
| 3644 | case Primitive::kPrimInt: |
| 3645 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3646 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3651 | if (is_volatile) { |
| 3652 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3653 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3654 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3655 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3656 | __ psrlq(temp, Immediate(32)); |
| 3657 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3658 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3659 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3660 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3661 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3662 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3663 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3664 | break; |
| 3665 | } |
| 3666 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3667 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3668 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3669 | break; |
| 3670 | } |
| 3671 | |
| 3672 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3673 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3674 | break; |
| 3675 | } |
| 3676 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3677 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3678 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3679 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3680 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3681 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3682 | // Longs are handled in the switch. |
| 3683 | if (field_type != Primitive::kPrimLong) { |
| 3684 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3685 | } |
| 3686 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3687 | if (is_volatile) { |
| 3688 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3689 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3690 | |
| 3691 | if (field_type == Primitive::kPrimNot) { |
| 3692 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3693 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3697 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3698 | |
| 3699 | LocationSummary* locations = |
| 3700 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3701 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3702 | bool is_volatile = field_info.IsVolatile(); |
| 3703 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3704 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3705 | || (field_type == Primitive::kPrimByte); |
| 3706 | |
| 3707 | // The register allocator does not support multiple |
| 3708 | // inputs that die at entry with one in a specific register. |
| 3709 | if (is_byte_type) { |
| 3710 | // Ensure the value is in a byte register. |
| 3711 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3712 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3713 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3714 | } else { |
| 3715 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3716 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3717 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3718 | // Temporary registers for the write barrier. |
| 3719 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3720 | // Ensure the card is in a byte register. |
| 3721 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3722 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3723 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3724 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3725 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3726 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3727 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3728 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3729 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3730 | } |
| 3731 | } |
| 3732 | |
| 3733 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3734 | const FieldInfo& field_info, |
| 3735 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3736 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3737 | |
| 3738 | LocationSummary* locations = instruction->GetLocations(); |
| 3739 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3740 | Location value = locations->InAt(1); |
| 3741 | bool is_volatile = field_info.IsVolatile(); |
| 3742 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3743 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3744 | bool needs_write_barrier = |
| 3745 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3746 | |
| 3747 | if (is_volatile) { |
| 3748 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3749 | } |
| 3750 | |
| 3751 | switch (field_type) { |
| 3752 | case Primitive::kPrimBoolean: |
| 3753 | case Primitive::kPrimByte: { |
| 3754 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 3755 | break; |
| 3756 | } |
| 3757 | |
| 3758 | case Primitive::kPrimShort: |
| 3759 | case Primitive::kPrimChar: { |
| 3760 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 3761 | break; |
| 3762 | } |
| 3763 | |
| 3764 | case Primitive::kPrimInt: |
| 3765 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3766 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3767 | // Note that in the case where `value` is a null reference, |
| 3768 | // we do not enter this block, as the reference does not |
| 3769 | // need poisoning. |
| 3770 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3771 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3772 | __ movl(temp, value.AsRegister<Register>()); |
| 3773 | __ PoisonHeapReference(temp); |
| 3774 | __ movl(Address(base, offset), temp); |
| 3775 | } else { |
| 3776 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 3777 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3778 | break; |
| 3779 | } |
| 3780 | |
| 3781 | case Primitive::kPrimLong: { |
| 3782 | if (is_volatile) { |
| 3783 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3784 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 3785 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 3786 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 3787 | __ punpckldq(temp1, temp2); |
| 3788 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3789 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3790 | } else { |
| 3791 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3792 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3793 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 3794 | } |
| 3795 | break; |
| 3796 | } |
| 3797 | |
| 3798 | case Primitive::kPrimFloat: { |
| 3799 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3800 | break; |
| 3801 | } |
| 3802 | |
| 3803 | case Primitive::kPrimDouble: { |
| 3804 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3805 | break; |
| 3806 | } |
| 3807 | |
| 3808 | case Primitive::kPrimVoid: |
| 3809 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3810 | UNREACHABLE(); |
| 3811 | } |
| 3812 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3813 | // Longs are handled in the switch. |
| 3814 | if (field_type != Primitive::kPrimLong) { |
| 3815 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3816 | } |
| 3817 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3818 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3819 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3820 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3821 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3824 | if (is_volatile) { |
| 3825 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3826 | } |
| 3827 | } |
| 3828 | |
| 3829 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3830 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3831 | } |
| 3832 | |
| 3833 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3834 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3835 | } |
| 3836 | |
| 3837 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3838 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3839 | } |
| 3840 | |
| 3841 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3842 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3846 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3847 | } |
| 3848 | |
| 3849 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3850 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3854 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3855 | } |
| 3856 | |
| 3857 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3858 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3862 | LocationSummary* locations = |
| 3863 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3864 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3865 | ? Location::RequiresRegister() |
| 3866 | : Location::Any(); |
| 3867 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3868 | if (instruction->HasUses()) { |
| 3869 | locations->SetOut(Location::SameAsFirstInput()); |
| 3870 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3871 | } |
| 3872 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3873 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3874 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3875 | return; |
| 3876 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3877 | LocationSummary* locations = instruction->GetLocations(); |
| 3878 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3879 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3880 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 3881 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3882 | } |
| 3883 | |
| 3884 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3885 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3886 | codegen_->AddSlowPath(slow_path); |
| 3887 | |
| 3888 | LocationSummary* locations = instruction->GetLocations(); |
| 3889 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3890 | |
| 3891 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 3892 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3893 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3894 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3895 | } else { |
| 3896 | DCHECK(obj.IsConstant()) << obj; |
| 3897 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 3898 | __ jmp(slow_path->GetEntryLabel()); |
| 3899 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3900 | } |
| 3901 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3902 | } |
| 3903 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3904 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| 3905 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3906 | GenerateImplicitNullCheck(instruction); |
| 3907 | } else { |
| 3908 | GenerateExplicitNullCheck(instruction); |
| 3909 | } |
| 3910 | } |
| 3911 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3912 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3913 | LocationSummary* locations = |
| 3914 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3915 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3916 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3917 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3918 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3919 | } else { |
| 3920 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3921 | // the array's location. |
| 3922 | locations->SetOut(Location::RequiresRegister(), |
| 3923 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3924 | : Location::kNoOutputOverlap); |
| 3925 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 3929 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3930 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3931 | Location index = locations->InAt(1); |
| 3932 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3933 | Primitive::Type type = instruction->GetType(); |
| 3934 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3935 | case Primitive::kPrimBoolean: { |
| 3936 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3937 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3938 | if (index.IsConstant()) { |
| 3939 | __ movzxb(out, Address(obj, |
| 3940 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3941 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3942 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3943 | } |
| 3944 | break; |
| 3945 | } |
| 3946 | |
| 3947 | case Primitive::kPrimByte: { |
| 3948 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3949 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3950 | if (index.IsConstant()) { |
| 3951 | __ movsxb(out, Address(obj, |
| 3952 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3953 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3954 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3955 | } |
| 3956 | break; |
| 3957 | } |
| 3958 | |
| 3959 | case Primitive::kPrimShort: { |
| 3960 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3961 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3962 | if (index.IsConstant()) { |
| 3963 | __ movsxw(out, Address(obj, |
| 3964 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3965 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3966 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3967 | } |
| 3968 | break; |
| 3969 | } |
| 3970 | |
| 3971 | case Primitive::kPrimChar: { |
| 3972 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3973 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3974 | if (index.IsConstant()) { |
| 3975 | __ movzxw(out, Address(obj, |
| 3976 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3977 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3978 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3979 | } |
| 3980 | break; |
| 3981 | } |
| 3982 | |
| 3983 | case Primitive::kPrimInt: |
| 3984 | case Primitive::kPrimNot: { |
| 3985 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3986 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3987 | if (index.IsConstant()) { |
| 3988 | __ movl(out, Address(obj, |
| 3989 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3990 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3991 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3992 | } |
| 3993 | break; |
| 3994 | } |
| 3995 | |
| 3996 | case Primitive::kPrimLong: { |
| 3997 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3998 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3999 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4000 | if (index.IsConstant()) { |
| 4001 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4002 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4003 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4004 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4005 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4006 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4007 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4008 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4009 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4010 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4011 | } |
| 4012 | break; |
| 4013 | } |
| 4014 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4015 | case Primitive::kPrimFloat: { |
| 4016 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4017 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4018 | if (index.IsConstant()) { |
| 4019 | __ movss(out, Address(obj, |
| 4020 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4021 | } else { |
| 4022 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4023 | } |
| 4024 | break; |
| 4025 | } |
| 4026 | |
| 4027 | case Primitive::kPrimDouble: { |
| 4028 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4029 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4030 | if (index.IsConstant()) { |
| 4031 | __ movsd(out, Address(obj, |
| 4032 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4033 | } else { |
| 4034 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 4035 | } |
| 4036 | break; |
| 4037 | } |
| 4038 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4039 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4040 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4041 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4042 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4043 | |
| 4044 | if (type != Primitive::kPrimLong) { |
| 4045 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4046 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4047 | |
| 4048 | if (type == Primitive::kPrimNot) { |
| 4049 | Register out = locations->Out().AsRegister<Register>(); |
| 4050 | __ MaybeUnpoisonHeapReference(out); |
| 4051 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4055 | // This location builder might end up asking to up to four registers, which is |
| 4056 | // not currently possible for baseline. The situation in which we need four |
| 4057 | // registers cannot be met by baseline though, because it has not run any |
| 4058 | // optimization. |
| 4059 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4060 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4061 | bool needs_write_barrier = |
| 4062 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 4063 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4064 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4065 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4066 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4067 | instruction, |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4068 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4069 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4070 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4071 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4072 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4073 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4074 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4075 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4076 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4077 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4078 | // 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] | 4079 | // In case of a byte operation, the register allocator does not support multiple |
| 4080 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4081 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4082 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4083 | if (is_byte_type) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4084 | // Ensure the value is in a byte register. |
| 4085 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4086 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 4087 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4088 | } else { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4089 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4090 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4091 | if (needs_write_barrier) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4092 | // Temporary registers for the write barrier. |
| 4093 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4094 | // Ensure the card is in a byte register. |
| 4095 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4096 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4097 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4101 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4102 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4103 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4104 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4105 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4106 | bool needs_runtime_call = locations->WillCall(); |
| 4107 | bool needs_write_barrier = |
| 4108 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4109 | |
| 4110 | switch (value_type) { |
| 4111 | case Primitive::kPrimBoolean: |
| 4112 | case Primitive::kPrimByte: { |
| 4113 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4114 | if (index.IsConstant()) { |
| 4115 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4116 | if (value.IsRegister()) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4117 | __ movb(Address(obj, offset), value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4118 | } else { |
| 4119 | __ movb(Address(obj, offset), |
| 4120 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4121 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4122 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4123 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4124 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4125 | value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4126 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4127 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4128 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4129 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4130 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4131 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4132 | break; |
| 4133 | } |
| 4134 | |
| 4135 | case Primitive::kPrimShort: |
| 4136 | case Primitive::kPrimChar: { |
| 4137 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4138 | if (index.IsConstant()) { |
| 4139 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4140 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4141 | __ movw(Address(obj, offset), value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4142 | } else { |
| 4143 | __ movw(Address(obj, offset), |
| 4144 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4145 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4146 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4147 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4148 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
| 4149 | value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4150 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4151 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4152 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4153 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4154 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4155 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4156 | break; |
| 4157 | } |
| 4158 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4159 | case Primitive::kPrimInt: |
| 4160 | case Primitive::kPrimNot: { |
| 4161 | if (!needs_runtime_call) { |
| 4162 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4163 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4164 | size_t offset = |
| 4165 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4166 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4167 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4168 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4169 | __ movl(temp, value.AsRegister<Register>()); |
| 4170 | __ PoisonHeapReference(temp); |
| 4171 | __ movl(Address(obj, offset), temp); |
| 4172 | } else { |
| 4173 | __ movl(Address(obj, offset), value.AsRegister<Register>()); |
| 4174 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4175 | } else { |
| 4176 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4177 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4178 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4179 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4180 | // Note: if heap poisoning is enabled, no need to poison |
| 4181 | // (negate) `v` if it is a reference, as it would be null. |
| 4182 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4183 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4184 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4185 | DCHECK(index.IsRegister()) << index; |
| 4186 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4187 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4188 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4189 | __ movl(temp, value.AsRegister<Register>()); |
| 4190 | __ PoisonHeapReference(temp); |
| 4191 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), temp); |
| 4192 | } else { |
| 4193 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4194 | value.AsRegister<Register>()); |
| 4195 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4196 | } else { |
| 4197 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4198 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4199 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4200 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4201 | // Note: if heap poisoning is enabled, no need to poison |
| 4202 | // (negate) `v` if it is a reference, as it would be null. |
| 4203 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4204 | } |
| 4205 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4206 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4207 | |
| 4208 | if (needs_write_barrier) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4209 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4210 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4211 | codegen_->MarkGCCard( |
| 4212 | temp, card, obj, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4213 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4214 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4215 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4216 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4217 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4218 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4219 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4220 | instruction, |
| 4221 | instruction->GetDexPc(), |
| 4222 | nullptr); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4223 | } |
| 4224 | break; |
| 4225 | } |
| 4226 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4227 | case Primitive::kPrimLong: { |
| 4228 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4229 | if (index.IsConstant()) { |
| 4230 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4231 | if (value.IsRegisterPair()) { |
| 4232 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4233 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4234 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4235 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4236 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4237 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4238 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4239 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4240 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 4241 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4242 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4243 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4244 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4245 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4246 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4247 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4248 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4249 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4250 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4251 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4252 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4253 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4254 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4255 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4256 | Immediate(High32Bits(val))); |
| 4257 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4258 | } |
| 4259 | break; |
| 4260 | } |
| 4261 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4262 | case Primitive::kPrimFloat: { |
| 4263 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4264 | DCHECK(value.IsFpuRegister()); |
| 4265 | if (index.IsConstant()) { |
| 4266 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4267 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4268 | } else { |
| 4269 | __ movss(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4270 | value.AsFpuRegister<XmmRegister>()); |
| 4271 | } |
| 4272 | break; |
| 4273 | } |
| 4274 | |
| 4275 | case Primitive::kPrimDouble: { |
| 4276 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4277 | DCHECK(value.IsFpuRegister()); |
| 4278 | if (index.IsConstant()) { |
| 4279 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4280 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4281 | } else { |
| 4282 | __ movsd(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
| 4283 | value.AsFpuRegister<XmmRegister>()); |
| 4284 | } |
| 4285 | break; |
| 4286 | } |
| 4287 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4288 | case Primitive::kPrimVoid: |
| 4289 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4290 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4291 | } |
| 4292 | } |
| 4293 | |
| 4294 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 4295 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4296 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4297 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 4301 | LocationSummary* locations = instruction->GetLocations(); |
| 4302 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4303 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4304 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4305 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4306 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4310 | LocationSummary* locations = |
| 4311 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4312 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4313 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4314 | if (instruction->HasUses()) { |
| 4315 | locations->SetOut(Location::SameAsFirstInput()); |
| 4316 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4320 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4321 | Location index_loc = locations->InAt(0); |
| 4322 | Location length_loc = locations->InAt(1); |
| 4323 | SlowPathCodeX86* slow_path = |
| 4324 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction, index_loc, length_loc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4325 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4326 | if (length_loc.IsConstant()) { |
| 4327 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4328 | if (index_loc.IsConstant()) { |
| 4329 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4330 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4331 | if (index < 0 || index >= length) { |
| 4332 | codegen_->AddSlowPath(slow_path); |
| 4333 | __ jmp(slow_path->GetEntryLabel()); |
| 4334 | } else { |
| 4335 | // Some optimization after BCE may have generated this, and we should not |
| 4336 | // generate a bounds check if it is a valid range. |
| 4337 | } |
| 4338 | return; |
| 4339 | } |
| 4340 | |
| 4341 | // We have to reverse the jump condition because the length is the constant. |
| 4342 | Register index_reg = index_loc.AsRegister<Register>(); |
| 4343 | __ cmpl(index_reg, Immediate(length)); |
| 4344 | codegen_->AddSlowPath(slow_path); |
| 4345 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4346 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4347 | Register length = length_loc.AsRegister<Register>(); |
| 4348 | if (index_loc.IsConstant()) { |
| 4349 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4350 | __ cmpl(length, Immediate(value)); |
| 4351 | } else { |
| 4352 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 4353 | } |
| 4354 | codegen_->AddSlowPath(slow_path); |
| 4355 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4356 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4357 | } |
| 4358 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4359 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 4360 | temp->SetLocations(nullptr); |
| 4361 | } |
| 4362 | |
| 4363 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 4364 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4365 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4366 | } |
| 4367 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4368 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4369 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4370 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4374 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4375 | } |
| 4376 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4377 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4378 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4379 | } |
| 4380 | |
| 4381 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4382 | HBasicBlock* block = instruction->GetBlock(); |
| 4383 | if (block->GetLoopInformation() != nullptr) { |
| 4384 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4385 | // The back edge will generate the suspend check. |
| 4386 | return; |
| 4387 | } |
| 4388 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4389 | // The goto will generate the suspend check. |
| 4390 | return; |
| 4391 | } |
| 4392 | GenerateSuspendCheck(instruction, nullptr); |
| 4393 | } |
| 4394 | |
| 4395 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4396 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4397 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4398 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 4399 | if (slow_path == nullptr) { |
| 4400 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 4401 | instruction->SetSlowPath(slow_path); |
| 4402 | codegen_->AddSlowPath(slow_path); |
| 4403 | if (successor != nullptr) { |
| 4404 | DCHECK(successor->IsLoopHeader()); |
| 4405 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4406 | } |
| 4407 | } else { |
| 4408 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4409 | } |
| 4410 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4411 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4412 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4413 | if (successor == nullptr) { |
| 4414 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4415 | __ Bind(slow_path->GetReturnLabel()); |
| 4416 | } else { |
| 4417 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4418 | __ jmp(slow_path->GetEntryLabel()); |
| 4419 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4420 | } |
| 4421 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4422 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 4423 | return codegen_->GetAssembler(); |
| 4424 | } |
| 4425 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4426 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4427 | ScratchRegisterScope ensure_scratch( |
| 4428 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4429 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4430 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4431 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4432 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4436 | ScratchRegisterScope ensure_scratch( |
| 4437 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4438 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4439 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4440 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4441 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 4442 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 4443 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 4447 | MoveOperands* move = moves_.Get(index); |
| 4448 | Location source = move->GetSource(); |
| 4449 | Location destination = move->GetDestination(); |
| 4450 | |
| 4451 | if (source.IsRegister()) { |
| 4452 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4453 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4454 | } else { |
| 4455 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4456 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4457 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4458 | } else if (source.IsFpuRegister()) { |
| 4459 | if (destination.IsFpuRegister()) { |
| 4460 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4461 | } else if (destination.IsStackSlot()) { |
| 4462 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4463 | } else { |
| 4464 | DCHECK(destination.IsDoubleStackSlot()); |
| 4465 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4466 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4467 | } else if (source.IsStackSlot()) { |
| 4468 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4469 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4470 | } else if (destination.IsFpuRegister()) { |
| 4471 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4472 | } else { |
| 4473 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4474 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4475 | } |
| 4476 | } else if (source.IsDoubleStackSlot()) { |
| 4477 | if (destination.IsFpuRegister()) { |
| 4478 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 4479 | } else { |
| 4480 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4481 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4482 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4483 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4484 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4485 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4486 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4487 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4488 | if (value == 0) { |
| 4489 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4490 | } else { |
| 4491 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 4492 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4493 | } else { |
| 4494 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4495 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4496 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4497 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4498 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4499 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4500 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4501 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4502 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4503 | if (value == 0) { |
| 4504 | // Easy handling of 0.0. |
| 4505 | __ xorps(dest, dest); |
| 4506 | } else { |
| 4507 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4508 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4509 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4510 | __ movl(temp, Immediate(value)); |
| 4511 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4512 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4513 | } else { |
| 4514 | DCHECK(destination.IsStackSlot()) << destination; |
| 4515 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 4516 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4517 | } else if (constant->IsLongConstant()) { |
| 4518 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4519 | int32_t low_value = Low32Bits(value); |
| 4520 | int32_t high_value = High32Bits(value); |
| 4521 | Immediate low(low_value); |
| 4522 | Immediate high(high_value); |
| 4523 | if (destination.IsDoubleStackSlot()) { |
| 4524 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4525 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4526 | } else { |
| 4527 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 4528 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 4529 | } |
| 4530 | } else { |
| 4531 | DCHECK(constant->IsDoubleConstant()); |
| 4532 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4533 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4534 | int32_t low_value = Low32Bits(value); |
| 4535 | int32_t high_value = High32Bits(value); |
| 4536 | Immediate low(low_value); |
| 4537 | Immediate high(high_value); |
| 4538 | if (destination.IsFpuRegister()) { |
| 4539 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4540 | if (value == 0) { |
| 4541 | // Easy handling of 0.0. |
| 4542 | __ xorpd(dest, dest); |
| 4543 | } else { |
| 4544 | __ pushl(high); |
| 4545 | __ pushl(low); |
| 4546 | __ movsd(dest, Address(ESP, 0)); |
| 4547 | __ addl(ESP, Immediate(8)); |
| 4548 | } |
| 4549 | } else { |
| 4550 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4551 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4552 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4553 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4554 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4555 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4556 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4557 | } |
| 4558 | } |
| 4559 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4560 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4561 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4562 | ScratchRegisterScope ensure_scratch( |
| 4563 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4564 | |
| 4565 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4566 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4567 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4568 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4569 | } |
| 4570 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4571 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4572 | ScratchRegisterScope ensure_scratch( |
| 4573 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4574 | |
| 4575 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4576 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4577 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4578 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4579 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4580 | } |
| 4581 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4582 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4583 | ScratchRegisterScope ensure_scratch1( |
| 4584 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4585 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4586 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4587 | ScratchRegisterScope ensure_scratch2( |
| 4588 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4589 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4590 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4591 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4592 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4593 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4594 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4595 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4596 | } |
| 4597 | |
| 4598 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 4599 | MoveOperands* move = moves_.Get(index); |
| 4600 | Location source = move->GetSource(); |
| 4601 | Location destination = move->GetDestination(); |
| 4602 | |
| 4603 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 4604 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 4605 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4606 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4607 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4608 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4609 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4610 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4611 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4612 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4613 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4614 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4615 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4616 | // Use XOR Swap algorithm to avoid a temporary. |
| 4617 | DCHECK_NE(source.reg(), destination.reg()); |
| 4618 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4619 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4620 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4621 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4622 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4623 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4624 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4625 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4626 | // Take advantage of the 16 bytes in the XMM register. |
| 4627 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4628 | Address stack(ESP, destination.GetStackIndex()); |
| 4629 | // Load the double into the high doubleword. |
| 4630 | __ movhpd(reg, stack); |
| 4631 | |
| 4632 | // Store the low double into the destination. |
| 4633 | __ movsd(stack, reg); |
| 4634 | |
| 4635 | // Move the high double to the low double. |
| 4636 | __ psrldq(reg, Immediate(8)); |
| 4637 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4638 | // Take advantage of the 16 bytes in the XMM register. |
| 4639 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4640 | Address stack(ESP, source.GetStackIndex()); |
| 4641 | // Load the double into the high doubleword. |
| 4642 | __ movhpd(reg, stack); |
| 4643 | |
| 4644 | // Store the low double into the destination. |
| 4645 | __ movsd(stack, reg); |
| 4646 | |
| 4647 | // Move the high double to the low double. |
| 4648 | __ psrldq(reg, Immediate(8)); |
| 4649 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4650 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4651 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4652 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4653 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4654 | } |
| 4655 | } |
| 4656 | |
| 4657 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4658 | __ pushl(static_cast<Register>(reg)); |
| 4659 | } |
| 4660 | |
| 4661 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4662 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4663 | } |
| 4664 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4665 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4666 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4667 | ? LocationSummary::kCallOnSlowPath |
| 4668 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4669 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4670 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4671 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4672 | locations->SetOut(Location::RequiresRegister()); |
| 4673 | } |
| 4674 | |
| 4675 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4676 | LocationSummary* locations = cls->GetLocations(); |
| 4677 | Register out = locations->Out().AsRegister<Register>(); |
| 4678 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4679 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4680 | DCHECK(!cls->CanCallRuntime()); |
| 4681 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4682 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4683 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4684 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4685 | __ movl(out, Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4686 | current_method, ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4687 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4688 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4689 | |
| 4690 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4691 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4692 | codegen_->AddSlowPath(slow_path); |
| 4693 | __ testl(out, out); |
| 4694 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4695 | if (cls->MustGenerateClinitCheck()) { |
| 4696 | GenerateClassInitializationCheck(slow_path, out); |
| 4697 | } else { |
| 4698 | __ Bind(slow_path->GetExitLabel()); |
| 4699 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4700 | } |
| 4701 | } |
| 4702 | |
| 4703 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 4704 | LocationSummary* locations = |
| 4705 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4706 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4707 | if (check->HasUses()) { |
| 4708 | locations->SetOut(Location::SameAsFirstInput()); |
| 4709 | } |
| 4710 | } |
| 4711 | |
| 4712 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4713 | // We assume the class to not be null. |
| 4714 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4715 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4716 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4717 | GenerateClassInitializationCheck(slow_path, |
| 4718 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4719 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4720 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4721 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 4722 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4723 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4724 | Immediate(mirror::Class::kStatusInitialized)); |
| 4725 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4726 | __ Bind(slow_path->GetExitLabel()); |
| 4727 | // No need for memory fence, thanks to the X86 memory model. |
| 4728 | } |
| 4729 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4730 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 4731 | LocationSummary* locations = |
| 4732 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4733 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4734 | locations->SetOut(Location::RequiresRegister()); |
| 4735 | } |
| 4736 | |
| 4737 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 4738 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 4739 | codegen_->AddSlowPath(slow_path); |
| 4740 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4741 | LocationSummary* locations = load->GetLocations(); |
| 4742 | Register out = locations->Out().AsRegister<Register>(); |
| 4743 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4744 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4745 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4746 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4747 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4748 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4749 | __ testl(out, out); |
| 4750 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4751 | __ Bind(slow_path->GetExitLabel()); |
| 4752 | } |
| 4753 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4754 | static Address GetExceptionTlsAddress() { |
| 4755 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 4756 | } |
| 4757 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4758 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 4759 | LocationSummary* locations = |
| 4760 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4761 | locations->SetOut(Location::RequiresRegister()); |
| 4762 | } |
| 4763 | |
| 4764 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4765 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 4766 | } |
| 4767 | |
| 4768 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 4769 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4770 | } |
| 4771 | |
| 4772 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4773 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 4777 | LocationSummary* locations = |
| 4778 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4779 | InvokeRuntimeCallingConvention calling_convention; |
| 4780 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4781 | } |
| 4782 | |
| 4783 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4784 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4785 | instruction, |
| 4786 | instruction->GetDexPc(), |
| 4787 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4788 | } |
| 4789 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4790 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4791 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4792 | ? LocationSummary::kNoCall |
| 4793 | : LocationSummary::kCallOnSlowPath; |
| 4794 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4795 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4796 | locations->SetInAt(1, Location::Any()); |
| 4797 | locations->SetOut(Location::RequiresRegister()); |
| 4798 | } |
| 4799 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4800 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4801 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4802 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4803 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4804 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4805 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4806 | Label done, zero; |
| 4807 | SlowPathCodeX86* slow_path = nullptr; |
| 4808 | |
| 4809 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4810 | // Avoid null check if we know obj is not null. |
| 4811 | if (instruction->MustDoNullCheck()) { |
| 4812 | __ testl(obj, obj); |
| 4813 | __ j(kEqual, &zero); |
| 4814 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4815 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4816 | __ movl(out, Address(obj, class_offset)); |
| 4817 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4818 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4819 | __ cmpl(out, cls.AsRegister<Register>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4820 | } else { |
| 4821 | DCHECK(cls.IsStackSlot()) << cls; |
| 4822 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 4823 | } |
| 4824 | |
| 4825 | if (instruction->IsClassFinal()) { |
| 4826 | // Classes must be equal for the instanceof to succeed. |
| 4827 | __ j(kNotEqual, &zero); |
| 4828 | __ movl(out, Immediate(1)); |
| 4829 | __ jmp(&done); |
| 4830 | } else { |
| 4831 | // If the classes are not equal, we go into a slow path. |
| 4832 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4833 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4834 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4835 | codegen_->AddSlowPath(slow_path); |
| 4836 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4837 | __ movl(out, Immediate(1)); |
| 4838 | __ jmp(&done); |
| 4839 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4840 | |
| 4841 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4842 | __ Bind(&zero); |
| 4843 | __ movl(out, Immediate(0)); |
| 4844 | } |
| 4845 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4846 | if (slow_path != nullptr) { |
| 4847 | __ Bind(slow_path->GetExitLabel()); |
| 4848 | } |
| 4849 | __ Bind(&done); |
| 4850 | } |
| 4851 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4852 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| 4853 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4854 | instruction, LocationSummary::kCallOnSlowPath); |
| 4855 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4856 | locations->SetInAt(1, Location::Any()); |
| 4857 | locations->AddTemp(Location::RequiresRegister()); |
| 4858 | } |
| 4859 | |
| 4860 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 4861 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4862 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4863 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4864 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4865 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4866 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 4867 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 4868 | codegen_->AddSlowPath(slow_path); |
| 4869 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4870 | // Avoid null check if we know obj is not null. |
| 4871 | if (instruction->MustDoNullCheck()) { |
| 4872 | __ testl(obj, obj); |
| 4873 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4874 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4875 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4876 | __ movl(temp, Address(obj, class_offset)); |
| 4877 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4878 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4879 | __ cmpl(temp, cls.AsRegister<Register>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4880 | } else { |
| 4881 | DCHECK(cls.IsStackSlot()) << cls; |
| 4882 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 4883 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4884 | // The checkcast succeeds if the classes are equal (fast path). |
| 4885 | // Otherwise, we need to go into the slow path to check the types. |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4886 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4887 | __ Bind(slow_path->GetExitLabel()); |
| 4888 | } |
| 4889 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4890 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4891 | LocationSummary* locations = |
| 4892 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4893 | InvokeRuntimeCallingConvention calling_convention; |
| 4894 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4895 | } |
| 4896 | |
| 4897 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4898 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 4899 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 4900 | instruction, |
| 4901 | instruction->GetDexPc(), |
| 4902 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4905 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4906 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4907 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4908 | |
| 4909 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4910 | LocationSummary* locations = |
| 4911 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4912 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4913 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4914 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4915 | locations->SetInAt(1, Location::Any()); |
| 4916 | locations->SetOut(Location::SameAsFirstInput()); |
| 4917 | } |
| 4918 | |
| 4919 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 4920 | HandleBitwiseOperation(instruction); |
| 4921 | } |
| 4922 | |
| 4923 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 4924 | HandleBitwiseOperation(instruction); |
| 4925 | } |
| 4926 | |
| 4927 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 4928 | HandleBitwiseOperation(instruction); |
| 4929 | } |
| 4930 | |
| 4931 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4932 | LocationSummary* locations = instruction->GetLocations(); |
| 4933 | Location first = locations->InAt(0); |
| 4934 | Location second = locations->InAt(1); |
| 4935 | DCHECK(first.Equals(locations->Out())); |
| 4936 | |
| 4937 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 4938 | if (second.IsRegister()) { |
| 4939 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4940 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4941 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4942 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4943 | } else { |
| 4944 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4945 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4946 | } |
| 4947 | } else if (second.IsConstant()) { |
| 4948 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4949 | __ andl(first.AsRegister<Register>(), |
| 4950 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4951 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4952 | __ orl(first.AsRegister<Register>(), |
| 4953 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4954 | } else { |
| 4955 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4956 | __ xorl(first.AsRegister<Register>(), |
| 4957 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4958 | } |
| 4959 | } else { |
| 4960 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4961 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4962 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4963 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4964 | } else { |
| 4965 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4966 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4967 | } |
| 4968 | } |
| 4969 | } else { |
| 4970 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 4971 | if (second.IsRegisterPair()) { |
| 4972 | if (instruction->IsAnd()) { |
| 4973 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 4974 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 4975 | } else if (instruction->IsOr()) { |
| 4976 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 4977 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 4978 | } else { |
| 4979 | DCHECK(instruction->IsXor()); |
| 4980 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 4981 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 4982 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4983 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4984 | if (instruction->IsAnd()) { |
| 4985 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 4986 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 4987 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 4988 | } else if (instruction->IsOr()) { |
| 4989 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 4990 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 4991 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 4992 | } else { |
| 4993 | DCHECK(instruction->IsXor()); |
| 4994 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 4995 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 4996 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 4997 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4998 | } else { |
| 4999 | DCHECK(second.IsConstant()) << second; |
| 5000 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5001 | int32_t low_value = Low32Bits(value); |
| 5002 | int32_t high_value = High32Bits(value); |
| 5003 | Immediate low(low_value); |
| 5004 | Immediate high(high_value); |
| 5005 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5006 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5007 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5008 | if (low_value == 0) { |
| 5009 | __ xorl(first_low, first_low); |
| 5010 | } else if (low_value != -1) { |
| 5011 | __ andl(first_low, low); |
| 5012 | } |
| 5013 | if (high_value == 0) { |
| 5014 | __ xorl(first_high, first_high); |
| 5015 | } else if (high_value != -1) { |
| 5016 | __ andl(first_high, high); |
| 5017 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5018 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5019 | if (low_value != 0) { |
| 5020 | __ orl(first_low, low); |
| 5021 | } |
| 5022 | if (high_value != 0) { |
| 5023 | __ orl(first_high, high); |
| 5024 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5025 | } else { |
| 5026 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5027 | if (low_value != 0) { |
| 5028 | __ xorl(first_low, low); |
| 5029 | } |
| 5030 | if (high_value != 0) { |
| 5031 | __ xorl(first_high, high); |
| 5032 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5033 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5034 | } |
| 5035 | } |
| 5036 | } |
| 5037 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5038 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 5039 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5040 | UNUSED(instruction); |
| 5041 | LOG(FATAL) << "Unreachable"; |
| 5042 | } |
| 5043 | |
| 5044 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 5045 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5046 | UNUSED(instruction); |
| 5047 | LOG(FATAL) << "Unreachable"; |
| 5048 | } |
| 5049 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5050 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 5051 | DCHECK(codegen_->IsBaseline()); |
| 5052 | LocationSummary* locations = |
| 5053 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5054 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5055 | } |
| 5056 | |
| 5057 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5058 | DCHECK(codegen_->IsBaseline()); |
| 5059 | // Will be generated at use site. |
| 5060 | } |
| 5061 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5062 | #undef __ |
| 5063 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5064 | } // namespace x86 |
| 5065 | } // namespace art |