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" |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | namespace x86 { |
| 38 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 39 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 40 | static constexpr Register kMethodRegisterArgument = EAX; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 41 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 42 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 43 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 44 | static constexpr int kC2ConditionMask = 0x400; |
| 45 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 46 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 47 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 48 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 49 | #define QUICK_ENTRY_POINT(x) Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x)) |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 50 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 51 | class NullCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 53 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 55 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 56 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 58 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 59 | instruction_, |
| 60 | instruction_->GetDexPc(), |
| 61 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 64 | bool IsFatal() const OVERRIDE { return true; } |
| 65 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 66 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 67 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 69 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 71 | }; |
| 72 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 73 | class DivZeroCheckSlowPathX86 : public SlowPathCodeX86 { |
| 74 | public: |
| 75 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 76 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 77 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 78 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 79 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 80 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 81 | instruction_, |
| 82 | instruction_->GetDexPc(), |
| 83 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 86 | bool IsFatal() const OVERRIDE { return true; } |
| 87 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 88 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 89 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | private: |
| 91 | HDivZeroCheck* const instruction_; |
| 92 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 93 | }; |
| 94 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 95 | class DivRemMinusOneSlowPathX86 : public SlowPathCodeX86 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 97 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 99 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 101 | if (is_div_) { |
| 102 | __ negl(reg_); |
| 103 | } else { |
| 104 | __ movl(reg_, Immediate(0)); |
| 105 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | __ jmp(GetExitLabel()); |
| 107 | } |
| 108 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 109 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 110 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | private: |
| 112 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | bool is_div_; |
| 114 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 117 | class BoundsCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 118 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 119 | BoundsCheckSlowPathX86(HBoundsCheck* instruction, |
| 120 | Location index_location, |
| 121 | Location length_location) |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 122 | : instruction_(instruction), |
| 123 | index_location_(index_location), |
| 124 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 125 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 126 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 127 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 128 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 129 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 130 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 131 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 132 | x86_codegen->EmitParallelMoves( |
| 133 | index_location_, |
| 134 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 135 | Primitive::kPrimInt, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 136 | length_location_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 137 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 138 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 139 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 140 | instruction_, |
| 141 | instruction_->GetDexPc(), |
| 142 | this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 143 | } |
| 144 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 145 | bool IsFatal() const OVERRIDE { return true; } |
| 146 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 147 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 148 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 149 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 150 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 151 | const Location index_location_; |
| 152 | const Location length_location_; |
| 153 | |
| 154 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 155 | }; |
| 156 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 157 | class SuspendCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 158 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 159 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 160 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 161 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 162 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 163 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 164 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 165 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 166 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 167 | instruction_, |
| 168 | instruction_->GetDexPc(), |
| 169 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 170 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 171 | if (successor_ == nullptr) { |
| 172 | __ jmp(GetReturnLabel()); |
| 173 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 174 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 175 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 178 | Label* GetReturnLabel() { |
| 179 | DCHECK(successor_ == nullptr); |
| 180 | return &return_label_; |
| 181 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 182 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 183 | HBasicBlock* GetSuccessor() const { |
| 184 | return successor_; |
| 185 | } |
| 186 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 187 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 188 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | private: |
| 190 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 191 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 192 | Label return_label_; |
| 193 | |
| 194 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 195 | }; |
| 196 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 197 | class LoadStringSlowPathX86 : public SlowPathCodeX86 { |
| 198 | public: |
| 199 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 200 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 201 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 202 | LocationSummary* locations = instruction_->GetLocations(); |
| 203 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 204 | |
| 205 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 206 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 207 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 208 | |
| 209 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 210 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 211 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 212 | instruction_, |
| 213 | instruction_->GetDexPc(), |
| 214 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 215 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 216 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 217 | |
| 218 | __ jmp(GetExitLabel()); |
| 219 | } |
| 220 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 221 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 222 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 223 | private: |
| 224 | HLoadString* const instruction_; |
| 225 | |
| 226 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 227 | }; |
| 228 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 229 | class LoadClassSlowPathX86 : public SlowPathCodeX86 { |
| 230 | public: |
| 231 | LoadClassSlowPathX86(HLoadClass* cls, |
| 232 | HInstruction* at, |
| 233 | uint32_t dex_pc, |
| 234 | bool do_clinit) |
| 235 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 236 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 237 | } |
| 238 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 239 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 240 | LocationSummary* locations = at_->GetLocations(); |
| 241 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 242 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 243 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | |
| 245 | InvokeRuntimeCallingConvention calling_convention; |
| 246 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 247 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 248 | : QUICK_ENTRY_POINT(pInitializeType), |
| 249 | at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 250 | |
| 251 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 252 | Location out = locations->Out(); |
| 253 | if (out.IsValid()) { |
| 254 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 255 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 256 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 257 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 258 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 259 | __ jmp(GetExitLabel()); |
| 260 | } |
| 261 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 262 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 263 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 264 | private: |
| 265 | // The class this slow path will load. |
| 266 | HLoadClass* const cls_; |
| 267 | |
| 268 | // The instruction where this slow path is happening. |
| 269 | // (Might be the load class or an initialization check). |
| 270 | HInstruction* const at_; |
| 271 | |
| 272 | // The dex PC of `at_`. |
| 273 | const uint32_t dex_pc_; |
| 274 | |
| 275 | // Whether to initialize the class. |
| 276 | const bool do_clinit_; |
| 277 | |
| 278 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 279 | }; |
| 280 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 281 | class TypeCheckSlowPathX86 : public SlowPathCodeX86 { |
| 282 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 283 | TypeCheckSlowPathX86(HInstruction* instruction, |
| 284 | Location class_to_check, |
| 285 | Location object_class, |
| 286 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 287 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 288 | class_to_check_(class_to_check), |
| 289 | object_class_(object_class), |
| 290 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 291 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 292 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 293 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 294 | DCHECK(instruction_->IsCheckCast() |
| 295 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 296 | |
| 297 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 298 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 299 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 300 | |
| 301 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 302 | // move resolver. |
| 303 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 304 | x86_codegen->EmitParallelMoves( |
| 305 | class_to_check_, |
| 306 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 307 | Primitive::kPrimNot, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 308 | object_class_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 309 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 310 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 311 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 312 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 313 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 314 | instruction_, |
| 315 | instruction_->GetDexPc(), |
| 316 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 317 | } else { |
| 318 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 319 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 320 | instruction_, |
| 321 | instruction_->GetDexPc(), |
| 322 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 325 | RecordPcInfo(codegen, instruction_, dex_pc_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 326 | if (instruction_->IsInstanceOf()) { |
| 327 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 328 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 329 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 330 | |
| 331 | __ jmp(GetExitLabel()); |
| 332 | } |
| 333 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 334 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
| 335 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 337 | HInstruction* const instruction_; |
| 338 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 340 | const uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 341 | |
| 342 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 343 | }; |
| 344 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 345 | class DeoptimizationSlowPathX86 : public SlowPathCodeX86 { |
| 346 | public: |
| 347 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 348 | : instruction_(instruction) {} |
| 349 | |
| 350 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 351 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 352 | __ Bind(GetEntryLabel()); |
| 353 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 354 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 355 | instruction_, |
| 356 | instruction_->GetDexPc(), |
| 357 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 358 | // No need to restore live registers. |
| 359 | DCHECK(instruction_->IsDeoptimize()); |
| 360 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 361 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 362 | codegen->RecordPcInfo(instruction_, dex_pc, this); |
| 363 | } |
| 364 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 365 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 366 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 367 | private: |
| 368 | HInstruction* const instruction_; |
| 369 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 370 | }; |
| 371 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 372 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 373 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 374 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 375 | inline Condition X86SignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 376 | switch (cond) { |
| 377 | case kCondEQ: return kEqual; |
| 378 | case kCondNE: return kNotEqual; |
| 379 | case kCondLT: return kLess; |
| 380 | case kCondLE: return kLessEqual; |
| 381 | case kCondGT: return kGreater; |
| 382 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 383 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 384 | LOG(FATAL) << "Unreachable"; |
| 385 | UNREACHABLE(); |
| 386 | } |
| 387 | |
| 388 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 389 | switch (cond) { |
| 390 | case kCondEQ: return kEqual; |
| 391 | case kCondNE: return kNotEqual; |
| 392 | case kCondLT: return kBelow; |
| 393 | case kCondLE: return kBelowEqual; |
| 394 | case kCondGT: return kAbove; |
| 395 | case kCondGE: return kAboveEqual; |
| 396 | } |
| 397 | LOG(FATAL) << "Unreachable"; |
| 398 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 401 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 402 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 406 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 409 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 410 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 411 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 414 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 415 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 416 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 419 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 420 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 421 | return GetFloatingPointSpillSlotSize(); |
| 422 | } |
| 423 | |
| 424 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 425 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 426 | return GetFloatingPointSpillSlotSize(); |
| 427 | } |
| 428 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 429 | void CodeGeneratorX86::InvokeRuntime(Address entry_point, |
| 430 | HInstruction* instruction, |
| 431 | uint32_t dex_pc, |
| 432 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 433 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 434 | __ fs()->call(entry_point); |
| 435 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 438 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| 439 | const X86InstructionSetFeatures& isa_features, |
| 440 | const CompilerOptions& compiler_options) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 441 | : CodeGenerator(graph, |
| 442 | kNumberOfCpuRegisters, |
| 443 | kNumberOfXmmRegisters, |
| 444 | kNumberOfRegisterPairs, |
| 445 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 446 | arraysize(kCoreCalleeSaves)) |
| 447 | | (1 << kFakeReturnRegister), |
| 448 | 0, |
| 449 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 450 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 451 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 452 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 453 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 454 | isa_features_(isa_features), |
| 455 | method_patches_(graph->GetArena()->Adapter()), |
| 456 | relative_call_patches_(graph->GetArena()->Adapter()) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 457 | // Use a fake return address register to mimic Quick. |
| 458 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 459 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 460 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 461 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 462 | switch (type) { |
| 463 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 464 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 465 | X86ManagedRegister pair = |
| 466 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 467 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 468 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 469 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 470 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 471 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 472 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | case Primitive::kPrimByte: |
| 476 | case Primitive::kPrimBoolean: |
| 477 | case Primitive::kPrimChar: |
| 478 | case Primitive::kPrimShort: |
| 479 | case Primitive::kPrimInt: |
| 480 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 481 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 482 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 483 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 484 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 485 | X86ManagedRegister current = |
| 486 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 487 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 488 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 489 | } |
| 490 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 491 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 495 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 496 | return Location::FpuRegisterLocation( |
| 497 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 498 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 499 | |
| 500 | case Primitive::kPrimVoid: |
| 501 | LOG(FATAL) << "Unreachable type " << type; |
| 502 | } |
| 503 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 504 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 505 | } |
| 506 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 507 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 508 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 509 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 510 | |
| 511 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 512 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 513 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 514 | if (is_baseline) { |
| 515 | blocked_core_registers_[EBP] = true; |
| 516 | blocked_core_registers_[ESI] = true; |
| 517 | blocked_core_registers_[EDI] = true; |
| 518 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 519 | |
| 520 | UpdateBlockedPairRegisters(); |
| 521 | } |
| 522 | |
| 523 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 524 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 525 | X86ManagedRegister current = |
| 526 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 527 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 528 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 529 | blocked_register_pairs_[i] = true; |
| 530 | } |
| 531 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 532 | } |
| 533 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 534 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 535 | : HGraphVisitor(graph), |
| 536 | assembler_(codegen->GetAssembler()), |
| 537 | codegen_(codegen) {} |
| 538 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 539 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 540 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 541 | } |
| 542 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 543 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 544 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 545 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 546 | bool skip_overflow_check = |
| 547 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 548 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 549 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 550 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 551 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 552 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 553 | } |
| 554 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 555 | if (HasEmptyFrame()) { |
| 556 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 557 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 558 | |
| 559 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 560 | Register reg = kCoreCalleeSaves[i]; |
| 561 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 562 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 563 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 564 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 568 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 569 | __ subl(ESP, Immediate(adjust)); |
| 570 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 571 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 575 | __ cfi().RememberState(); |
| 576 | if (!HasEmptyFrame()) { |
| 577 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 578 | __ addl(ESP, Immediate(adjust)); |
| 579 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 580 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 581 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 582 | Register reg = kCoreCalleeSaves[i]; |
| 583 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 584 | __ popl(reg); |
| 585 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 586 | __ cfi().Restore(DWARFReg(reg)); |
| 587 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 588 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 589 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 590 | __ ret(); |
| 591 | __ cfi().RestoreState(); |
| 592 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 595 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 596 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 599 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 600 | switch (load->GetType()) { |
| 601 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 602 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 603 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 604 | |
| 605 | case Primitive::kPrimInt: |
| 606 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 607 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 608 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 609 | |
| 610 | case Primitive::kPrimBoolean: |
| 611 | case Primitive::kPrimByte: |
| 612 | case Primitive::kPrimChar: |
| 613 | case Primitive::kPrimShort: |
| 614 | case Primitive::kPrimVoid: |
| 615 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 616 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 620 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 621 | } |
| 622 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 623 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 624 | switch (type) { |
| 625 | case Primitive::kPrimBoolean: |
| 626 | case Primitive::kPrimByte: |
| 627 | case Primitive::kPrimChar: |
| 628 | case Primitive::kPrimShort: |
| 629 | case Primitive::kPrimInt: |
| 630 | case Primitive::kPrimNot: |
| 631 | return Location::RegisterLocation(EAX); |
| 632 | |
| 633 | case Primitive::kPrimLong: |
| 634 | return Location::RegisterPairLocation(EAX, EDX); |
| 635 | |
| 636 | case Primitive::kPrimVoid: |
| 637 | return Location::NoLocation(); |
| 638 | |
| 639 | case Primitive::kPrimDouble: |
| 640 | case Primitive::kPrimFloat: |
| 641 | return Location::FpuRegisterLocation(XMM0); |
| 642 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 643 | |
| 644 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 648 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 649 | } |
| 650 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 651 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 652 | switch (type) { |
| 653 | case Primitive::kPrimBoolean: |
| 654 | case Primitive::kPrimByte: |
| 655 | case Primitive::kPrimChar: |
| 656 | case Primitive::kPrimShort: |
| 657 | case Primitive::kPrimInt: |
| 658 | case Primitive::kPrimNot: { |
| 659 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 660 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 661 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 662 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 663 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 664 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 665 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 666 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 667 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 668 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 669 | uint32_t index = gp_index_; |
| 670 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 671 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 672 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 673 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 674 | calling_convention.GetRegisterPairAt(index)); |
| 675 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 676 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 677 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 682 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 683 | stack_index_++; |
| 684 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 685 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 686 | } else { |
| 687 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 692 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 693 | stack_index_ += 2; |
| 694 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 695 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 696 | } else { |
| 697 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 701 | case Primitive::kPrimVoid: |
| 702 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 703 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 704 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 705 | return Location(); |
| 706 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 707 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 708 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 709 | if (source.Equals(destination)) { |
| 710 | return; |
| 711 | } |
| 712 | if (destination.IsRegister()) { |
| 713 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 714 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 715 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 716 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 717 | } else { |
| 718 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 719 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 720 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 721 | } else if (destination.IsFpuRegister()) { |
| 722 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 723 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 724 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 725 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 726 | } else { |
| 727 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 728 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 729 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 730 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 731 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 732 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 733 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 734 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 735 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 736 | } else if (source.IsConstant()) { |
| 737 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 738 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 739 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 740 | } else { |
| 741 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 742 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 743 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 749 | if (source.Equals(destination)) { |
| 750 | return; |
| 751 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 752 | if (destination.IsRegisterPair()) { |
| 753 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 754 | EmitParallelMoves( |
| 755 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 756 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 757 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 758 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 759 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 760 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 761 | } else if (source.IsFpuRegister()) { |
| 762 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 763 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 764 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 765 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 766 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 767 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 768 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 769 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 770 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 771 | if (source.IsFpuRegister()) { |
| 772 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 773 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 774 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 775 | } else { |
| 776 | LOG(FATAL) << "Unimplemented"; |
| 777 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 778 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 779 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 780 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 781 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 782 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 783 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 784 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 785 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 786 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 787 | } else if (source.IsConstant()) { |
| 788 | HConstant* constant = source.GetConstant(); |
| 789 | int64_t value; |
| 790 | if (constant->IsLongConstant()) { |
| 791 | value = constant->AsLongConstant()->GetValue(); |
| 792 | } else { |
| 793 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 794 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 795 | } |
| 796 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 797 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 798 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 799 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 800 | EmitParallelMoves( |
| 801 | Location::StackSlot(source.GetStackIndex()), |
| 802 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 803 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 804 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 805 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 806 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | } |
| 810 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 811 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 812 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 813 | if (instruction->IsCurrentMethod()) { |
| 814 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 815 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 816 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 817 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 818 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 819 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 820 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 821 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 822 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 823 | } else if (location.IsStackSlot()) { |
| 824 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 825 | } else { |
| 826 | DCHECK(location.IsConstant()); |
| 827 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 828 | } |
| 829 | } else if (const_to_move->IsLongConstant()) { |
| 830 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 831 | if (location.IsRegisterPair()) { |
| 832 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 833 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 834 | } else if (location.IsDoubleStackSlot()) { |
| 835 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 836 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 837 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 838 | } else { |
| 839 | DCHECK(location.IsConstant()); |
| 840 | DCHECK_EQ(location.GetConstant(), instruction); |
| 841 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 842 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 843 | } else if (instruction->IsTemporary()) { |
| 844 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 845 | if (temp_location.IsStackSlot()) { |
| 846 | Move32(location, temp_location); |
| 847 | } else { |
| 848 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 849 | Move64(location, temp_location); |
| 850 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 851 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 852 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 853 | switch (instruction->GetType()) { |
| 854 | case Primitive::kPrimBoolean: |
| 855 | case Primitive::kPrimByte: |
| 856 | case Primitive::kPrimChar: |
| 857 | case Primitive::kPrimShort: |
| 858 | case Primitive::kPrimInt: |
| 859 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 860 | case Primitive::kPrimFloat: |
| 861 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 862 | break; |
| 863 | |
| 864 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 865 | case Primitive::kPrimDouble: |
| 866 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 867 | break; |
| 868 | |
| 869 | default: |
| 870 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 871 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 872 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 873 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 874 | switch (instruction->GetType()) { |
| 875 | case Primitive::kPrimBoolean: |
| 876 | case Primitive::kPrimByte: |
| 877 | case Primitive::kPrimChar: |
| 878 | case Primitive::kPrimShort: |
| 879 | case Primitive::kPrimInt: |
| 880 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 881 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 882 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 883 | break; |
| 884 | |
| 885 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 886 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 887 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 891 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 892 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 896 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 897 | DCHECK(!successor->IsExitBlock()); |
| 898 | |
| 899 | HBasicBlock* block = got->GetBlock(); |
| 900 | HInstruction* previous = got->GetPrevious(); |
| 901 | |
| 902 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 903 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 904 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 909 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 910 | } |
| 911 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 912 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 916 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 917 | got->SetLocations(nullptr); |
| 918 | } |
| 919 | |
| 920 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 921 | HandleGoto(got, got->GetSuccessor()); |
| 922 | } |
| 923 | |
| 924 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 925 | try_boundary->SetLocations(nullptr); |
| 926 | } |
| 927 | |
| 928 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 929 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 930 | if (!successor->IsExitBlock()) { |
| 931 | HandleGoto(try_boundary, successor); |
| 932 | } |
| 933 | } |
| 934 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 935 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 936 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 939 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 940 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 943 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 944 | Label* true_label, |
| 945 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 946 | if (cond->IsFPConditionTrueIfNaN()) { |
| 947 | __ j(kUnordered, true_label); |
| 948 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 949 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 950 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 951 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 955 | Label* true_label, |
| 956 | Label* false_label) { |
| 957 | LocationSummary* locations = cond->GetLocations(); |
| 958 | Location left = locations->InAt(0); |
| 959 | Location right = locations->InAt(1); |
| 960 | IfCondition if_cond = cond->GetCondition(); |
| 961 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 962 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 963 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 964 | IfCondition true_high_cond = if_cond; |
| 965 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 966 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 967 | |
| 968 | // Set the conditions for the test, remembering that == needs to be |
| 969 | // decided using the low words. |
| 970 | switch (if_cond) { |
| 971 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 972 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 973 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 974 | break; |
| 975 | case kCondLT: |
| 976 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 977 | break; |
| 978 | case kCondLE: |
| 979 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 980 | break; |
| 981 | case kCondGT: |
| 982 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 983 | break; |
| 984 | case kCondGE: |
| 985 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 986 | break; |
| 987 | } |
| 988 | |
| 989 | if (right.IsConstant()) { |
| 990 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 991 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 992 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 993 | |
| 994 | if (val_high == 0) { |
| 995 | __ testl(left_high, left_high); |
| 996 | } else { |
| 997 | __ cmpl(left_high, Immediate(val_high)); |
| 998 | } |
| 999 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1000 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1001 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1002 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1003 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1004 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1005 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1006 | } |
| 1007 | // Must be equal high, so compare the lows. |
| 1008 | if (val_low == 0) { |
| 1009 | __ testl(left_low, left_low); |
| 1010 | } else { |
| 1011 | __ cmpl(left_low, Immediate(val_low)); |
| 1012 | } |
| 1013 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1014 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1015 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1016 | |
| 1017 | __ cmpl(left_high, right_high); |
| 1018 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1019 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1020 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1021 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1022 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1023 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1024 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1025 | } |
| 1026 | // Must be equal high, so compare the lows. |
| 1027 | __ cmpl(left_low, right_low); |
| 1028 | } |
| 1029 | // The last comparison might be unsigned. |
| 1030 | __ j(final_condition, true_label); |
| 1031 | } |
| 1032 | |
| 1033 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1034 | HCondition* condition, |
| 1035 | Label* true_target, |
| 1036 | Label* false_target, |
| 1037 | Label* always_true_target) { |
| 1038 | LocationSummary* locations = condition->GetLocations(); |
| 1039 | Location left = locations->InAt(0); |
| 1040 | Location right = locations->InAt(1); |
| 1041 | |
| 1042 | // We don't want true_target as a nullptr. |
| 1043 | if (true_target == nullptr) { |
| 1044 | true_target = always_true_target; |
| 1045 | } |
| 1046 | bool falls_through = (false_target == nullptr); |
| 1047 | |
| 1048 | // FP compares don't like null false_targets. |
| 1049 | if (false_target == nullptr) { |
| 1050 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1051 | } |
| 1052 | |
| 1053 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1054 | switch (type) { |
| 1055 | case Primitive::kPrimLong: |
| 1056 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1057 | break; |
| 1058 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1059 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1060 | GenerateFPJumps(condition, true_target, false_target); |
| 1061 | break; |
| 1062 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1063 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1064 | GenerateFPJumps(condition, true_target, false_target); |
| 1065 | break; |
| 1066 | default: |
| 1067 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1068 | } |
| 1069 | |
| 1070 | if (!falls_through) { |
| 1071 | __ jmp(false_target); |
| 1072 | } |
| 1073 | } |
| 1074 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1075 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| 1076 | Label* true_target, |
| 1077 | Label* false_target, |
| 1078 | Label* always_true_target) { |
| 1079 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1080 | if (cond->IsIntConstant()) { |
| 1081 | // Constant condition, statically compared against 1. |
| 1082 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1083 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1084 | if (always_true_target != nullptr) { |
| 1085 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1086 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1087 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1088 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1089 | DCHECK_EQ(cond_value, 0); |
| 1090 | } |
| 1091 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1092 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1093 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1094 | // Moves do not affect the eflags register, so if the condition is |
| 1095 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1096 | // again. We can't use the eflags on long/FP conditions if they are |
| 1097 | // materialized due to the complex branching. |
| 1098 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1099 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1100 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1101 | && (type != Primitive::kPrimLong && !Primitive::IsFloatingPointType(type)); |
| 1102 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1103 | if (!eflags_set) { |
| 1104 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1105 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1106 | if (lhs.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1107 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1108 | } else { |
| 1109 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1110 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1111 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1112 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1113 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1114 | } |
| 1115 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1116 | // Condition has not been materialized, use its inputs as the |
| 1117 | // comparison and its condition as the branch condition. |
| 1118 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1119 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1120 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1121 | // Generate the comparison directly. |
| 1122 | GenerateCompareTestAndBranch(instruction->AsIf(), |
| 1123 | cond->AsCondition(), |
| 1124 | true_target, |
| 1125 | false_target, |
| 1126 | always_true_target); |
| 1127 | return; |
| 1128 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1129 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1130 | Location lhs = cond->GetLocations()->InAt(0); |
| 1131 | Location rhs = cond->GetLocations()->InAt(1); |
| 1132 | // LHS is guaranteed to be in a register (see |
| 1133 | // LocationsBuilderX86::VisitCondition). |
| 1134 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1135 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1136 | } else if (rhs.IsConstant()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame] | 1137 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1138 | if (constant == 0) { |
| 1139 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1140 | } else { |
| 1141 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1142 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1143 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1144 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1145 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1146 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1147 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1148 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1149 | if (false_target != nullptr) { |
| 1150 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1154 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| 1155 | LocationSummary* locations = |
| 1156 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1157 | HInstruction* cond = if_instr->InputAt(0); |
| 1158 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1159 | locations->SetInAt(0, Location::Any()); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| 1164 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1165 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1166 | Label* always_true_target = true_target; |
| 1167 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1168 | if_instr->IfTrueSuccessor())) { |
| 1169 | always_true_target = nullptr; |
| 1170 | } |
| 1171 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1172 | if_instr->IfFalseSuccessor())) { |
| 1173 | false_target = nullptr; |
| 1174 | } |
| 1175 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1176 | } |
| 1177 | |
| 1178 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1179 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1180 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1181 | HInstruction* cond = deoptimize->InputAt(0); |
| 1182 | DCHECK(cond->IsCondition()); |
| 1183 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1184 | locations->SetInAt(0, Location::Any()); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1189 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) |
| 1190 | DeoptimizationSlowPathX86(deoptimize); |
| 1191 | codegen_->AddSlowPath(slow_path); |
| 1192 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1193 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1194 | } |
| 1195 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1196 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1197 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1200 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1201 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1204 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1205 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1208 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1209 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1210 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1213 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1214 | LocationSummary* locations = |
| 1215 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1216 | switch (store->InputAt(1)->GetType()) { |
| 1217 | case Primitive::kPrimBoolean: |
| 1218 | case Primitive::kPrimByte: |
| 1219 | case Primitive::kPrimChar: |
| 1220 | case Primitive::kPrimShort: |
| 1221 | case Primitive::kPrimInt: |
| 1222 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1223 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1224 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1225 | break; |
| 1226 | |
| 1227 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1228 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1229 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1230 | break; |
| 1231 | |
| 1232 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1233 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1234 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1237 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1238 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1241 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1242 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1243 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1244 | // Handle the long/FP comparisons made in instruction simplification. |
| 1245 | switch (cond->InputAt(0)->GetType()) { |
| 1246 | case Primitive::kPrimLong: { |
| 1247 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1248 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1249 | if (cond->NeedsMaterialization()) { |
| 1250 | locations->SetOut(Location::RequiresRegister()); |
| 1251 | } |
| 1252 | break; |
| 1253 | } |
| 1254 | case Primitive::kPrimFloat: |
| 1255 | case Primitive::kPrimDouble: { |
| 1256 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1257 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1258 | if (cond->NeedsMaterialization()) { |
| 1259 | locations->SetOut(Location::RequiresRegister()); |
| 1260 | } |
| 1261 | break; |
| 1262 | } |
| 1263 | default: |
| 1264 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1265 | locations->SetInAt(1, Location::Any()); |
| 1266 | if (cond->NeedsMaterialization()) { |
| 1267 | // We need a byte register. |
| 1268 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1269 | } |
| 1270 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1271 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1274 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 | if (!cond->NeedsMaterialization()) { |
| 1276 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1277 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1278 | |
| 1279 | LocationSummary* locations = cond->GetLocations(); |
| 1280 | Location lhs = locations->InAt(0); |
| 1281 | Location rhs = locations->InAt(1); |
| 1282 | Register reg = locations->Out().AsRegister<Register>(); |
| 1283 | Label true_label, false_label; |
| 1284 | |
| 1285 | switch (cond->InputAt(0)->GetType()) { |
| 1286 | default: { |
| 1287 | // Integer case. |
| 1288 | |
| 1289 | // Clear output register: setcc only sets the low byte. |
| 1290 | __ xorl(reg, reg); |
| 1291 | |
| 1292 | if (rhs.IsRegister()) { |
| 1293 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1294 | } else if (rhs.IsConstant()) { |
| 1295 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1296 | if (constant == 0) { |
| 1297 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1298 | } else { |
| 1299 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1300 | } |
| 1301 | } else { |
| 1302 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1303 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1304 | __ setb(X86SignedCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1305 | return; |
| 1306 | } |
| 1307 | case Primitive::kPrimLong: |
| 1308 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1309 | break; |
| 1310 | case Primitive::kPrimFloat: |
| 1311 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1312 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1313 | break; |
| 1314 | case Primitive::kPrimDouble: |
| 1315 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1316 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1317 | break; |
| 1318 | } |
| 1319 | |
| 1320 | // Convert the jumps into the result. |
| 1321 | Label done_label; |
| 1322 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1323 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1324 | __ Bind(&false_label); |
| 1325 | __ xorl(reg, reg); |
| 1326 | __ jmp(&done_label); |
| 1327 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1328 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1329 | __ Bind(&true_label); |
| 1330 | __ movl(reg, Immediate(1)); |
| 1331 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1335 | VisitCondition(comp); |
| 1336 | } |
| 1337 | |
| 1338 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1339 | VisitCondition(comp); |
| 1340 | } |
| 1341 | |
| 1342 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1343 | VisitCondition(comp); |
| 1344 | } |
| 1345 | |
| 1346 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1347 | VisitCondition(comp); |
| 1348 | } |
| 1349 | |
| 1350 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1351 | VisitCondition(comp); |
| 1352 | } |
| 1353 | |
| 1354 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1355 | VisitCondition(comp); |
| 1356 | } |
| 1357 | |
| 1358 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1359 | VisitCondition(comp); |
| 1360 | } |
| 1361 | |
| 1362 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1363 | VisitCondition(comp); |
| 1364 | } |
| 1365 | |
| 1366 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1367 | VisitCondition(comp); |
| 1368 | } |
| 1369 | |
| 1370 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1371 | VisitCondition(comp); |
| 1372 | } |
| 1373 | |
| 1374 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1375 | VisitCondition(comp); |
| 1376 | } |
| 1377 | |
| 1378 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1379 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1383 | LocationSummary* locations = |
| 1384 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1385 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1388 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1389 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1390 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1393 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1394 | LocationSummary* locations = |
| 1395 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1396 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1397 | } |
| 1398 | |
| 1399 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant) { |
| 1400 | // Will be generated at use site. |
| 1401 | UNUSED(constant); |
| 1402 | } |
| 1403 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1404 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1405 | LocationSummary* locations = |
| 1406 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1407 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 1411 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1412 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1413 | } |
| 1414 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1415 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1416 | LocationSummary* locations = |
| 1417 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1418 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1419 | } |
| 1420 | |
| 1421 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1422 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1423 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1427 | LocationSummary* locations = |
| 1428 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1429 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1430 | } |
| 1431 | |
| 1432 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1433 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1434 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1435 | } |
| 1436 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1437 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1438 | memory_barrier->SetLocations(nullptr); |
| 1439 | } |
| 1440 | |
| 1441 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1442 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1443 | } |
| 1444 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1445 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1446 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1449 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1450 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1451 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1452 | } |
| 1453 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1454 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1455 | LocationSummary* locations = |
| 1456 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1457 | switch (ret->InputAt(0)->GetType()) { |
| 1458 | case Primitive::kPrimBoolean: |
| 1459 | case Primitive::kPrimByte: |
| 1460 | case Primitive::kPrimChar: |
| 1461 | case Primitive::kPrimShort: |
| 1462 | case Primitive::kPrimInt: |
| 1463 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1464 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1465 | break; |
| 1466 | |
| 1467 | case Primitive::kPrimLong: |
| 1468 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1469 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1470 | break; |
| 1471 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1472 | case Primitive::kPrimFloat: |
| 1473 | case Primitive::kPrimDouble: |
| 1474 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1475 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1476 | break; |
| 1477 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1478 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1479 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1480 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1483 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1484 | if (kIsDebugBuild) { |
| 1485 | switch (ret->InputAt(0)->GetType()) { |
| 1486 | case Primitive::kPrimBoolean: |
| 1487 | case Primitive::kPrimByte: |
| 1488 | case Primitive::kPrimChar: |
| 1489 | case Primitive::kPrimShort: |
| 1490 | case Primitive::kPrimInt: |
| 1491 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1492 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1493 | break; |
| 1494 | |
| 1495 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1496 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1497 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1498 | break; |
| 1499 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1500 | case Primitive::kPrimFloat: |
| 1501 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1502 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1503 | break; |
| 1504 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1505 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1506 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1507 | } |
| 1508 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1509 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1512 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1513 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1514 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1515 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1516 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1517 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1518 | if (intrinsic.TryDispatch(invoke)) { |
| 1519 | return; |
| 1520 | } |
| 1521 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1522 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1523 | |
| 1524 | if (codegen_->IsBaseline()) { |
| 1525 | // Baseline does not have enough registers if the current method also |
| 1526 | // needs a register. We therefore do not require a register for it, and let |
| 1527 | // the code generation of the invoke handle it. |
| 1528 | LocationSummary* locations = invoke->GetLocations(); |
| 1529 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 1530 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 1531 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 1532 | } |
| 1533 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1534 | } |
| 1535 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1536 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1537 | if (invoke->GetLocations()->Intrinsified()) { |
| 1538 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1539 | intrinsic.Dispatch(invoke); |
| 1540 | return true; |
| 1541 | } |
| 1542 | return false; |
| 1543 | } |
| 1544 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1545 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1546 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1547 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1548 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1549 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1550 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1551 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1552 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1553 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1554 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1555 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1556 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1557 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1561 | HandleInvoke(invoke); |
| 1562 | } |
| 1563 | |
| 1564 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1565 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1566 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1569 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1570 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1571 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1572 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1573 | LocationSummary* locations = invoke->GetLocations(); |
| 1574 | Location receiver = locations->InAt(0); |
| 1575 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1576 | // temp = object->GetClass(); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1577 | DCHECK(receiver.IsRegister()); |
| 1578 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1579 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1580 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1581 | // temp = temp->GetMethodAt(method_offset); |
| 1582 | __ movl(temp, Address(temp, method_offset)); |
| 1583 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1584 | __ call(Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1585 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1586 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1587 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1588 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1591 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1592 | HandleInvoke(invoke); |
| 1593 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1594 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1598 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1599 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1600 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1601 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1602 | LocationSummary* locations = invoke->GetLocations(); |
| 1603 | Location receiver = locations->InAt(0); |
| 1604 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1605 | |
| 1606 | // Set the hidden argument. |
| 1607 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1608 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1609 | |
| 1610 | // temp = object->GetClass(); |
| 1611 | if (receiver.IsStackSlot()) { |
| 1612 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1613 | __ movl(temp, Address(temp, class_offset)); |
| 1614 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1615 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1616 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1617 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1618 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1619 | // temp = temp->GetImtEntryAt(method_offset); |
| 1620 | __ movl(temp, Address(temp, method_offset)); |
| 1621 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1622 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1623 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1624 | |
| 1625 | DCHECK(!codegen_->IsLeafMethod()); |
| 1626 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1627 | } |
| 1628 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1629 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1630 | LocationSummary* locations = |
| 1631 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1632 | switch (neg->GetResultType()) { |
| 1633 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1634 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1635 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1636 | locations->SetOut(Location::SameAsFirstInput()); |
| 1637 | break; |
| 1638 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1639 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1640 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1641 | locations->SetOut(Location::SameAsFirstInput()); |
| 1642 | locations->AddTemp(Location::RequiresRegister()); |
| 1643 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1644 | break; |
| 1645 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1646 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1647 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1648 | locations->SetOut(Location::SameAsFirstInput()); |
| 1649 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1650 | break; |
| 1651 | |
| 1652 | default: |
| 1653 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1658 | LocationSummary* locations = neg->GetLocations(); |
| 1659 | Location out = locations->Out(); |
| 1660 | Location in = locations->InAt(0); |
| 1661 | switch (neg->GetResultType()) { |
| 1662 | case Primitive::kPrimInt: |
| 1663 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1664 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1665 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1666 | break; |
| 1667 | |
| 1668 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1669 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1670 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1671 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1672 | // Negation is similar to subtraction from zero. The least |
| 1673 | // significant byte triggers a borrow when it is different from |
| 1674 | // zero; to take it into account, add 1 to the most significant |
| 1675 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1676 | // operation. |
| 1677 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1678 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1679 | break; |
| 1680 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1681 | case Primitive::kPrimFloat: { |
| 1682 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1683 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1684 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1685 | // Implement float negation with an exclusive or with value |
| 1686 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1687 | // single-precision floating-point number). |
| 1688 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1689 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1690 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1691 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1692 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1693 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1694 | case Primitive::kPrimDouble: { |
| 1695 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1696 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1697 | // Implement double negation with an exclusive or with value |
| 1698 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1699 | // a double-precision floating-point number). |
| 1700 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1701 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1702 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1703 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1704 | |
| 1705 | default: |
| 1706 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1707 | } |
| 1708 | } |
| 1709 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1710 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1711 | Primitive::Type result_type = conversion->GetResultType(); |
| 1712 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1713 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1714 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1715 | // The float-to-long and double-to-long type conversions rely on a |
| 1716 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1717 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1718 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1719 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1720 | ? LocationSummary::kCall |
| 1721 | : LocationSummary::kNoCall; |
| 1722 | LocationSummary* locations = |
| 1723 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1724 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1725 | // The Java language does not allow treating boolean as an integral type but |
| 1726 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1727 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1728 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1729 | case Primitive::kPrimByte: |
| 1730 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1731 | case Primitive::kPrimBoolean: |
| 1732 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1733 | case Primitive::kPrimShort: |
| 1734 | case Primitive::kPrimInt: |
| 1735 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1736 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1737 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1738 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1739 | // the validation of the linear scan implementation |
| 1740 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1741 | break; |
| 1742 | |
| 1743 | default: |
| 1744 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1745 | << " to " << result_type; |
| 1746 | } |
| 1747 | break; |
| 1748 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1749 | case Primitive::kPrimShort: |
| 1750 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1751 | case Primitive::kPrimBoolean: |
| 1752 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1753 | case Primitive::kPrimByte: |
| 1754 | case Primitive::kPrimInt: |
| 1755 | case Primitive::kPrimChar: |
| 1756 | // Processing a Dex `int-to-short' instruction. |
| 1757 | locations->SetInAt(0, Location::Any()); |
| 1758 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1759 | break; |
| 1760 | |
| 1761 | default: |
| 1762 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1763 | << " to " << result_type; |
| 1764 | } |
| 1765 | break; |
| 1766 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1767 | case Primitive::kPrimInt: |
| 1768 | switch (input_type) { |
| 1769 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1770 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1771 | locations->SetInAt(0, Location::Any()); |
| 1772 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1773 | break; |
| 1774 | |
| 1775 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1776 | // Processing a Dex `float-to-int' instruction. |
| 1777 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1778 | locations->SetOut(Location::RequiresRegister()); |
| 1779 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1780 | break; |
| 1781 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1782 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1783 | // Processing a Dex `double-to-int' instruction. |
| 1784 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1785 | locations->SetOut(Location::RequiresRegister()); |
| 1786 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1787 | break; |
| 1788 | |
| 1789 | default: |
| 1790 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1791 | << " to " << result_type; |
| 1792 | } |
| 1793 | break; |
| 1794 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1795 | case Primitive::kPrimLong: |
| 1796 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1797 | case Primitive::kPrimBoolean: |
| 1798 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1799 | case Primitive::kPrimByte: |
| 1800 | case Primitive::kPrimShort: |
| 1801 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1802 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1803 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1804 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1805 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1806 | break; |
| 1807 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1808 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1809 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1810 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1811 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1812 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1813 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1814 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1815 | // The runtime helper puts the result in EAX, EDX. |
| 1816 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1817 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1818 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1819 | |
| 1820 | default: |
| 1821 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1822 | << " to " << result_type; |
| 1823 | } |
| 1824 | break; |
| 1825 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1826 | case Primitive::kPrimChar: |
| 1827 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1828 | case Primitive::kPrimBoolean: |
| 1829 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1830 | case Primitive::kPrimByte: |
| 1831 | case Primitive::kPrimShort: |
| 1832 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1833 | // Processing a Dex `int-to-char' instruction. |
| 1834 | locations->SetInAt(0, Location::Any()); |
| 1835 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1836 | break; |
| 1837 | |
| 1838 | default: |
| 1839 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1840 | << " to " << result_type; |
| 1841 | } |
| 1842 | break; |
| 1843 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1844 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1845 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1846 | case Primitive::kPrimBoolean: |
| 1847 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1848 | case Primitive::kPrimByte: |
| 1849 | case Primitive::kPrimShort: |
| 1850 | case Primitive::kPrimInt: |
| 1851 | case Primitive::kPrimChar: |
| 1852 | // Processing a Dex `int-to-float' instruction. |
| 1853 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1854 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1855 | break; |
| 1856 | |
| 1857 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1858 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1859 | locations->SetInAt(0, Location::Any()); |
| 1860 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1861 | break; |
| 1862 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1863 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1864 | // Processing a Dex `double-to-float' instruction. |
| 1865 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1866 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1867 | break; |
| 1868 | |
| 1869 | default: |
| 1870 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1871 | << " to " << result_type; |
| 1872 | }; |
| 1873 | break; |
| 1874 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1875 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1876 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1877 | case Primitive::kPrimBoolean: |
| 1878 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1879 | case Primitive::kPrimByte: |
| 1880 | case Primitive::kPrimShort: |
| 1881 | case Primitive::kPrimInt: |
| 1882 | case Primitive::kPrimChar: |
| 1883 | // Processing a Dex `int-to-double' instruction. |
| 1884 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1885 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1886 | break; |
| 1887 | |
| 1888 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1889 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1890 | locations->SetInAt(0, Location::Any()); |
| 1891 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1892 | break; |
| 1893 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1894 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1895 | // Processing a Dex `float-to-double' instruction. |
| 1896 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1897 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1898 | break; |
| 1899 | |
| 1900 | default: |
| 1901 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1902 | << " to " << result_type; |
| 1903 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1904 | break; |
| 1905 | |
| 1906 | default: |
| 1907 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1908 | << " to " << result_type; |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1913 | LocationSummary* locations = conversion->GetLocations(); |
| 1914 | Location out = locations->Out(); |
| 1915 | Location in = locations->InAt(0); |
| 1916 | Primitive::Type result_type = conversion->GetResultType(); |
| 1917 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1918 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1919 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1920 | case Primitive::kPrimByte: |
| 1921 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1922 | case Primitive::kPrimBoolean: |
| 1923 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1924 | case Primitive::kPrimShort: |
| 1925 | case Primitive::kPrimInt: |
| 1926 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1927 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1928 | if (in.IsRegister()) { |
| 1929 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1930 | } else { |
| 1931 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1932 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1933 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 1934 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1935 | break; |
| 1936 | |
| 1937 | default: |
| 1938 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1939 | << " to " << result_type; |
| 1940 | } |
| 1941 | break; |
| 1942 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1943 | case Primitive::kPrimShort: |
| 1944 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1945 | case Primitive::kPrimBoolean: |
| 1946 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1947 | case Primitive::kPrimByte: |
| 1948 | case Primitive::kPrimInt: |
| 1949 | case Primitive::kPrimChar: |
| 1950 | // Processing a Dex `int-to-short' instruction. |
| 1951 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1952 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1953 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1954 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1955 | } else { |
| 1956 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1957 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1958 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1959 | } |
| 1960 | break; |
| 1961 | |
| 1962 | default: |
| 1963 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1964 | << " to " << result_type; |
| 1965 | } |
| 1966 | break; |
| 1967 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1968 | case Primitive::kPrimInt: |
| 1969 | switch (input_type) { |
| 1970 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1971 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1972 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1973 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1974 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1975 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1976 | } else { |
| 1977 | DCHECK(in.IsConstant()); |
| 1978 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1979 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1980 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1981 | } |
| 1982 | break; |
| 1983 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1984 | case Primitive::kPrimFloat: { |
| 1985 | // Processing a Dex `float-to-int' instruction. |
| 1986 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1987 | Register output = out.AsRegister<Register>(); |
| 1988 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1989 | Label done, nan; |
| 1990 | |
| 1991 | __ movl(output, Immediate(kPrimIntMax)); |
| 1992 | // temp = int-to-float(output) |
| 1993 | __ cvtsi2ss(temp, output); |
| 1994 | // if input >= temp goto done |
| 1995 | __ comiss(input, temp); |
| 1996 | __ j(kAboveEqual, &done); |
| 1997 | // if input == NaN goto nan |
| 1998 | __ j(kUnordered, &nan); |
| 1999 | // output = float-to-int-truncate(input) |
| 2000 | __ cvttss2si(output, input); |
| 2001 | __ jmp(&done); |
| 2002 | __ Bind(&nan); |
| 2003 | // output = 0 |
| 2004 | __ xorl(output, output); |
| 2005 | __ Bind(&done); |
| 2006 | break; |
| 2007 | } |
| 2008 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2009 | case Primitive::kPrimDouble: { |
| 2010 | // Processing a Dex `double-to-int' instruction. |
| 2011 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2012 | Register output = out.AsRegister<Register>(); |
| 2013 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2014 | Label done, nan; |
| 2015 | |
| 2016 | __ movl(output, Immediate(kPrimIntMax)); |
| 2017 | // temp = int-to-double(output) |
| 2018 | __ cvtsi2sd(temp, output); |
| 2019 | // if input >= temp goto done |
| 2020 | __ comisd(input, temp); |
| 2021 | __ j(kAboveEqual, &done); |
| 2022 | // if input == NaN goto nan |
| 2023 | __ j(kUnordered, &nan); |
| 2024 | // output = double-to-int-truncate(input) |
| 2025 | __ cvttsd2si(output, input); |
| 2026 | __ jmp(&done); |
| 2027 | __ Bind(&nan); |
| 2028 | // output = 0 |
| 2029 | __ xorl(output, output); |
| 2030 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2031 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2032 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2033 | |
| 2034 | default: |
| 2035 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2036 | << " to " << result_type; |
| 2037 | } |
| 2038 | break; |
| 2039 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2040 | case Primitive::kPrimLong: |
| 2041 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2042 | case Primitive::kPrimBoolean: |
| 2043 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2044 | case Primitive::kPrimByte: |
| 2045 | case Primitive::kPrimShort: |
| 2046 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2047 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2048 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2049 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2050 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2051 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2052 | __ cdq(); |
| 2053 | break; |
| 2054 | |
| 2055 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2056 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2057 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2058 | conversion, |
| 2059 | conversion->GetDexPc(), |
| 2060 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2061 | break; |
| 2062 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2063 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2064 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2065 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2066 | conversion, |
| 2067 | conversion->GetDexPc(), |
| 2068 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2069 | break; |
| 2070 | |
| 2071 | default: |
| 2072 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2073 | << " to " << result_type; |
| 2074 | } |
| 2075 | break; |
| 2076 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2077 | case Primitive::kPrimChar: |
| 2078 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2079 | case Primitive::kPrimBoolean: |
| 2080 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2081 | case Primitive::kPrimByte: |
| 2082 | case Primitive::kPrimShort: |
| 2083 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2084 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2085 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2086 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2087 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2088 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2089 | } else { |
| 2090 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2091 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2092 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2093 | } |
| 2094 | break; |
| 2095 | |
| 2096 | default: |
| 2097 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2098 | << " to " << result_type; |
| 2099 | } |
| 2100 | break; |
| 2101 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2102 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2103 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2104 | case Primitive::kPrimBoolean: |
| 2105 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2106 | case Primitive::kPrimByte: |
| 2107 | case Primitive::kPrimShort: |
| 2108 | case Primitive::kPrimInt: |
| 2109 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2110 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2111 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2112 | break; |
| 2113 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2114 | case Primitive::kPrimLong: { |
| 2115 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2116 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2117 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2118 | // Create stack space for the call to |
| 2119 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2120 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2121 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2122 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2123 | __ subl(ESP, Immediate(adjustment)); |
| 2124 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2125 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2126 | // Load the value to the FP stack, using temporaries if needed. |
| 2127 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2128 | |
| 2129 | if (out.IsStackSlot()) { |
| 2130 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2131 | } else { |
| 2132 | __ fstps(Address(ESP, 0)); |
| 2133 | Location stack_temp = Location::StackSlot(0); |
| 2134 | codegen_->Move32(out, stack_temp); |
| 2135 | } |
| 2136 | |
| 2137 | // Remove the temporary stack space we allocated. |
| 2138 | if (adjustment != 0) { |
| 2139 | __ addl(ESP, Immediate(adjustment)); |
| 2140 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2141 | break; |
| 2142 | } |
| 2143 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2144 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2145 | // Processing a Dex `double-to-float' instruction. |
| 2146 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2147 | break; |
| 2148 | |
| 2149 | default: |
| 2150 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2151 | << " to " << result_type; |
| 2152 | }; |
| 2153 | break; |
| 2154 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2155 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2156 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2157 | case Primitive::kPrimBoolean: |
| 2158 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2159 | case Primitive::kPrimByte: |
| 2160 | case Primitive::kPrimShort: |
| 2161 | case Primitive::kPrimInt: |
| 2162 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2163 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2164 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2165 | break; |
| 2166 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2167 | case Primitive::kPrimLong: { |
| 2168 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2169 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2170 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2171 | // Create stack space for the call to |
| 2172 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2173 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2174 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2175 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2176 | __ subl(ESP, Immediate(adjustment)); |
| 2177 | } |
| 2178 | |
| 2179 | // Load the value to the FP stack, using temporaries if needed. |
| 2180 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2181 | |
| 2182 | if (out.IsDoubleStackSlot()) { |
| 2183 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2184 | } else { |
| 2185 | __ fstpl(Address(ESP, 0)); |
| 2186 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2187 | codegen_->Move64(out, stack_temp); |
| 2188 | } |
| 2189 | |
| 2190 | // Remove the temporary stack space we allocated. |
| 2191 | if (adjustment != 0) { |
| 2192 | __ addl(ESP, Immediate(adjustment)); |
| 2193 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2194 | break; |
| 2195 | } |
| 2196 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2197 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2198 | // Processing a Dex `float-to-double' instruction. |
| 2199 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2200 | break; |
| 2201 | |
| 2202 | default: |
| 2203 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2204 | << " to " << result_type; |
| 2205 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2206 | break; |
| 2207 | |
| 2208 | default: |
| 2209 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2210 | << " to " << result_type; |
| 2211 | } |
| 2212 | } |
| 2213 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2214 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2215 | LocationSummary* locations = |
| 2216 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2217 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2218 | case Primitive::kPrimInt: { |
| 2219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2220 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2221 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2222 | break; |
| 2223 | } |
| 2224 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2225 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2226 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2227 | locations->SetInAt(1, Location::Any()); |
| 2228 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2229 | break; |
| 2230 | } |
| 2231 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2232 | case Primitive::kPrimFloat: |
| 2233 | case Primitive::kPrimDouble: { |
| 2234 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Calin Juravle | 3173c8a | 2015-02-23 15:53:39 +0000 | [diff] [blame] | 2235 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2236 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2237 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2238 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2239 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2240 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2241 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2242 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2243 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2247 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2248 | Location first = locations->InAt(0); |
| 2249 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2250 | Location out = locations->Out(); |
| 2251 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2252 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2253 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2254 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2255 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2256 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2257 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2258 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2259 | } else { |
| 2260 | __ leal(out.AsRegister<Register>(), Address( |
| 2261 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2262 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2263 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2264 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2265 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2266 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2267 | } else { |
| 2268 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2269 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2270 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2271 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2272 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2273 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2274 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2278 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2279 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2280 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2281 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2282 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2283 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2284 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2285 | } else { |
| 2286 | DCHECK(second.IsConstant()) << second; |
| 2287 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2288 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2289 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2290 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2291 | break; |
| 2292 | } |
| 2293 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2294 | case Primitive::kPrimFloat: { |
| 2295 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2296 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2297 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2298 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | case Primitive::kPrimDouble: { |
| 2302 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2303 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2304 | } |
| 2305 | break; |
| 2306 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2307 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2308 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2309 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2310 | } |
| 2311 | } |
| 2312 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2313 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2314 | LocationSummary* locations = |
| 2315 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2316 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2317 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2318 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2319 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2320 | locations->SetInAt(1, Location::Any()); |
| 2321 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2322 | break; |
| 2323 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2324 | case Primitive::kPrimFloat: |
| 2325 | case Primitive::kPrimDouble: { |
| 2326 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2327 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2328 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2329 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2330 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2331 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2332 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2333 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2334 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2338 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2339 | Location first = locations->InAt(0); |
| 2340 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2341 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2342 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2343 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2344 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2345 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2346 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2347 | __ subl(first.AsRegister<Register>(), |
| 2348 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2349 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2350 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2351 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2352 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2356 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2357 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2358 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2359 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2360 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2361 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2362 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2363 | } else { |
| 2364 | DCHECK(second.IsConstant()) << second; |
| 2365 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2366 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2367 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2368 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2369 | break; |
| 2370 | } |
| 2371 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2372 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2373 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2374 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2378 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2379 | break; |
| 2380 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2381 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2382 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2383 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2384 | } |
| 2385 | } |
| 2386 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2387 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2388 | LocationSummary* locations = |
| 2389 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2390 | switch (mul->GetResultType()) { |
| 2391 | case Primitive::kPrimInt: |
| 2392 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2393 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2394 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2395 | // Can use 3 operand multiply. |
| 2396 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2397 | } else { |
| 2398 | locations->SetOut(Location::SameAsFirstInput()); |
| 2399 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2400 | break; |
| 2401 | case Primitive::kPrimLong: { |
| 2402 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2403 | locations->SetInAt(1, Location::Any()); |
| 2404 | locations->SetOut(Location::SameAsFirstInput()); |
| 2405 | // Needed for imul on 32bits with 64bits output. |
| 2406 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2407 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2408 | break; |
| 2409 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2410 | case Primitive::kPrimFloat: |
| 2411 | case Primitive::kPrimDouble: { |
| 2412 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2413 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2414 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2415 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2416 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2417 | |
| 2418 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2419 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2424 | LocationSummary* locations = mul->GetLocations(); |
| 2425 | Location first = locations->InAt(0); |
| 2426 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2427 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2428 | |
| 2429 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2430 | case Primitive::kPrimInt: |
| 2431 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2432 | // problems where the output may not be the same as the first operand. |
| 2433 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2434 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2435 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2436 | } else if (second.IsRegister()) { |
| 2437 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2438 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2439 | } else { |
| 2440 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2441 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2442 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2443 | } |
| 2444 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2445 | |
| 2446 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2447 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2448 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2449 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2450 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2451 | |
| 2452 | DCHECK_EQ(EAX, eax); |
| 2453 | DCHECK_EQ(EDX, edx); |
| 2454 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2455 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2456 | // output: in1 |
| 2457 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2458 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2459 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2460 | if (second.IsConstant()) { |
| 2461 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2462 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2463 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2464 | int32_t low_value = Low32Bits(value); |
| 2465 | int32_t high_value = High32Bits(value); |
| 2466 | Immediate low(low_value); |
| 2467 | Immediate high(high_value); |
| 2468 | |
| 2469 | __ movl(eax, high); |
| 2470 | // eax <- in1.lo * in2.hi |
| 2471 | __ imull(eax, in1_lo); |
| 2472 | // in1.hi <- in1.hi * in2.lo |
| 2473 | __ imull(in1_hi, low); |
| 2474 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2475 | __ addl(in1_hi, eax); |
| 2476 | // move in2_lo to eax to prepare for double precision |
| 2477 | __ movl(eax, low); |
| 2478 | // edx:eax <- in1.lo * in2.lo |
| 2479 | __ mull(in1_lo); |
| 2480 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2481 | __ addl(in1_hi, edx); |
| 2482 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2483 | __ movl(in1_lo, eax); |
| 2484 | } else if (second.IsRegisterPair()) { |
| 2485 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2486 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2487 | |
| 2488 | __ movl(eax, in2_hi); |
| 2489 | // eax <- in1.lo * in2.hi |
| 2490 | __ imull(eax, in1_lo); |
| 2491 | // in1.hi <- in1.hi * in2.lo |
| 2492 | __ imull(in1_hi, in2_lo); |
| 2493 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2494 | __ addl(in1_hi, eax); |
| 2495 | // move in1_lo to eax to prepare for double precision |
| 2496 | __ movl(eax, in1_lo); |
| 2497 | // edx:eax <- in1.lo * in2.lo |
| 2498 | __ mull(in2_lo); |
| 2499 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2500 | __ addl(in1_hi, edx); |
| 2501 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2502 | __ movl(in1_lo, eax); |
| 2503 | } else { |
| 2504 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2505 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2506 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2507 | |
| 2508 | __ movl(eax, in2_hi); |
| 2509 | // eax <- in1.lo * in2.hi |
| 2510 | __ imull(eax, in1_lo); |
| 2511 | // in1.hi <- in1.hi * in2.lo |
| 2512 | __ imull(in1_hi, in2_lo); |
| 2513 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2514 | __ addl(in1_hi, eax); |
| 2515 | // move in1_lo to eax to prepare for double precision |
| 2516 | __ movl(eax, in1_lo); |
| 2517 | // edx:eax <- in1.lo * in2.lo |
| 2518 | __ mull(in2_lo); |
| 2519 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2520 | __ addl(in1_hi, edx); |
| 2521 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2522 | __ movl(in1_lo, eax); |
| 2523 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2524 | |
| 2525 | break; |
| 2526 | } |
| 2527 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2528 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2529 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2530 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2534 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2535 | break; |
| 2536 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2537 | |
| 2538 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2539 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2540 | } |
| 2541 | } |
| 2542 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2543 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 2544 | uint32_t temp_offset, |
| 2545 | uint32_t stack_adjustment, |
| 2546 | bool is_fp, |
| 2547 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2548 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2549 | DCHECK(!is_wide); |
| 2550 | if (is_fp) { |
| 2551 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2552 | } else { |
| 2553 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2554 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2555 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2556 | DCHECK(is_wide); |
| 2557 | if (is_fp) { |
| 2558 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2559 | } else { |
| 2560 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2561 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2562 | } else { |
| 2563 | // 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] | 2564 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2565 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2566 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2567 | if (is_fp) { |
| 2568 | __ flds(Address(ESP, temp_offset)); |
| 2569 | } else { |
| 2570 | __ filds(Address(ESP, temp_offset)); |
| 2571 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2572 | } else { |
| 2573 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2574 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2575 | if (is_fp) { |
| 2576 | __ fldl(Address(ESP, temp_offset)); |
| 2577 | } else { |
| 2578 | __ fildl(Address(ESP, temp_offset)); |
| 2579 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2580 | } |
| 2581 | } |
| 2582 | } |
| 2583 | |
| 2584 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2585 | Primitive::Type type = rem->GetResultType(); |
| 2586 | bool is_float = type == Primitive::kPrimFloat; |
| 2587 | size_t elem_size = Primitive::ComponentSize(type); |
| 2588 | LocationSummary* locations = rem->GetLocations(); |
| 2589 | Location first = locations->InAt(0); |
| 2590 | Location second = locations->InAt(1); |
| 2591 | Location out = locations->Out(); |
| 2592 | |
| 2593 | // Create stack space for 2 elements. |
| 2594 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2595 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2596 | |
| 2597 | // 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] | 2598 | const bool is_wide = !is_float; |
| 2599 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 2600 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2601 | |
| 2602 | // Loop doing FPREM until we stabilize. |
| 2603 | Label retry; |
| 2604 | __ Bind(&retry); |
| 2605 | __ fprem(); |
| 2606 | |
| 2607 | // Move FP status to AX. |
| 2608 | __ fstsw(); |
| 2609 | |
| 2610 | // And see if the argument reduction is complete. This is signaled by the |
| 2611 | // C2 FPU flag bit set to 0. |
| 2612 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2613 | __ j(kNotEqual, &retry); |
| 2614 | |
| 2615 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2616 | // Store FP top of stack to real stack. |
| 2617 | if (is_float) { |
| 2618 | __ fsts(Address(ESP, 0)); |
| 2619 | } else { |
| 2620 | __ fstl(Address(ESP, 0)); |
| 2621 | } |
| 2622 | |
| 2623 | // Pop the 2 items from the FP stack. |
| 2624 | __ fucompp(); |
| 2625 | |
| 2626 | // Load the value from the stack into an XMM register. |
| 2627 | DCHECK(out.IsFpuRegister()) << out; |
| 2628 | if (is_float) { |
| 2629 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2630 | } else { |
| 2631 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2632 | } |
| 2633 | |
| 2634 | // And remove the temporary stack space we allocated. |
| 2635 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2636 | } |
| 2637 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2638 | |
| 2639 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2640 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2641 | |
| 2642 | LocationSummary* locations = instruction->GetLocations(); |
| 2643 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2644 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2645 | |
| 2646 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2647 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2648 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2649 | |
| 2650 | DCHECK(imm == 1 || imm == -1); |
| 2651 | |
| 2652 | if (instruction->IsRem()) { |
| 2653 | __ xorl(out_register, out_register); |
| 2654 | } else { |
| 2655 | __ movl(out_register, input_register); |
| 2656 | if (imm == -1) { |
| 2657 | __ negl(out_register); |
| 2658 | } |
| 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2663 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2664 | LocationSummary* locations = instruction->GetLocations(); |
| 2665 | |
| 2666 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2667 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2668 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2669 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2670 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2671 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2672 | |
| 2673 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2674 | __ testl(input_register, input_register); |
| 2675 | __ cmovl(kGreaterEqual, num, input_register); |
| 2676 | int shift = CTZ(imm); |
| 2677 | __ sarl(num, Immediate(shift)); |
| 2678 | |
| 2679 | if (imm < 0) { |
| 2680 | __ negl(num); |
| 2681 | } |
| 2682 | |
| 2683 | __ movl(out_register, num); |
| 2684 | } |
| 2685 | |
| 2686 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2687 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2688 | |
| 2689 | LocationSummary* locations = instruction->GetLocations(); |
| 2690 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2691 | |
| 2692 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2693 | Register out = locations->Out().AsRegister<Register>(); |
| 2694 | Register num; |
| 2695 | Register edx; |
| 2696 | |
| 2697 | if (instruction->IsDiv()) { |
| 2698 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2699 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2700 | } else { |
| 2701 | edx = locations->Out().AsRegister<Register>(); |
| 2702 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2703 | } |
| 2704 | |
| 2705 | DCHECK_EQ(EAX, eax); |
| 2706 | DCHECK_EQ(EDX, edx); |
| 2707 | if (instruction->IsDiv()) { |
| 2708 | DCHECK_EQ(EAX, out); |
| 2709 | } else { |
| 2710 | DCHECK_EQ(EDX, out); |
| 2711 | } |
| 2712 | |
| 2713 | int64_t magic; |
| 2714 | int shift; |
| 2715 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2716 | |
| 2717 | Label ndiv; |
| 2718 | Label end; |
| 2719 | // If numerator is 0, the result is 0, no computation needed. |
| 2720 | __ testl(eax, eax); |
| 2721 | __ j(kNotEqual, &ndiv); |
| 2722 | |
| 2723 | __ xorl(out, out); |
| 2724 | __ jmp(&end); |
| 2725 | |
| 2726 | __ Bind(&ndiv); |
| 2727 | |
| 2728 | // Save the numerator. |
| 2729 | __ movl(num, eax); |
| 2730 | |
| 2731 | // EAX = magic |
| 2732 | __ movl(eax, Immediate(magic)); |
| 2733 | |
| 2734 | // EDX:EAX = magic * numerator |
| 2735 | __ imull(num); |
| 2736 | |
| 2737 | if (imm > 0 && magic < 0) { |
| 2738 | // EDX += num |
| 2739 | __ addl(edx, num); |
| 2740 | } else if (imm < 0 && magic > 0) { |
| 2741 | __ subl(edx, num); |
| 2742 | } |
| 2743 | |
| 2744 | // Shift if needed. |
| 2745 | if (shift != 0) { |
| 2746 | __ sarl(edx, Immediate(shift)); |
| 2747 | } |
| 2748 | |
| 2749 | // EDX += 1 if EDX < 0 |
| 2750 | __ movl(eax, edx); |
| 2751 | __ shrl(edx, Immediate(31)); |
| 2752 | __ addl(edx, eax); |
| 2753 | |
| 2754 | if (instruction->IsRem()) { |
| 2755 | __ movl(eax, num); |
| 2756 | __ imull(edx, Immediate(imm)); |
| 2757 | __ subl(eax, edx); |
| 2758 | __ movl(edx, eax); |
| 2759 | } else { |
| 2760 | __ movl(eax, edx); |
| 2761 | } |
| 2762 | __ Bind(&end); |
| 2763 | } |
| 2764 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2765 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2766 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2767 | |
| 2768 | LocationSummary* locations = instruction->GetLocations(); |
| 2769 | Location out = locations->Out(); |
| 2770 | Location first = locations->InAt(0); |
| 2771 | Location second = locations->InAt(1); |
| 2772 | bool is_div = instruction->IsDiv(); |
| 2773 | |
| 2774 | switch (instruction->GetResultType()) { |
| 2775 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2776 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2777 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2778 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2779 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2780 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2781 | |
| 2782 | if (imm == 0) { |
| 2783 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2784 | } else if (imm == 1 || imm == -1) { |
| 2785 | DivRemOneOrMinusOne(instruction); |
| 2786 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2787 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2788 | } else { |
| 2789 | DCHECK(imm <= -2 || imm >= 2); |
| 2790 | GenerateDivRemWithAnyConstant(instruction); |
| 2791 | } |
| 2792 | } else { |
| 2793 | SlowPathCodeX86* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2794 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2795 | is_div); |
| 2796 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2797 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2798 | Register second_reg = second.AsRegister<Register>(); |
| 2799 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2800 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2801 | // it's safe to just use negl instead of more complex comparisons. |
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 | __ cmpl(second_reg, Immediate(-1)); |
| 2804 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2805 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2806 | // edx:eax <- sign-extended of eax |
| 2807 | __ cdq(); |
| 2808 | // eax = quotient, edx = remainder |
| 2809 | __ idivl(second_reg); |
| 2810 | __ Bind(slow_path->GetExitLabel()); |
| 2811 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2812 | break; |
| 2813 | } |
| 2814 | |
| 2815 | case Primitive::kPrimLong: { |
| 2816 | InvokeRuntimeCallingConvention calling_convention; |
| 2817 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2818 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2819 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2820 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2821 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2822 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2823 | |
| 2824 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2825 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2826 | instruction, |
| 2827 | instruction->GetDexPc(), |
| 2828 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2829 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2830 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 2831 | instruction, |
| 2832 | instruction->GetDexPc(), |
| 2833 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2834 | } |
| 2835 | uint32_t dex_pc = is_div |
| 2836 | ? instruction->AsDiv()->GetDexPc() |
| 2837 | : instruction->AsRem()->GetDexPc(); |
| 2838 | codegen_->RecordPcInfo(instruction, dex_pc); |
| 2839 | |
| 2840 | break; |
| 2841 | } |
| 2842 | |
| 2843 | default: |
| 2844 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 2845 | } |
| 2846 | } |
| 2847 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2848 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2849 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2850 | ? LocationSummary::kCall |
| 2851 | : LocationSummary::kNoCall; |
| 2852 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2853 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2854 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2855 | case Primitive::kPrimInt: { |
| 2856 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2857 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2858 | locations->SetOut(Location::SameAsFirstInput()); |
| 2859 | // Intel uses edx:eax as the dividend. |
| 2860 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2861 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2862 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 2863 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2864 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2865 | locations->AddTemp(Location::RequiresRegister()); |
| 2866 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2867 | break; |
| 2868 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2869 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2870 | InvokeRuntimeCallingConvention calling_convention; |
| 2871 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2872 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2873 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2874 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2875 | // Runtime helper puts the result in EAX, EDX. |
| 2876 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2877 | break; |
| 2878 | } |
| 2879 | case Primitive::kPrimFloat: |
| 2880 | case Primitive::kPrimDouble: { |
| 2881 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2882 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2883 | locations->SetOut(Location::SameAsFirstInput()); |
| 2884 | break; |
| 2885 | } |
| 2886 | |
| 2887 | default: |
| 2888 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2889 | } |
| 2890 | } |
| 2891 | |
| 2892 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 2893 | LocationSummary* locations = div->GetLocations(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2894 | Location out = locations->Out(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2895 | Location first = locations->InAt(0); |
| 2896 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2897 | |
| 2898 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2899 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2900 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2901 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2902 | break; |
| 2903 | } |
| 2904 | |
| 2905 | case Primitive::kPrimFloat: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2906 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2907 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2908 | break; |
| 2909 | } |
| 2910 | |
| 2911 | case Primitive::kPrimDouble: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2912 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2913 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2914 | break; |
| 2915 | } |
| 2916 | |
| 2917 | default: |
| 2918 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2919 | } |
| 2920 | } |
| 2921 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2922 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2923 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2924 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2925 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 2926 | ? LocationSummary::kCall |
| 2927 | : LocationSummary::kNoCall; |
| 2928 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2929 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2930 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2931 | case Primitive::kPrimInt: { |
| 2932 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2933 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2934 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2935 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2936 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 2937 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2938 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2939 | locations->AddTemp(Location::RequiresRegister()); |
| 2940 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2941 | break; |
| 2942 | } |
| 2943 | case Primitive::kPrimLong: { |
| 2944 | InvokeRuntimeCallingConvention calling_convention; |
| 2945 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2946 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2947 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2948 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2949 | // Runtime helper puts the result in EAX, EDX. |
| 2950 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2951 | break; |
| 2952 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2953 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2954 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2955 | locations->SetInAt(0, Location::Any()); |
| 2956 | locations->SetInAt(1, Location::Any()); |
| 2957 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2958 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2959 | break; |
| 2960 | } |
| 2961 | |
| 2962 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2963 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 2968 | Primitive::Type type = rem->GetResultType(); |
| 2969 | switch (type) { |
| 2970 | case Primitive::kPrimInt: |
| 2971 | case Primitive::kPrimLong: { |
| 2972 | GenerateDivRemIntegral(rem); |
| 2973 | break; |
| 2974 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2975 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2976 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2977 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2978 | break; |
| 2979 | } |
| 2980 | default: |
| 2981 | LOG(FATAL) << "Unexpected rem type " << type; |
| 2982 | } |
| 2983 | } |
| 2984 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2985 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2986 | LocationSummary* locations = |
| 2987 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2988 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 2989 | case Primitive::kPrimByte: |
| 2990 | case Primitive::kPrimChar: |
| 2991 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2992 | case Primitive::kPrimInt: { |
| 2993 | locations->SetInAt(0, Location::Any()); |
| 2994 | break; |
| 2995 | } |
| 2996 | case Primitive::kPrimLong: { |
| 2997 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2998 | if (!instruction->IsConstant()) { |
| 2999 | locations->AddTemp(Location::RequiresRegister()); |
| 3000 | } |
| 3001 | break; |
| 3002 | } |
| 3003 | default: |
| 3004 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3005 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3006 | if (instruction->HasUses()) { |
| 3007 | locations->SetOut(Location::SameAsFirstInput()); |
| 3008 | } |
| 3009 | } |
| 3010 | |
| 3011 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3012 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 3013 | codegen_->AddSlowPath(slow_path); |
| 3014 | |
| 3015 | LocationSummary* locations = instruction->GetLocations(); |
| 3016 | Location value = locations->InAt(0); |
| 3017 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3018 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3019 | case Primitive::kPrimByte: |
| 3020 | case Primitive::kPrimChar: |
| 3021 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3022 | case Primitive::kPrimInt: { |
| 3023 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3024 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3025 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3026 | } else if (value.IsStackSlot()) { |
| 3027 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3028 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3029 | } else { |
| 3030 | DCHECK(value.IsConstant()) << value; |
| 3031 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3032 | __ jmp(slow_path->GetEntryLabel()); |
| 3033 | } |
| 3034 | } |
| 3035 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3036 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3037 | case Primitive::kPrimLong: { |
| 3038 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3039 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3040 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3041 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3042 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3043 | } else { |
| 3044 | DCHECK(value.IsConstant()) << value; |
| 3045 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3046 | __ jmp(slow_path->GetEntryLabel()); |
| 3047 | } |
| 3048 | } |
| 3049 | break; |
| 3050 | } |
| 3051 | default: |
| 3052 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3053 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3054 | } |
| 3055 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3056 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3057 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3058 | |
| 3059 | LocationSummary* locations = |
| 3060 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3061 | |
| 3062 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3063 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3064 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3065 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3066 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3067 | // The shift count needs to be in CL or a constant. |
| 3068 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3069 | locations->SetOut(Location::SameAsFirstInput()); |
| 3070 | break; |
| 3071 | } |
| 3072 | default: |
| 3073 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3078 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3079 | |
| 3080 | LocationSummary* locations = op->GetLocations(); |
| 3081 | Location first = locations->InAt(0); |
| 3082 | Location second = locations->InAt(1); |
| 3083 | DCHECK(first.Equals(locations->Out())); |
| 3084 | |
| 3085 | switch (op->GetResultType()) { |
| 3086 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3087 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3088 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3089 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3090 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3091 | DCHECK_EQ(ECX, second_reg); |
| 3092 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3093 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3094 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3095 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3096 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3097 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3098 | } |
| 3099 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3100 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3101 | if (shift == 0) { |
| 3102 | return; |
| 3103 | } |
| 3104 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3105 | if (op->IsShl()) { |
| 3106 | __ shll(first_reg, imm); |
| 3107 | } else if (op->IsShr()) { |
| 3108 | __ sarl(first_reg, imm); |
| 3109 | } else { |
| 3110 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3111 | } |
| 3112 | } |
| 3113 | break; |
| 3114 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3115 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3116 | if (second.IsRegister()) { |
| 3117 | Register second_reg = second.AsRegister<Register>(); |
| 3118 | DCHECK_EQ(ECX, second_reg); |
| 3119 | if (op->IsShl()) { |
| 3120 | GenerateShlLong(first, second_reg); |
| 3121 | } else if (op->IsShr()) { |
| 3122 | GenerateShrLong(first, second_reg); |
| 3123 | } else { |
| 3124 | GenerateUShrLong(first, second_reg); |
| 3125 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3126 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3127 | // Shift by a constant. |
| 3128 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3129 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3130 | if (shift != 0) { |
| 3131 | if (op->IsShl()) { |
| 3132 | GenerateShlLong(first, shift); |
| 3133 | } else if (op->IsShr()) { |
| 3134 | GenerateShrLong(first, shift); |
| 3135 | } else { |
| 3136 | GenerateUShrLong(first, shift); |
| 3137 | } |
| 3138 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3139 | } |
| 3140 | break; |
| 3141 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3142 | default: |
| 3143 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3144 | } |
| 3145 | } |
| 3146 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3147 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3148 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3149 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3150 | if (shift == 1) { |
| 3151 | // This is just an addition. |
| 3152 | __ addl(low, low); |
| 3153 | __ adcl(high, high); |
| 3154 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3155 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3156 | codegen_->EmitParallelMoves( |
| 3157 | loc.ToLow(), |
| 3158 | loc.ToHigh(), |
| 3159 | Primitive::kPrimInt, |
| 3160 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3161 | loc.ToLow(), |
| 3162 | Primitive::kPrimInt); |
| 3163 | } else if (shift > 32) { |
| 3164 | // Low part becomes 0. High part is low part << (shift-32). |
| 3165 | __ movl(high, low); |
| 3166 | __ shll(high, Immediate(shift - 32)); |
| 3167 | __ xorl(low, low); |
| 3168 | } else { |
| 3169 | // Between 1 and 31. |
| 3170 | __ shld(high, low, Immediate(shift)); |
| 3171 | __ shll(low, Immediate(shift)); |
| 3172 | } |
| 3173 | } |
| 3174 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3175 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| 3176 | Label done; |
| 3177 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3178 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3179 | __ testl(shifter, Immediate(32)); |
| 3180 | __ j(kEqual, &done); |
| 3181 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3182 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3183 | __ Bind(&done); |
| 3184 | } |
| 3185 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3186 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3187 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3188 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3189 | if (shift == 32) { |
| 3190 | // Need to copy the sign. |
| 3191 | DCHECK_NE(low, high); |
| 3192 | __ movl(low, high); |
| 3193 | __ sarl(high, Immediate(31)); |
| 3194 | } else if (shift > 32) { |
| 3195 | DCHECK_NE(low, high); |
| 3196 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3197 | __ movl(low, high); |
| 3198 | __ sarl(high, Immediate(31)); |
| 3199 | __ sarl(low, Immediate(shift - 32)); |
| 3200 | } else { |
| 3201 | // Between 1 and 31. |
| 3202 | __ shrd(low, high, Immediate(shift)); |
| 3203 | __ sarl(high, Immediate(shift)); |
| 3204 | } |
| 3205 | } |
| 3206 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3207 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| 3208 | Label done; |
| 3209 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3210 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3211 | __ testl(shifter, Immediate(32)); |
| 3212 | __ j(kEqual, &done); |
| 3213 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3214 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3215 | __ Bind(&done); |
| 3216 | } |
| 3217 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3218 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3219 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3220 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3221 | if (shift == 32) { |
| 3222 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3223 | codegen_->EmitParallelMoves( |
| 3224 | loc.ToHigh(), |
| 3225 | loc.ToLow(), |
| 3226 | Primitive::kPrimInt, |
| 3227 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3228 | loc.ToHigh(), |
| 3229 | Primitive::kPrimInt); |
| 3230 | } else if (shift > 32) { |
| 3231 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3232 | __ movl(low, high); |
| 3233 | __ shrl(low, Immediate(shift - 32)); |
| 3234 | __ xorl(high, high); |
| 3235 | } else { |
| 3236 | // Between 1 and 31. |
| 3237 | __ shrd(low, high, Immediate(shift)); |
| 3238 | __ shrl(high, Immediate(shift)); |
| 3239 | } |
| 3240 | } |
| 3241 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3242 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| 3243 | Label done; |
| 3244 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3245 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3246 | __ testl(shifter, Immediate(32)); |
| 3247 | __ j(kEqual, &done); |
| 3248 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3249 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3250 | __ Bind(&done); |
| 3251 | } |
| 3252 | |
| 3253 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3254 | HandleShift(shl); |
| 3255 | } |
| 3256 | |
| 3257 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3258 | HandleShift(shl); |
| 3259 | } |
| 3260 | |
| 3261 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3262 | HandleShift(shr); |
| 3263 | } |
| 3264 | |
| 3265 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3266 | HandleShift(shr); |
| 3267 | } |
| 3268 | |
| 3269 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3270 | HandleShift(ushr); |
| 3271 | } |
| 3272 | |
| 3273 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3274 | HandleShift(ushr); |
| 3275 | } |
| 3276 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3277 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3278 | LocationSummary* locations = |
| 3279 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3280 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3281 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3282 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3283 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 3287 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3288 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3289 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3290 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3291 | codegen_->InvokeRuntime( |
| 3292 | Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint())), |
| 3293 | instruction, |
| 3294 | instruction->GetDexPc(), |
| 3295 | nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3296 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3297 | } |
| 3298 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3299 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3300 | LocationSummary* locations = |
| 3301 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3302 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3303 | InvokeRuntimeCallingConvention calling_convention; |
| 3304 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3305 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3306 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3310 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3311 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 3312 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3313 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3314 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3315 | codegen_->InvokeRuntime( |
| 3316 | Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint())), |
| 3317 | instruction, |
| 3318 | instruction->GetDexPc(), |
| 3319 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3320 | DCHECK(!codegen_->IsLeafMethod()); |
| 3321 | } |
| 3322 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3323 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3324 | LocationSummary* locations = |
| 3325 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3326 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3327 | if (location.IsStackSlot()) { |
| 3328 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3329 | } else if (location.IsDoubleStackSlot()) { |
| 3330 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3331 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3332 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3333 | } |
| 3334 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3335 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3336 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3337 | } |
| 3338 | |
| 3339 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3340 | LocationSummary* locations = |
| 3341 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3342 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3343 | } |
| 3344 | |
| 3345 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3346 | } |
| 3347 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3348 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3349 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3350 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3352 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3353 | } |
| 3354 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3355 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3356 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3357 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3358 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3359 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3360 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3361 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3362 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3363 | break; |
| 3364 | |
| 3365 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3366 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3367 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3368 | break; |
| 3369 | |
| 3370 | default: |
| 3371 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3372 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3373 | } |
| 3374 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3375 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3376 | LocationSummary* locations = |
| 3377 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3378 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3379 | locations->SetOut(Location::SameAsFirstInput()); |
| 3380 | } |
| 3381 | |
| 3382 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3383 | LocationSummary* locations = bool_not->GetLocations(); |
| 3384 | Location in = locations->InAt(0); |
| 3385 | Location out = locations->Out(); |
| 3386 | DCHECK(in.Equals(out)); |
| 3387 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3388 | } |
| 3389 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3390 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3391 | LocationSummary* locations = |
| 3392 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3393 | switch (compare->InputAt(0)->GetType()) { |
| 3394 | case Primitive::kPrimLong: { |
| 3395 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3396 | locations->SetInAt(1, Location::Any()); |
| 3397 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3398 | break; |
| 3399 | } |
| 3400 | case Primitive::kPrimFloat: |
| 3401 | case Primitive::kPrimDouble: { |
| 3402 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3403 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3404 | locations->SetOut(Location::RequiresRegister()); |
| 3405 | break; |
| 3406 | } |
| 3407 | default: |
| 3408 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3409 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3413 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3414 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3415 | Location left = locations->InAt(0); |
| 3416 | Location right = locations->InAt(1); |
| 3417 | |
| 3418 | Label less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3419 | switch (compare->InputAt(0)->GetType()) { |
| 3420 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3421 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 3422 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 3423 | int32_t val_low = 0; |
| 3424 | int32_t val_high = 0; |
| 3425 | bool right_is_const = false; |
| 3426 | |
| 3427 | if (right.IsConstant()) { |
| 3428 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 3429 | right_is_const = true; |
| 3430 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 3431 | val_low = Low32Bits(val); |
| 3432 | val_high = High32Bits(val); |
| 3433 | } |
| 3434 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3435 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3436 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3437 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3438 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3439 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3440 | DCHECK(right_is_const) << right; |
| 3441 | if (val_high == 0) { |
| 3442 | __ testl(left_high, left_high); |
| 3443 | } else { |
| 3444 | __ cmpl(left_high, Immediate(val_high)); |
| 3445 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3446 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3447 | __ j(kLess, &less); // Signed compare. |
| 3448 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3449 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3450 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3451 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3452 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3453 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3454 | DCHECK(right_is_const) << right; |
| 3455 | if (val_low == 0) { |
| 3456 | __ testl(left_low, left_low); |
| 3457 | } else { |
| 3458 | __ cmpl(left_low, Immediate(val_low)); |
| 3459 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3460 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3461 | break; |
| 3462 | } |
| 3463 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3464 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3465 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3466 | break; |
| 3467 | } |
| 3468 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3469 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3470 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3471 | break; |
| 3472 | } |
| 3473 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3474 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3475 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3476 | __ movl(out, Immediate(0)); |
| 3477 | __ j(kEqual, &done); |
| 3478 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3479 | |
| 3480 | __ Bind(&greater); |
| 3481 | __ movl(out, Immediate(1)); |
| 3482 | __ jmp(&done); |
| 3483 | |
| 3484 | __ Bind(&less); |
| 3485 | __ movl(out, Immediate(-1)); |
| 3486 | |
| 3487 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3488 | } |
| 3489 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3490 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3491 | LocationSummary* locations = |
| 3492 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3493 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3494 | locations->SetInAt(i, Location::Any()); |
| 3495 | } |
| 3496 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3500 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3501 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3502 | } |
| 3503 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3504 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3505 | /* |
| 3506 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3507 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3508 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3509 | */ |
| 3510 | switch (kind) { |
| 3511 | case MemBarrierKind::kAnyAny: { |
| 3512 | __ mfence(); |
| 3513 | break; |
| 3514 | } |
| 3515 | case MemBarrierKind::kAnyStore: |
| 3516 | case MemBarrierKind::kLoadAny: |
| 3517 | case MemBarrierKind::kStoreStore: { |
| 3518 | // nop |
| 3519 | break; |
| 3520 | } |
| 3521 | default: |
| 3522 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3523 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3524 | } |
| 3525 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3526 | |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 3527 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 3528 | switch (invoke->GetMethodLoadKind()) { |
| 3529 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3530 | // temp = thread->string_init_entrypoint |
| 3531 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 3532 | break; |
| 3533 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 3534 | // Nothing to do. |
| 3535 | break; |
| 3536 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3537 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 3538 | break; |
| 3539 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3540 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 3541 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3542 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 3543 | break; |
| 3544 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 3545 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 3546 | FALLTHROUGH_INTENDED; |
| 3547 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 3548 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3549 | Register method_reg; |
| 3550 | Register reg = temp.AsRegister<Register>(); |
| 3551 | if (current_method.IsRegister()) { |
| 3552 | method_reg = current_method.AsRegister<Register>(); |
| 3553 | } else { |
| 3554 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 3555 | DCHECK(!current_method.IsValid()); |
| 3556 | method_reg = reg; |
| 3557 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 3558 | } |
| 3559 | // temp = temp->dex_cache_resolved_methods_; |
| 3560 | __ movl(reg, Address(method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 3561 | // temp = temp[index_in_cache] |
| 3562 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3563 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 3564 | break; |
Nicolas Geoffray | c345f14 | 2015-06-04 17:17:32 +0000 | [diff] [blame] | 3565 | } |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 3566 | } |
| 3567 | |
| 3568 | switch (invoke->GetCodePtrLocation()) { |
| 3569 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3570 | __ call(GetFrameEntryLabel()); |
| 3571 | break; |
| 3572 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3573 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3574 | Label* label = &relative_call_patches_.back().label; |
| 3575 | __ call(label); // Bind to the patch label, override at link time. |
| 3576 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 3577 | break; |
| 3578 | } |
| 3579 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3580 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3581 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 3582 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 3583 | FALLTHROUGH_INTENDED; |
| 3584 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3585 | // (temp + offset_of_quick_compiled_code)() |
| 3586 | __ call(Address(temp.AsRegister<Register>(), ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3587 | kX86WordSize).Int32Value())); |
| 3588 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3592 | } |
| 3593 | |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame^] | 3594 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3595 | DCHECK(linker_patches->empty()); |
| 3596 | linker_patches->reserve(method_patches_.size() + relative_call_patches_.size()); |
| 3597 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 3598 | // The label points to the end of the "movl" insn but the literal offset for method |
| 3599 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3600 | uint32_t literal_offset = info.label.Position() - 4; |
| 3601 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 3602 | info.target_method.dex_file, |
| 3603 | info.target_method.dex_method_index)); |
| 3604 | } |
| 3605 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 3606 | // The label points to the end of the "call" insn but the literal offset for method |
| 3607 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3608 | uint32_t literal_offset = info.label.Position() - 4; |
| 3609 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 3610 | info.target_method.dex_file, |
| 3611 | info.target_method.dex_method_index)); |
| 3612 | } |
| 3613 | } |
| 3614 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3615 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 3616 | Register card, |
| 3617 | Register object, |
| 3618 | Register value, |
| 3619 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3620 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3621 | if (value_can_be_null) { |
| 3622 | __ testl(value, value); |
| 3623 | __ j(kEqual, &is_null); |
| 3624 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3625 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3626 | __ movl(temp, object); |
| 3627 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3628 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3629 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3630 | if (value_can_be_null) { |
| 3631 | __ Bind(&is_null); |
| 3632 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3633 | } |
| 3634 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3635 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3636 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3637 | LocationSummary* locations = |
| 3638 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3639 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3640 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3641 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3642 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3643 | } else { |
| 3644 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3645 | // the object's location. |
| 3646 | locations->SetOut(Location::RequiresRegister(), |
| 3647 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3648 | : Location::kNoOutputOverlap); |
| 3649 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3650 | |
| 3651 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3652 | // Long values can be loaded atomically into an XMM using movsd. |
| 3653 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3654 | // and then copy the XMM into the output 32bits at a time). |
| 3655 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3656 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3657 | } |
| 3658 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3659 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3660 | const FieldInfo& field_info) { |
| 3661 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3662 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3663 | LocationSummary* locations = instruction->GetLocations(); |
| 3664 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3665 | Location out = locations->Out(); |
| 3666 | bool is_volatile = field_info.IsVolatile(); |
| 3667 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3668 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3669 | |
| 3670 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3671 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3672 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3673 | break; |
| 3674 | } |
| 3675 | |
| 3676 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3677 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3678 | break; |
| 3679 | } |
| 3680 | |
| 3681 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3682 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3683 | break; |
| 3684 | } |
| 3685 | |
| 3686 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3687 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3688 | break; |
| 3689 | } |
| 3690 | |
| 3691 | case Primitive::kPrimInt: |
| 3692 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3693 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3694 | break; |
| 3695 | } |
| 3696 | |
| 3697 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3698 | if (is_volatile) { |
| 3699 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3700 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3701 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3702 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3703 | __ psrlq(temp, Immediate(32)); |
| 3704 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3705 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3706 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3707 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3708 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3709 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3710 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3711 | break; |
| 3712 | } |
| 3713 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3714 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3715 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3716 | break; |
| 3717 | } |
| 3718 | |
| 3719 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3720 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3721 | break; |
| 3722 | } |
| 3723 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3724 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3725 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3726 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3727 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3728 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3729 | // Longs are handled in the switch. |
| 3730 | if (field_type != Primitive::kPrimLong) { |
| 3731 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3732 | } |
| 3733 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3734 | if (is_volatile) { |
| 3735 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3736 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3737 | |
| 3738 | if (field_type == Primitive::kPrimNot) { |
| 3739 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3740 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3744 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3745 | |
| 3746 | LocationSummary* locations = |
| 3747 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3748 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3749 | bool is_volatile = field_info.IsVolatile(); |
| 3750 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3751 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3752 | || (field_type == Primitive::kPrimByte); |
| 3753 | |
| 3754 | // The register allocator does not support multiple |
| 3755 | // inputs that die at entry with one in a specific register. |
| 3756 | if (is_byte_type) { |
| 3757 | // Ensure the value is in a byte register. |
| 3758 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3759 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3760 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3761 | } else { |
| 3762 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3763 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3764 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3765 | // Temporary registers for the write barrier. |
| 3766 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3767 | // Ensure the card is in a byte register. |
| 3768 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3769 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3770 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3771 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3772 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3773 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3774 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3775 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3776 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3781 | const FieldInfo& field_info, |
| 3782 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3783 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3784 | |
| 3785 | LocationSummary* locations = instruction->GetLocations(); |
| 3786 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3787 | Location value = locations->InAt(1); |
| 3788 | bool is_volatile = field_info.IsVolatile(); |
| 3789 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3790 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3791 | bool needs_write_barrier = |
| 3792 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3793 | |
| 3794 | if (is_volatile) { |
| 3795 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3796 | } |
| 3797 | |
| 3798 | switch (field_type) { |
| 3799 | case Primitive::kPrimBoolean: |
| 3800 | case Primitive::kPrimByte: { |
| 3801 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 3802 | break; |
| 3803 | } |
| 3804 | |
| 3805 | case Primitive::kPrimShort: |
| 3806 | case Primitive::kPrimChar: { |
| 3807 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 3808 | break; |
| 3809 | } |
| 3810 | |
| 3811 | case Primitive::kPrimInt: |
| 3812 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3813 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3814 | // Note that in the case where `value` is a null reference, |
| 3815 | // we do not enter this block, as the reference does not |
| 3816 | // need poisoning. |
| 3817 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3818 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3819 | __ movl(temp, value.AsRegister<Register>()); |
| 3820 | __ PoisonHeapReference(temp); |
| 3821 | __ movl(Address(base, offset), temp); |
| 3822 | } else { |
| 3823 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 3824 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3825 | break; |
| 3826 | } |
| 3827 | |
| 3828 | case Primitive::kPrimLong: { |
| 3829 | if (is_volatile) { |
| 3830 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3831 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 3832 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 3833 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 3834 | __ punpckldq(temp1, temp2); |
| 3835 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3836 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3837 | } else { |
| 3838 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3839 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3840 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 3841 | } |
| 3842 | break; |
| 3843 | } |
| 3844 | |
| 3845 | case Primitive::kPrimFloat: { |
| 3846 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3847 | break; |
| 3848 | } |
| 3849 | |
| 3850 | case Primitive::kPrimDouble: { |
| 3851 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3852 | break; |
| 3853 | } |
| 3854 | |
| 3855 | case Primitive::kPrimVoid: |
| 3856 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3857 | UNREACHABLE(); |
| 3858 | } |
| 3859 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3860 | // Longs are handled in the switch. |
| 3861 | if (field_type != Primitive::kPrimLong) { |
| 3862 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3863 | } |
| 3864 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3865 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3866 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3867 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3868 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3871 | if (is_volatile) { |
| 3872 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3873 | } |
| 3874 | } |
| 3875 | |
| 3876 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3877 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3878 | } |
| 3879 | |
| 3880 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3881 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3882 | } |
| 3883 | |
| 3884 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3885 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3886 | } |
| 3887 | |
| 3888 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3889 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3893 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3894 | } |
| 3895 | |
| 3896 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3897 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3901 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3902 | } |
| 3903 | |
| 3904 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3905 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3909 | LocationSummary* locations = |
| 3910 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3911 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3912 | ? Location::RequiresRegister() |
| 3913 | : Location::Any(); |
| 3914 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3915 | if (instruction->HasUses()) { |
| 3916 | locations->SetOut(Location::SameAsFirstInput()); |
| 3917 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3918 | } |
| 3919 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3920 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3921 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3922 | return; |
| 3923 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3924 | LocationSummary* locations = instruction->GetLocations(); |
| 3925 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3926 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3927 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 3928 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3929 | } |
| 3930 | |
| 3931 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3932 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3933 | codegen_->AddSlowPath(slow_path); |
| 3934 | |
| 3935 | LocationSummary* locations = instruction->GetLocations(); |
| 3936 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3937 | |
| 3938 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 3939 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3940 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3941 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3942 | } else { |
| 3943 | DCHECK(obj.IsConstant()) << obj; |
| 3944 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 3945 | __ jmp(slow_path->GetEntryLabel()); |
| 3946 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3947 | } |
| 3948 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3949 | } |
| 3950 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3951 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| 3952 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3953 | GenerateImplicitNullCheck(instruction); |
| 3954 | } else { |
| 3955 | GenerateExplicitNullCheck(instruction); |
| 3956 | } |
| 3957 | } |
| 3958 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3959 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3960 | LocationSummary* locations = |
| 3961 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3962 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3963 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3964 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3965 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3966 | } else { |
| 3967 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3968 | // the array's location. |
| 3969 | locations->SetOut(Location::RequiresRegister(), |
| 3970 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3971 | : Location::kNoOutputOverlap); |
| 3972 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 3976 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3977 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3978 | Location index = locations->InAt(1); |
| 3979 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3980 | Primitive::Type type = instruction->GetType(); |
| 3981 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3982 | case Primitive::kPrimBoolean: { |
| 3983 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3984 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3985 | if (index.IsConstant()) { |
| 3986 | __ movzxb(out, Address(obj, |
| 3987 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3988 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3989 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3990 | } |
| 3991 | break; |
| 3992 | } |
| 3993 | |
| 3994 | case Primitive::kPrimByte: { |
| 3995 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3996 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3997 | if (index.IsConstant()) { |
| 3998 | __ movsxb(out, Address(obj, |
| 3999 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4000 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4001 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4002 | } |
| 4003 | break; |
| 4004 | } |
| 4005 | |
| 4006 | case Primitive::kPrimShort: { |
| 4007 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4008 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4009 | if (index.IsConstant()) { |
| 4010 | __ movsxw(out, Address(obj, |
| 4011 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4012 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4013 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4014 | } |
| 4015 | break; |
| 4016 | } |
| 4017 | |
| 4018 | case Primitive::kPrimChar: { |
| 4019 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4020 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4021 | if (index.IsConstant()) { |
| 4022 | __ movzxw(out, Address(obj, |
| 4023 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4024 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4025 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4026 | } |
| 4027 | break; |
| 4028 | } |
| 4029 | |
| 4030 | case Primitive::kPrimInt: |
| 4031 | case Primitive::kPrimNot: { |
| 4032 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4033 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4034 | if (index.IsConstant()) { |
| 4035 | __ movl(out, Address(obj, |
| 4036 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4037 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4038 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4039 | } |
| 4040 | break; |
| 4041 | } |
| 4042 | |
| 4043 | case Primitive::kPrimLong: { |
| 4044 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4045 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4046 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4047 | if (index.IsConstant()) { |
| 4048 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4049 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4050 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4051 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4052 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4053 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4054 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4055 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4056 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4057 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4058 | } |
| 4059 | break; |
| 4060 | } |
| 4061 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4062 | case Primitive::kPrimFloat: { |
| 4063 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4064 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4065 | if (index.IsConstant()) { |
| 4066 | __ movss(out, Address(obj, |
| 4067 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4068 | } else { |
| 4069 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4070 | } |
| 4071 | break; |
| 4072 | } |
| 4073 | |
| 4074 | case Primitive::kPrimDouble: { |
| 4075 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4076 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4077 | if (index.IsConstant()) { |
| 4078 | __ movsd(out, Address(obj, |
| 4079 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4080 | } else { |
| 4081 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 4082 | } |
| 4083 | break; |
| 4084 | } |
| 4085 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4086 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4087 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4088 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4089 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4090 | |
| 4091 | if (type != Primitive::kPrimLong) { |
| 4092 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4093 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4094 | |
| 4095 | if (type == Primitive::kPrimNot) { |
| 4096 | Register out = locations->Out().AsRegister<Register>(); |
| 4097 | __ MaybeUnpoisonHeapReference(out); |
| 4098 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4102 | // This location builder might end up asking to up to four registers, which is |
| 4103 | // not currently possible for baseline. The situation in which we need four |
| 4104 | // registers cannot be met by baseline though, because it has not run any |
| 4105 | // optimization. |
| 4106 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4107 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4108 | bool needs_write_barrier = |
| 4109 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 4110 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4111 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4112 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4113 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4114 | instruction, |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4115 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4116 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4117 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4118 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4119 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4120 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4121 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4122 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4123 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4124 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4125 | // 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] | 4126 | // In case of a byte operation, the register allocator does not support multiple |
| 4127 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4128 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4129 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4130 | if (is_byte_type) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4131 | // Ensure the value is in a byte register. |
| 4132 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4133 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 4134 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4135 | } else { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4136 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4137 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4138 | if (needs_write_barrier) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4139 | // Temporary registers for the write barrier. |
| 4140 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4141 | // Ensure the card is in a byte register. |
| 4142 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4143 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4144 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4148 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4149 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4150 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4151 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4152 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4153 | bool needs_runtime_call = locations->WillCall(); |
| 4154 | bool needs_write_barrier = |
| 4155 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4156 | |
| 4157 | switch (value_type) { |
| 4158 | case Primitive::kPrimBoolean: |
| 4159 | case Primitive::kPrimByte: { |
| 4160 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4161 | if (index.IsConstant()) { |
| 4162 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4163 | if (value.IsRegister()) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4164 | __ movb(Address(obj, offset), value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4165 | } else { |
| 4166 | __ movb(Address(obj, offset), |
| 4167 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4168 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4169 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4170 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4171 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4172 | value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4173 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4174 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4175 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4176 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4177 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4178 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4179 | break; |
| 4180 | } |
| 4181 | |
| 4182 | case Primitive::kPrimShort: |
| 4183 | case Primitive::kPrimChar: { |
| 4184 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4185 | if (index.IsConstant()) { |
| 4186 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4187 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4188 | __ movw(Address(obj, offset), value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4189 | } else { |
| 4190 | __ movw(Address(obj, offset), |
| 4191 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4192 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4193 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4194 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4195 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
| 4196 | value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4197 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4198 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4199 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4200 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4201 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4202 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4203 | break; |
| 4204 | } |
| 4205 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4206 | case Primitive::kPrimInt: |
| 4207 | case Primitive::kPrimNot: { |
| 4208 | if (!needs_runtime_call) { |
| 4209 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4210 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4211 | size_t offset = |
| 4212 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4213 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4214 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4215 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4216 | __ movl(temp, value.AsRegister<Register>()); |
| 4217 | __ PoisonHeapReference(temp); |
| 4218 | __ movl(Address(obj, offset), temp); |
| 4219 | } else { |
| 4220 | __ movl(Address(obj, offset), value.AsRegister<Register>()); |
| 4221 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4222 | } else { |
| 4223 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4224 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4225 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4226 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4227 | // Note: if heap poisoning is enabled, no need to poison |
| 4228 | // (negate) `v` if it is a reference, as it would be null. |
| 4229 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4230 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4231 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4232 | DCHECK(index.IsRegister()) << index; |
| 4233 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4234 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4235 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4236 | __ movl(temp, value.AsRegister<Register>()); |
| 4237 | __ PoisonHeapReference(temp); |
| 4238 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), temp); |
| 4239 | } else { |
| 4240 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4241 | value.AsRegister<Register>()); |
| 4242 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4243 | } else { |
| 4244 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4245 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4246 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4247 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4248 | // Note: if heap poisoning is enabled, no need to poison |
| 4249 | // (negate) `v` if it is a reference, as it would be null. |
| 4250 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4251 | } |
| 4252 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4253 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4254 | |
| 4255 | if (needs_write_barrier) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4256 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4257 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4258 | codegen_->MarkGCCard( |
| 4259 | temp, card, obj, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4260 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4261 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4262 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4263 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4264 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4265 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4266 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4267 | instruction, |
| 4268 | instruction->GetDexPc(), |
| 4269 | nullptr); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4270 | } |
| 4271 | break; |
| 4272 | } |
| 4273 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4274 | case Primitive::kPrimLong: { |
| 4275 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4276 | if (index.IsConstant()) { |
| 4277 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4278 | if (value.IsRegisterPair()) { |
| 4279 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4280 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4281 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4282 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4283 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4284 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4285 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4286 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4287 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 4288 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4289 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4290 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4291 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4292 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4293 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4294 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4295 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4296 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4297 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4298 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4299 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4300 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4301 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4302 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4303 | Immediate(High32Bits(val))); |
| 4304 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4305 | } |
| 4306 | break; |
| 4307 | } |
| 4308 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4309 | case Primitive::kPrimFloat: { |
| 4310 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4311 | DCHECK(value.IsFpuRegister()); |
| 4312 | if (index.IsConstant()) { |
| 4313 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4314 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4315 | } else { |
| 4316 | __ movss(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4317 | value.AsFpuRegister<XmmRegister>()); |
| 4318 | } |
| 4319 | break; |
| 4320 | } |
| 4321 | |
| 4322 | case Primitive::kPrimDouble: { |
| 4323 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4324 | DCHECK(value.IsFpuRegister()); |
| 4325 | if (index.IsConstant()) { |
| 4326 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4327 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4328 | } else { |
| 4329 | __ movsd(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
| 4330 | value.AsFpuRegister<XmmRegister>()); |
| 4331 | } |
| 4332 | break; |
| 4333 | } |
| 4334 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4335 | case Primitive::kPrimVoid: |
| 4336 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4337 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4338 | } |
| 4339 | } |
| 4340 | |
| 4341 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 4342 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4343 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4344 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 4348 | LocationSummary* locations = instruction->GetLocations(); |
| 4349 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4350 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4351 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4352 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4353 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4357 | LocationSummary* locations = |
| 4358 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4359 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4360 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4361 | if (instruction->HasUses()) { |
| 4362 | locations->SetOut(Location::SameAsFirstInput()); |
| 4363 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4367 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4368 | Location index_loc = locations->InAt(0); |
| 4369 | Location length_loc = locations->InAt(1); |
| 4370 | SlowPathCodeX86* slow_path = |
| 4371 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction, index_loc, length_loc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4372 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4373 | if (length_loc.IsConstant()) { |
| 4374 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4375 | if (index_loc.IsConstant()) { |
| 4376 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4377 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4378 | if (index < 0 || index >= length) { |
| 4379 | codegen_->AddSlowPath(slow_path); |
| 4380 | __ jmp(slow_path->GetEntryLabel()); |
| 4381 | } else { |
| 4382 | // Some optimization after BCE may have generated this, and we should not |
| 4383 | // generate a bounds check if it is a valid range. |
| 4384 | } |
| 4385 | return; |
| 4386 | } |
| 4387 | |
| 4388 | // We have to reverse the jump condition because the length is the constant. |
| 4389 | Register index_reg = index_loc.AsRegister<Register>(); |
| 4390 | __ cmpl(index_reg, Immediate(length)); |
| 4391 | codegen_->AddSlowPath(slow_path); |
| 4392 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4393 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4394 | Register length = length_loc.AsRegister<Register>(); |
| 4395 | if (index_loc.IsConstant()) { |
| 4396 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4397 | __ cmpl(length, Immediate(value)); |
| 4398 | } else { |
| 4399 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 4400 | } |
| 4401 | codegen_->AddSlowPath(slow_path); |
| 4402 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4403 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4404 | } |
| 4405 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4406 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 4407 | temp->SetLocations(nullptr); |
| 4408 | } |
| 4409 | |
| 4410 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 4411 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4412 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4413 | } |
| 4414 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4415 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4416 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4417 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4421 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4422 | } |
| 4423 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4424 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4425 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4426 | } |
| 4427 | |
| 4428 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4429 | HBasicBlock* block = instruction->GetBlock(); |
| 4430 | if (block->GetLoopInformation() != nullptr) { |
| 4431 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4432 | // The back edge will generate the suspend check. |
| 4433 | return; |
| 4434 | } |
| 4435 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4436 | // The goto will generate the suspend check. |
| 4437 | return; |
| 4438 | } |
| 4439 | GenerateSuspendCheck(instruction, nullptr); |
| 4440 | } |
| 4441 | |
| 4442 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4443 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4444 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4445 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 4446 | if (slow_path == nullptr) { |
| 4447 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 4448 | instruction->SetSlowPath(slow_path); |
| 4449 | codegen_->AddSlowPath(slow_path); |
| 4450 | if (successor != nullptr) { |
| 4451 | DCHECK(successor->IsLoopHeader()); |
| 4452 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4453 | } |
| 4454 | } else { |
| 4455 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4456 | } |
| 4457 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4458 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4459 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4460 | if (successor == nullptr) { |
| 4461 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4462 | __ Bind(slow_path->GetReturnLabel()); |
| 4463 | } else { |
| 4464 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4465 | __ jmp(slow_path->GetEntryLabel()); |
| 4466 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4467 | } |
| 4468 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4469 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 4470 | return codegen_->GetAssembler(); |
| 4471 | } |
| 4472 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4473 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4474 | ScratchRegisterScope ensure_scratch( |
| 4475 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4476 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4477 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4478 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4479 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4483 | ScratchRegisterScope ensure_scratch( |
| 4484 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4485 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4486 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4487 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4488 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 4489 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 4490 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 4494 | MoveOperands* move = moves_.Get(index); |
| 4495 | Location source = move->GetSource(); |
| 4496 | Location destination = move->GetDestination(); |
| 4497 | |
| 4498 | if (source.IsRegister()) { |
| 4499 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4500 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4501 | } else { |
| 4502 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4503 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4504 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4505 | } else if (source.IsFpuRegister()) { |
| 4506 | if (destination.IsFpuRegister()) { |
| 4507 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4508 | } else if (destination.IsStackSlot()) { |
| 4509 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4510 | } else { |
| 4511 | DCHECK(destination.IsDoubleStackSlot()); |
| 4512 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4513 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4514 | } else if (source.IsStackSlot()) { |
| 4515 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4516 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4517 | } else if (destination.IsFpuRegister()) { |
| 4518 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4519 | } else { |
| 4520 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4521 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4522 | } |
| 4523 | } else if (source.IsDoubleStackSlot()) { |
| 4524 | if (destination.IsFpuRegister()) { |
| 4525 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 4526 | } else { |
| 4527 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4528 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4529 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4530 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4531 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4532 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4533 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4534 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4535 | if (value == 0) { |
| 4536 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4537 | } else { |
| 4538 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 4539 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4540 | } else { |
| 4541 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4542 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4543 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4544 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4545 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4546 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4547 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4548 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4549 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4550 | if (value == 0) { |
| 4551 | // Easy handling of 0.0. |
| 4552 | __ xorps(dest, dest); |
| 4553 | } else { |
| 4554 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4555 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4556 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4557 | __ movl(temp, Immediate(value)); |
| 4558 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4559 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4560 | } else { |
| 4561 | DCHECK(destination.IsStackSlot()) << destination; |
| 4562 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 4563 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4564 | } else if (constant->IsLongConstant()) { |
| 4565 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4566 | int32_t low_value = Low32Bits(value); |
| 4567 | int32_t high_value = High32Bits(value); |
| 4568 | Immediate low(low_value); |
| 4569 | Immediate high(high_value); |
| 4570 | if (destination.IsDoubleStackSlot()) { |
| 4571 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4572 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4573 | } else { |
| 4574 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 4575 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 4576 | } |
| 4577 | } else { |
| 4578 | DCHECK(constant->IsDoubleConstant()); |
| 4579 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4580 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4581 | int32_t low_value = Low32Bits(value); |
| 4582 | int32_t high_value = High32Bits(value); |
| 4583 | Immediate low(low_value); |
| 4584 | Immediate high(high_value); |
| 4585 | if (destination.IsFpuRegister()) { |
| 4586 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4587 | if (value == 0) { |
| 4588 | // Easy handling of 0.0. |
| 4589 | __ xorpd(dest, dest); |
| 4590 | } else { |
| 4591 | __ pushl(high); |
| 4592 | __ pushl(low); |
| 4593 | __ movsd(dest, Address(ESP, 0)); |
| 4594 | __ addl(ESP, Immediate(8)); |
| 4595 | } |
| 4596 | } else { |
| 4597 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4598 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4599 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4600 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4601 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4602 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4603 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4604 | } |
| 4605 | } |
| 4606 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4607 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4608 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4609 | ScratchRegisterScope ensure_scratch( |
| 4610 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4611 | |
| 4612 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4613 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4614 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4615 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4616 | } |
| 4617 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4618 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4619 | ScratchRegisterScope ensure_scratch( |
| 4620 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4621 | |
| 4622 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4623 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4624 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4625 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4626 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4627 | } |
| 4628 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4629 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4630 | ScratchRegisterScope ensure_scratch1( |
| 4631 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4632 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4633 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4634 | ScratchRegisterScope ensure_scratch2( |
| 4635 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4636 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4637 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4638 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4639 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4640 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4641 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4642 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 4646 | MoveOperands* move = moves_.Get(index); |
| 4647 | Location source = move->GetSource(); |
| 4648 | Location destination = move->GetDestination(); |
| 4649 | |
| 4650 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 4651 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 4652 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4653 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4654 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4655 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4656 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4657 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4658 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4659 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4660 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4661 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4662 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4663 | // Use XOR Swap algorithm to avoid a temporary. |
| 4664 | DCHECK_NE(source.reg(), destination.reg()); |
| 4665 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4666 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4667 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4668 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4669 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4670 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4671 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4672 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4673 | // Take advantage of the 16 bytes in the XMM register. |
| 4674 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4675 | Address stack(ESP, destination.GetStackIndex()); |
| 4676 | // Load the double into the high doubleword. |
| 4677 | __ movhpd(reg, stack); |
| 4678 | |
| 4679 | // Store the low double into the destination. |
| 4680 | __ movsd(stack, reg); |
| 4681 | |
| 4682 | // Move the high double to the low double. |
| 4683 | __ psrldq(reg, Immediate(8)); |
| 4684 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4685 | // Take advantage of the 16 bytes in the XMM register. |
| 4686 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4687 | Address stack(ESP, source.GetStackIndex()); |
| 4688 | // Load the double into the high doubleword. |
| 4689 | __ movhpd(reg, stack); |
| 4690 | |
| 4691 | // Store the low double into the destination. |
| 4692 | __ movsd(stack, reg); |
| 4693 | |
| 4694 | // Move the high double to the low double. |
| 4695 | __ psrldq(reg, Immediate(8)); |
| 4696 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4697 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4698 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4699 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4700 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4705 | __ pushl(static_cast<Register>(reg)); |
| 4706 | } |
| 4707 | |
| 4708 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4709 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4710 | } |
| 4711 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4712 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4713 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4714 | ? LocationSummary::kCallOnSlowPath |
| 4715 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4716 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4717 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4718 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4719 | locations->SetOut(Location::RequiresRegister()); |
| 4720 | } |
| 4721 | |
| 4722 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4723 | LocationSummary* locations = cls->GetLocations(); |
| 4724 | Register out = locations->Out().AsRegister<Register>(); |
| 4725 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4726 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4727 | DCHECK(!cls->CanCallRuntime()); |
| 4728 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4729 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4730 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4731 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4732 | __ movl(out, Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4733 | current_method, ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4734 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4735 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4736 | |
| 4737 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4738 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4739 | codegen_->AddSlowPath(slow_path); |
| 4740 | __ testl(out, out); |
| 4741 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4742 | if (cls->MustGenerateClinitCheck()) { |
| 4743 | GenerateClassInitializationCheck(slow_path, out); |
| 4744 | } else { |
| 4745 | __ Bind(slow_path->GetExitLabel()); |
| 4746 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4747 | } |
| 4748 | } |
| 4749 | |
| 4750 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 4751 | LocationSummary* locations = |
| 4752 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4753 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4754 | if (check->HasUses()) { |
| 4755 | locations->SetOut(Location::SameAsFirstInput()); |
| 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4760 | // We assume the class to not be null. |
| 4761 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4762 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4763 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4764 | GenerateClassInitializationCheck(slow_path, |
| 4765 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4766 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4767 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4768 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 4769 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4770 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4771 | Immediate(mirror::Class::kStatusInitialized)); |
| 4772 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4773 | __ Bind(slow_path->GetExitLabel()); |
| 4774 | // No need for memory fence, thanks to the X86 memory model. |
| 4775 | } |
| 4776 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4777 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 4778 | LocationSummary* locations = |
| 4779 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4780 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4781 | locations->SetOut(Location::RequiresRegister()); |
| 4782 | } |
| 4783 | |
| 4784 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 4785 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 4786 | codegen_->AddSlowPath(slow_path); |
| 4787 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4788 | LocationSummary* locations = load->GetLocations(); |
| 4789 | Register out = locations->Out().AsRegister<Register>(); |
| 4790 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4791 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4792 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4793 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4794 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4795 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4796 | __ testl(out, out); |
| 4797 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4798 | __ Bind(slow_path->GetExitLabel()); |
| 4799 | } |
| 4800 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4801 | static Address GetExceptionTlsAddress() { |
| 4802 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 4803 | } |
| 4804 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4805 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 4806 | LocationSummary* locations = |
| 4807 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4808 | locations->SetOut(Location::RequiresRegister()); |
| 4809 | } |
| 4810 | |
| 4811 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4812 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 4813 | } |
| 4814 | |
| 4815 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 4816 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4817 | } |
| 4818 | |
| 4819 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4820 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 4824 | LocationSummary* locations = |
| 4825 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4826 | InvokeRuntimeCallingConvention calling_convention; |
| 4827 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4828 | } |
| 4829 | |
| 4830 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4831 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4832 | instruction, |
| 4833 | instruction->GetDexPc(), |
| 4834 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4837 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4838 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4839 | ? LocationSummary::kNoCall |
| 4840 | : LocationSummary::kCallOnSlowPath; |
| 4841 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4842 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4843 | locations->SetInAt(1, Location::Any()); |
| 4844 | locations->SetOut(Location::RequiresRegister()); |
| 4845 | } |
| 4846 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4847 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4848 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4849 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4850 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4851 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4852 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4853 | Label done, zero; |
| 4854 | SlowPathCodeX86* slow_path = nullptr; |
| 4855 | |
| 4856 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4857 | // Avoid null check if we know obj is not null. |
| 4858 | if (instruction->MustDoNullCheck()) { |
| 4859 | __ testl(obj, obj); |
| 4860 | __ j(kEqual, &zero); |
| 4861 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4862 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4863 | __ movl(out, Address(obj, class_offset)); |
| 4864 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4865 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4866 | __ cmpl(out, cls.AsRegister<Register>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4867 | } else { |
| 4868 | DCHECK(cls.IsStackSlot()) << cls; |
| 4869 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 4870 | } |
| 4871 | |
| 4872 | if (instruction->IsClassFinal()) { |
| 4873 | // Classes must be equal for the instanceof to succeed. |
| 4874 | __ j(kNotEqual, &zero); |
| 4875 | __ movl(out, Immediate(1)); |
| 4876 | __ jmp(&done); |
| 4877 | } else { |
| 4878 | // If the classes are not equal, we go into a slow path. |
| 4879 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4880 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4881 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4882 | codegen_->AddSlowPath(slow_path); |
| 4883 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4884 | __ movl(out, Immediate(1)); |
| 4885 | __ jmp(&done); |
| 4886 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4887 | |
| 4888 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4889 | __ Bind(&zero); |
| 4890 | __ movl(out, Immediate(0)); |
| 4891 | } |
| 4892 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4893 | if (slow_path != nullptr) { |
| 4894 | __ Bind(slow_path->GetExitLabel()); |
| 4895 | } |
| 4896 | __ Bind(&done); |
| 4897 | } |
| 4898 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4899 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| 4900 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4901 | instruction, LocationSummary::kCallOnSlowPath); |
| 4902 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4903 | locations->SetInAt(1, Location::Any()); |
| 4904 | locations->AddTemp(Location::RequiresRegister()); |
| 4905 | } |
| 4906 | |
| 4907 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 4908 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4909 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4910 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4911 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4912 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4913 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 4914 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 4915 | codegen_->AddSlowPath(slow_path); |
| 4916 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4917 | // Avoid null check if we know obj is not null. |
| 4918 | if (instruction->MustDoNullCheck()) { |
| 4919 | __ testl(obj, obj); |
| 4920 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4921 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4922 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4923 | __ movl(temp, Address(obj, class_offset)); |
| 4924 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4925 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4926 | __ cmpl(temp, cls.AsRegister<Register>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4927 | } else { |
| 4928 | DCHECK(cls.IsStackSlot()) << cls; |
| 4929 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 4930 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4931 | // The checkcast succeeds if the classes are equal (fast path). |
| 4932 | // 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] | 4933 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4934 | __ Bind(slow_path->GetExitLabel()); |
| 4935 | } |
| 4936 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4937 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4938 | LocationSummary* locations = |
| 4939 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4940 | InvokeRuntimeCallingConvention calling_convention; |
| 4941 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4942 | } |
| 4943 | |
| 4944 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4945 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 4946 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 4947 | instruction, |
| 4948 | instruction->GetDexPc(), |
| 4949 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4950 | } |
| 4951 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4952 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4953 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4954 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4955 | |
| 4956 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4957 | LocationSummary* locations = |
| 4958 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4959 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4960 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4961 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4962 | locations->SetInAt(1, Location::Any()); |
| 4963 | locations->SetOut(Location::SameAsFirstInput()); |
| 4964 | } |
| 4965 | |
| 4966 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 4967 | HandleBitwiseOperation(instruction); |
| 4968 | } |
| 4969 | |
| 4970 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 4971 | HandleBitwiseOperation(instruction); |
| 4972 | } |
| 4973 | |
| 4974 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 4975 | HandleBitwiseOperation(instruction); |
| 4976 | } |
| 4977 | |
| 4978 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4979 | LocationSummary* locations = instruction->GetLocations(); |
| 4980 | Location first = locations->InAt(0); |
| 4981 | Location second = locations->InAt(1); |
| 4982 | DCHECK(first.Equals(locations->Out())); |
| 4983 | |
| 4984 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 4985 | if (second.IsRegister()) { |
| 4986 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4987 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4988 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4989 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4990 | } else { |
| 4991 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4992 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4993 | } |
| 4994 | } else if (second.IsConstant()) { |
| 4995 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4996 | __ andl(first.AsRegister<Register>(), |
| 4997 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4998 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4999 | __ orl(first.AsRegister<Register>(), |
| 5000 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5001 | } else { |
| 5002 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5003 | __ xorl(first.AsRegister<Register>(), |
| 5004 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5005 | } |
| 5006 | } else { |
| 5007 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5008 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5009 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5010 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5011 | } else { |
| 5012 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5013 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5014 | } |
| 5015 | } |
| 5016 | } else { |
| 5017 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5018 | if (second.IsRegisterPair()) { |
| 5019 | if (instruction->IsAnd()) { |
| 5020 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5021 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5022 | } else if (instruction->IsOr()) { |
| 5023 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5024 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5025 | } else { |
| 5026 | DCHECK(instruction->IsXor()); |
| 5027 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5028 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5029 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5030 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5031 | if (instruction->IsAnd()) { |
| 5032 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5033 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 5034 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5035 | } else if (instruction->IsOr()) { |
| 5036 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5037 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 5038 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5039 | } else { |
| 5040 | DCHECK(instruction->IsXor()); |
| 5041 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5042 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 5043 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5044 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5045 | } else { |
| 5046 | DCHECK(second.IsConstant()) << second; |
| 5047 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5048 | int32_t low_value = Low32Bits(value); |
| 5049 | int32_t high_value = High32Bits(value); |
| 5050 | Immediate low(low_value); |
| 5051 | Immediate high(high_value); |
| 5052 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5053 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5054 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5055 | if (low_value == 0) { |
| 5056 | __ xorl(first_low, first_low); |
| 5057 | } else if (low_value != -1) { |
| 5058 | __ andl(first_low, low); |
| 5059 | } |
| 5060 | if (high_value == 0) { |
| 5061 | __ xorl(first_high, first_high); |
| 5062 | } else if (high_value != -1) { |
| 5063 | __ andl(first_high, high); |
| 5064 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5065 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5066 | if (low_value != 0) { |
| 5067 | __ orl(first_low, low); |
| 5068 | } |
| 5069 | if (high_value != 0) { |
| 5070 | __ orl(first_high, high); |
| 5071 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5072 | } else { |
| 5073 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5074 | if (low_value != 0) { |
| 5075 | __ xorl(first_low, low); |
| 5076 | } |
| 5077 | if (high_value != 0) { |
| 5078 | __ xorl(first_high, high); |
| 5079 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5080 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5081 | } |
| 5082 | } |
| 5083 | } |
| 5084 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5085 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 5086 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5087 | UNUSED(instruction); |
| 5088 | LOG(FATAL) << "Unreachable"; |
| 5089 | } |
| 5090 | |
| 5091 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 5092 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5093 | UNUSED(instruction); |
| 5094 | LOG(FATAL) << "Unreachable"; |
| 5095 | } |
| 5096 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5097 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 5098 | DCHECK(codegen_->IsBaseline()); |
| 5099 | LocationSummary* locations = |
| 5100 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5101 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5102 | } |
| 5103 | |
| 5104 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5105 | DCHECK(codegen_->IsBaseline()); |
| 5106 | // Will be generated at use site. |
| 5107 | } |
| 5108 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5109 | #undef __ |
| 5110 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5111 | } // namespace x86 |
| 5112 | } // namespace art |