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