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" |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 22 | #include "constant_area_fixups_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 34 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | namespace x86 { |
| 39 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 40 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 41 | static constexpr Register kMethodRegisterArgument = EAX; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 43 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 44 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 45 | static constexpr int kC2ConditionMask = 0x400; |
| 46 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 47 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 48 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 49 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 50 | #define QUICK_ENTRY_POINT(x) Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x)) |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 51 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 52 | class NullCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 54 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 56 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 57 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 59 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 60 | instruction_, |
| 61 | instruction_->GetDexPc(), |
| 62 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 65 | bool IsFatal() const OVERRIDE { return true; } |
| 66 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 67 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 68 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 70 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 72 | }; |
| 73 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 74 | class DivZeroCheckSlowPathX86 : public SlowPathCodeX86 { |
| 75 | public: |
| 76 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 77 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 78 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 79 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 80 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 82 | instruction_, |
| 83 | instruction_->GetDexPc(), |
| 84 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 87 | bool IsFatal() const OVERRIDE { return true; } |
| 88 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 89 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 90 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | private: |
| 92 | HDivZeroCheck* const instruction_; |
| 93 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 94 | }; |
| 95 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 96 | class DivRemMinusOneSlowPathX86 : public SlowPathCodeX86 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 98 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 100 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 102 | if (is_div_) { |
| 103 | __ negl(reg_); |
| 104 | } else { |
| 105 | __ movl(reg_, Immediate(0)); |
| 106 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | __ jmp(GetExitLabel()); |
| 108 | } |
| 109 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 110 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 111 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | private: |
| 113 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | bool is_div_; |
| 115 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 118 | class BoundsCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 119 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 120 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 121 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 122 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 123 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 124 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 125 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 126 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 127 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 128 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 129 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 130 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 131 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 132 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 133 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 134 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 135 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 136 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 137 | instruction_, |
| 138 | instruction_->GetDexPc(), |
| 139 | this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 142 | bool IsFatal() const OVERRIDE { return true; } |
| 143 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 144 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 145 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 146 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 147 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 148 | |
| 149 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 150 | }; |
| 151 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 152 | class SuspendCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 153 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 154 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 155 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 156 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 157 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 158 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 159 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 160 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 161 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 162 | instruction_, |
| 163 | instruction_->GetDexPc(), |
| 164 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 165 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 166 | if (successor_ == nullptr) { |
| 167 | __ jmp(GetReturnLabel()); |
| 168 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 169 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 170 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 173 | Label* GetReturnLabel() { |
| 174 | DCHECK(successor_ == nullptr); |
| 175 | return &return_label_; |
| 176 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 177 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 178 | HBasicBlock* GetSuccessor() const { |
| 179 | return successor_; |
| 180 | } |
| 181 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 182 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 183 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | private: |
| 185 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 186 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 187 | Label return_label_; |
| 188 | |
| 189 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 190 | }; |
| 191 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 192 | class LoadStringSlowPathX86 : public SlowPathCodeX86 { |
| 193 | public: |
| 194 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 195 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 196 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 197 | LocationSummary* locations = instruction_->GetLocations(); |
| 198 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 199 | |
| 200 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 201 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 202 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 203 | |
| 204 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 205 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 206 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 207 | instruction_, |
| 208 | instruction_->GetDexPc(), |
| 209 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 210 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 211 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 212 | |
| 213 | __ jmp(GetExitLabel()); |
| 214 | } |
| 215 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 216 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 217 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 218 | private: |
| 219 | HLoadString* const instruction_; |
| 220 | |
| 221 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 222 | }; |
| 223 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | class LoadClassSlowPathX86 : public SlowPathCodeX86 { |
| 225 | public: |
| 226 | LoadClassSlowPathX86(HLoadClass* cls, |
| 227 | HInstruction* at, |
| 228 | uint32_t dex_pc, |
| 229 | bool do_clinit) |
| 230 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 231 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 232 | } |
| 233 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 234 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 235 | LocationSummary* locations = at_->GetLocations(); |
| 236 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 237 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 238 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 239 | |
| 240 | InvokeRuntimeCallingConvention calling_convention; |
| 241 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 242 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 243 | : QUICK_ENTRY_POINT(pInitializeType), |
| 244 | at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 245 | |
| 246 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 247 | Location out = locations->Out(); |
| 248 | if (out.IsValid()) { |
| 249 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 250 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 251 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 252 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 253 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 254 | __ jmp(GetExitLabel()); |
| 255 | } |
| 256 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 257 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 258 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 259 | private: |
| 260 | // The class this slow path will load. |
| 261 | HLoadClass* const cls_; |
| 262 | |
| 263 | // The instruction where this slow path is happening. |
| 264 | // (Might be the load class or an initialization check). |
| 265 | HInstruction* const at_; |
| 266 | |
| 267 | // The dex PC of `at_`. |
| 268 | const uint32_t dex_pc_; |
| 269 | |
| 270 | // Whether to initialize the class. |
| 271 | const bool do_clinit_; |
| 272 | |
| 273 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 274 | }; |
| 275 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 276 | class TypeCheckSlowPathX86 : public SlowPathCodeX86 { |
| 277 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 278 | explicit TypeCheckSlowPathX86(HInstruction* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 279 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 280 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 281 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 282 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 283 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 284 | DCHECK(instruction_->IsCheckCast() |
| 285 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 286 | |
| 287 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 288 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 289 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 290 | |
| 291 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 292 | // move resolver. |
| 293 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 294 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 295 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 296 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 297 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 298 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 299 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 300 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 302 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 303 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 304 | instruction_, |
| 305 | instruction_->GetDexPc(), |
| 306 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 307 | } else { |
| 308 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 309 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 310 | instruction_, |
| 311 | instruction_->GetDexPc(), |
| 312 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 315 | if (instruction_->IsInstanceOf()) { |
| 316 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 317 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 318 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 319 | |
| 320 | __ jmp(GetExitLabel()); |
| 321 | } |
| 322 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 323 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
| 324 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 325 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 326 | HInstruction* const instruction_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | |
| 328 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 329 | }; |
| 330 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 331 | class DeoptimizationSlowPathX86 : public SlowPathCodeX86 { |
| 332 | public: |
| 333 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 334 | : instruction_(instruction) {} |
| 335 | |
| 336 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 9859620 | 2015-08-19 11:33:36 +0100 | [diff] [blame] | 337 | DCHECK(instruction_->IsDeoptimize()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 338 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 339 | __ Bind(GetEntryLabel()); |
| 340 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 341 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 342 | instruction_, |
| 343 | instruction_->GetDexPc(), |
| 344 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 347 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 348 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 349 | private: |
| 350 | HInstruction* const instruction_; |
| 351 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 352 | }; |
| 353 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 354 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 355 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 356 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 357 | inline Condition X86SignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 358 | switch (cond) { |
| 359 | case kCondEQ: return kEqual; |
| 360 | case kCondNE: return kNotEqual; |
| 361 | case kCondLT: return kLess; |
| 362 | case kCondLE: return kLessEqual; |
| 363 | case kCondGT: return kGreater; |
| 364 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 365 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 366 | LOG(FATAL) << "Unreachable"; |
| 367 | UNREACHABLE(); |
| 368 | } |
| 369 | |
| 370 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 371 | switch (cond) { |
| 372 | case kCondEQ: return kEqual; |
| 373 | case kCondNE: return kNotEqual; |
| 374 | case kCondLT: return kBelow; |
| 375 | case kCondLE: return kBelowEqual; |
| 376 | case kCondGT: return kAbove; |
| 377 | case kCondGE: return kAboveEqual; |
| 378 | } |
| 379 | LOG(FATAL) << "Unreachable"; |
| 380 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 383 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 384 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 388 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 389 | } |
| 390 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 391 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 392 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 393 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 394 | } |
| 395 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 396 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 397 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 398 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 401 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 402 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 403 | return GetFloatingPointSpillSlotSize(); |
| 404 | } |
| 405 | |
| 406 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 407 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 408 | return GetFloatingPointSpillSlotSize(); |
| 409 | } |
| 410 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 411 | void CodeGeneratorX86::InvokeRuntime(Address entry_point, |
| 412 | HInstruction* instruction, |
| 413 | uint32_t dex_pc, |
| 414 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 415 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 416 | __ fs()->call(entry_point); |
| 417 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 418 | } |
| 419 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 420 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| 421 | const X86InstructionSetFeatures& isa_features, |
| 422 | const CompilerOptions& compiler_options) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 423 | : CodeGenerator(graph, |
| 424 | kNumberOfCpuRegisters, |
| 425 | kNumberOfXmmRegisters, |
| 426 | kNumberOfRegisterPairs, |
| 427 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 428 | arraysize(kCoreCalleeSaves)) |
| 429 | | (1 << kFakeReturnRegister), |
| 430 | 0, |
| 431 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 432 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 433 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 434 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 435 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 436 | isa_features_(isa_features), |
| 437 | method_patches_(graph->GetArena()->Adapter()), |
| 438 | relative_call_patches_(graph->GetArena()->Adapter()) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 439 | // Use a fake return address register to mimic Quick. |
| 440 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 441 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 442 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 443 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 444 | switch (type) { |
| 445 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 446 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 447 | X86ManagedRegister pair = |
| 448 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 449 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 450 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 451 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 452 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 453 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 454 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | case Primitive::kPrimByte: |
| 458 | case Primitive::kPrimBoolean: |
| 459 | case Primitive::kPrimChar: |
| 460 | case Primitive::kPrimShort: |
| 461 | case Primitive::kPrimInt: |
| 462 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 463 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 464 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 465 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 466 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 467 | X86ManagedRegister current = |
| 468 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 469 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 470 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 471 | } |
| 472 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 473 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 477 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 478 | return Location::FpuRegisterLocation( |
| 479 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 480 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 481 | |
| 482 | case Primitive::kPrimVoid: |
| 483 | LOG(FATAL) << "Unreachable type " << type; |
| 484 | } |
| 485 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 486 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 487 | } |
| 488 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 489 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 490 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 491 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 492 | |
| 493 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 494 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 495 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 496 | if (is_baseline) { |
| 497 | blocked_core_registers_[EBP] = true; |
| 498 | blocked_core_registers_[ESI] = true; |
| 499 | blocked_core_registers_[EDI] = true; |
| 500 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 501 | |
| 502 | UpdateBlockedPairRegisters(); |
| 503 | } |
| 504 | |
| 505 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 506 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 507 | X86ManagedRegister current = |
| 508 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 509 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 510 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 511 | blocked_register_pairs_[i] = true; |
| 512 | } |
| 513 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 516 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 517 | : HGraphVisitor(graph), |
| 518 | assembler_(codegen->GetAssembler()), |
| 519 | codegen_(codegen) {} |
| 520 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 521 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 522 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 525 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 526 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 527 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 528 | bool skip_overflow_check = |
| 529 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 530 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 531 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 532 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 533 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 534 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 537 | if (HasEmptyFrame()) { |
| 538 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 539 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 540 | |
| 541 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 542 | Register reg = kCoreCalleeSaves[i]; |
| 543 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 544 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 545 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 546 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 550 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 551 | __ subl(ESP, Immediate(adjust)); |
| 552 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 553 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 557 | __ cfi().RememberState(); |
| 558 | if (!HasEmptyFrame()) { |
| 559 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 560 | __ addl(ESP, Immediate(adjust)); |
| 561 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 562 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 563 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 564 | Register reg = kCoreCalleeSaves[i]; |
| 565 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 566 | __ popl(reg); |
| 567 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 568 | __ cfi().Restore(DWARFReg(reg)); |
| 569 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 570 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 571 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 572 | __ ret(); |
| 573 | __ cfi().RestoreState(); |
| 574 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 577 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 578 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 581 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 582 | switch (load->GetType()) { |
| 583 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 584 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 585 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 586 | |
| 587 | case Primitive::kPrimInt: |
| 588 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 589 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 590 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 591 | |
| 592 | case Primitive::kPrimBoolean: |
| 593 | case Primitive::kPrimByte: |
| 594 | case Primitive::kPrimChar: |
| 595 | case Primitive::kPrimShort: |
| 596 | case Primitive::kPrimVoid: |
| 597 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 598 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 602 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 605 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 606 | switch (type) { |
| 607 | case Primitive::kPrimBoolean: |
| 608 | case Primitive::kPrimByte: |
| 609 | case Primitive::kPrimChar: |
| 610 | case Primitive::kPrimShort: |
| 611 | case Primitive::kPrimInt: |
| 612 | case Primitive::kPrimNot: |
| 613 | return Location::RegisterLocation(EAX); |
| 614 | |
| 615 | case Primitive::kPrimLong: |
| 616 | return Location::RegisterPairLocation(EAX, EDX); |
| 617 | |
| 618 | case Primitive::kPrimVoid: |
| 619 | return Location::NoLocation(); |
| 620 | |
| 621 | case Primitive::kPrimDouble: |
| 622 | case Primitive::kPrimFloat: |
| 623 | return Location::FpuRegisterLocation(XMM0); |
| 624 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 625 | |
| 626 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 630 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 631 | } |
| 632 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 633 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 634 | switch (type) { |
| 635 | case Primitive::kPrimBoolean: |
| 636 | case Primitive::kPrimByte: |
| 637 | case Primitive::kPrimChar: |
| 638 | case Primitive::kPrimShort: |
| 639 | case Primitive::kPrimInt: |
| 640 | case Primitive::kPrimNot: { |
| 641 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 642 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 643 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 644 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 645 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 646 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 647 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 648 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 649 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 650 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 651 | uint32_t index = gp_index_; |
| 652 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 653 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 654 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 655 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 656 | calling_convention.GetRegisterPairAt(index)); |
| 657 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 658 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 659 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 664 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 665 | stack_index_++; |
| 666 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 667 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 668 | } else { |
| 669 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | case Primitive::kPrimDouble: { |
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_ += 2; |
| 676 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 677 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 678 | } else { |
| 679 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 683 | case Primitive::kPrimVoid: |
| 684 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 685 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 686 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 687 | return Location(); |
| 688 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 689 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 690 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 691 | if (source.Equals(destination)) { |
| 692 | return; |
| 693 | } |
| 694 | if (destination.IsRegister()) { |
| 695 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 696 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 697 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 698 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 699 | } else { |
| 700 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 701 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 702 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 703 | } else if (destination.IsFpuRegister()) { |
| 704 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 705 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 706 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 707 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 708 | } else { |
| 709 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 710 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 711 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 712 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 713 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 714 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 715 | __ movl(Address(ESP, destination.GetStackIndex()), 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 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 718 | } else if (source.IsConstant()) { |
| 719 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 720 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 721 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 722 | } else { |
| 723 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 724 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 725 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 731 | if (source.Equals(destination)) { |
| 732 | return; |
| 733 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 734 | if (destination.IsRegisterPair()) { |
| 735 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 736 | EmitParallelMoves( |
| 737 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 738 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 739 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 740 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 741 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 742 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 743 | } else if (source.IsFpuRegister()) { |
| 744 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 745 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 746 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 747 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 748 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 749 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 750 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 751 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 752 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 753 | if (source.IsFpuRegister()) { |
| 754 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 755 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 756 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 757 | } else { |
| 758 | LOG(FATAL) << "Unimplemented"; |
| 759 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 760 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 761 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 762 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 763 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 764 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 765 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 766 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 767 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 768 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 769 | } else if (source.IsConstant()) { |
| 770 | HConstant* constant = source.GetConstant(); |
| 771 | int64_t value; |
| 772 | if (constant->IsLongConstant()) { |
| 773 | value = constant->AsLongConstant()->GetValue(); |
| 774 | } else { |
| 775 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 776 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 777 | } |
| 778 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 779 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 780 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 781 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 782 | EmitParallelMoves( |
| 783 | Location::StackSlot(source.GetStackIndex()), |
| 784 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 785 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 786 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 787 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 788 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | } |
| 792 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 793 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 794 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 795 | if (instruction->IsCurrentMethod()) { |
| 796 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 797 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 798 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 799 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 800 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 801 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 802 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 803 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 804 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 805 | } else if (location.IsStackSlot()) { |
| 806 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 807 | } else { |
| 808 | DCHECK(location.IsConstant()); |
| 809 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 810 | } |
| 811 | } else if (const_to_move->IsLongConstant()) { |
| 812 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 813 | if (location.IsRegisterPair()) { |
| 814 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 815 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 816 | } else if (location.IsDoubleStackSlot()) { |
| 817 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 818 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 819 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 820 | } else { |
| 821 | DCHECK(location.IsConstant()); |
| 822 | DCHECK_EQ(location.GetConstant(), instruction); |
| 823 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 824 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 825 | } else if (instruction->IsTemporary()) { |
| 826 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 827 | if (temp_location.IsStackSlot()) { |
| 828 | Move32(location, temp_location); |
| 829 | } else { |
| 830 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 831 | Move64(location, temp_location); |
| 832 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 833 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 834 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 835 | switch (instruction->GetType()) { |
| 836 | case Primitive::kPrimBoolean: |
| 837 | case Primitive::kPrimByte: |
| 838 | case Primitive::kPrimChar: |
| 839 | case Primitive::kPrimShort: |
| 840 | case Primitive::kPrimInt: |
| 841 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 842 | case Primitive::kPrimFloat: |
| 843 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 844 | break; |
| 845 | |
| 846 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 847 | case Primitive::kPrimDouble: |
| 848 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | default: |
| 852 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 853 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 854 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 855 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 856 | switch (instruction->GetType()) { |
| 857 | case Primitive::kPrimBoolean: |
| 858 | case Primitive::kPrimByte: |
| 859 | case Primitive::kPrimChar: |
| 860 | case Primitive::kPrimShort: |
| 861 | case Primitive::kPrimInt: |
| 862 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 863 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 864 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 865 | break; |
| 866 | |
| 867 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 868 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 869 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 870 | break; |
| 871 | |
| 872 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 873 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 874 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 878 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 879 | DCHECK(!successor->IsExitBlock()); |
| 880 | |
| 881 | HBasicBlock* block = got->GetBlock(); |
| 882 | HInstruction* previous = got->GetPrevious(); |
| 883 | |
| 884 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 885 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 886 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 891 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 892 | } |
| 893 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 894 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 898 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 899 | got->SetLocations(nullptr); |
| 900 | } |
| 901 | |
| 902 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 903 | HandleGoto(got, got->GetSuccessor()); |
| 904 | } |
| 905 | |
| 906 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 907 | try_boundary->SetLocations(nullptr); |
| 908 | } |
| 909 | |
| 910 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 911 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 912 | if (!successor->IsExitBlock()) { |
| 913 | HandleGoto(try_boundary, successor); |
| 914 | } |
| 915 | } |
| 916 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 917 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 918 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 921 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 922 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 925 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 926 | Label* true_label, |
| 927 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 928 | if (cond->IsFPConditionTrueIfNaN()) { |
| 929 | __ j(kUnordered, true_label); |
| 930 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 931 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 932 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 933 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 937 | Label* true_label, |
| 938 | Label* false_label) { |
| 939 | LocationSummary* locations = cond->GetLocations(); |
| 940 | Location left = locations->InAt(0); |
| 941 | Location right = locations->InAt(1); |
| 942 | IfCondition if_cond = cond->GetCondition(); |
| 943 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 944 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 945 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 946 | IfCondition true_high_cond = if_cond; |
| 947 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 948 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 949 | |
| 950 | // Set the conditions for the test, remembering that == needs to be |
| 951 | // decided using the low words. |
| 952 | switch (if_cond) { |
| 953 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 954 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 955 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 956 | break; |
| 957 | case kCondLT: |
| 958 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 959 | break; |
| 960 | case kCondLE: |
| 961 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 962 | break; |
| 963 | case kCondGT: |
| 964 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 965 | break; |
| 966 | case kCondGE: |
| 967 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 968 | break; |
| 969 | } |
| 970 | |
| 971 | if (right.IsConstant()) { |
| 972 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 973 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 974 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 975 | |
| 976 | if (val_high == 0) { |
| 977 | __ testl(left_high, left_high); |
| 978 | } else { |
| 979 | __ cmpl(left_high, Immediate(val_high)); |
| 980 | } |
| 981 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 982 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 983 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 984 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 985 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 986 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 987 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 988 | } |
| 989 | // Must be equal high, so compare the lows. |
| 990 | if (val_low == 0) { |
| 991 | __ testl(left_low, left_low); |
| 992 | } else { |
| 993 | __ cmpl(left_low, Immediate(val_low)); |
| 994 | } |
| 995 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 996 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 997 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 998 | |
| 999 | __ cmpl(left_high, right_high); |
| 1000 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1001 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1002 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1003 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1004 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1005 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1006 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1007 | } |
| 1008 | // Must be equal high, so compare the lows. |
| 1009 | __ cmpl(left_low, right_low); |
| 1010 | } |
| 1011 | // The last comparison might be unsigned. |
| 1012 | __ j(final_condition, true_label); |
| 1013 | } |
| 1014 | |
| 1015 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1016 | HCondition* condition, |
| 1017 | Label* true_target, |
| 1018 | Label* false_target, |
| 1019 | Label* always_true_target) { |
| 1020 | LocationSummary* locations = condition->GetLocations(); |
| 1021 | Location left = locations->InAt(0); |
| 1022 | Location right = locations->InAt(1); |
| 1023 | |
| 1024 | // We don't want true_target as a nullptr. |
| 1025 | if (true_target == nullptr) { |
| 1026 | true_target = always_true_target; |
| 1027 | } |
| 1028 | bool falls_through = (false_target == nullptr); |
| 1029 | |
| 1030 | // FP compares don't like null false_targets. |
| 1031 | if (false_target == nullptr) { |
| 1032 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1033 | } |
| 1034 | |
| 1035 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1036 | switch (type) { |
| 1037 | case Primitive::kPrimLong: |
| 1038 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1039 | break; |
| 1040 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1041 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1042 | GenerateFPJumps(condition, true_target, false_target); |
| 1043 | break; |
| 1044 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1045 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1046 | GenerateFPJumps(condition, true_target, false_target); |
| 1047 | break; |
| 1048 | default: |
| 1049 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1050 | } |
| 1051 | |
| 1052 | if (!falls_through) { |
| 1053 | __ jmp(false_target); |
| 1054 | } |
| 1055 | } |
| 1056 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1057 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| 1058 | Label* true_target, |
| 1059 | Label* false_target, |
| 1060 | Label* always_true_target) { |
| 1061 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1062 | if (cond->IsIntConstant()) { |
| 1063 | // Constant condition, statically compared against 1. |
| 1064 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1065 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1066 | if (always_true_target != nullptr) { |
| 1067 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1068 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1069 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1070 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1071 | DCHECK_EQ(cond_value, 0); |
| 1072 | } |
| 1073 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1074 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1075 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1076 | // Moves do not affect the eflags register, so if the condition is |
| 1077 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1078 | // again. We can't use the eflags on long/FP conditions if they are |
| 1079 | // materialized due to the complex branching. |
| 1080 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1081 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1082 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1083 | && (type != Primitive::kPrimLong && !Primitive::IsFloatingPointType(type)); |
| 1084 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1085 | if (!eflags_set) { |
| 1086 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1087 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1088 | if (lhs.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1089 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1090 | } else { |
| 1091 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1092 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1093 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1094 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1095 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1096 | } |
| 1097 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1098 | // Condition has not been materialized, use its inputs as the |
| 1099 | // comparison and its condition as the branch condition. |
| 1100 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1101 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1102 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1103 | // Generate the comparison directly. |
| 1104 | GenerateCompareTestAndBranch(instruction->AsIf(), |
| 1105 | cond->AsCondition(), |
| 1106 | true_target, |
| 1107 | false_target, |
| 1108 | always_true_target); |
| 1109 | return; |
| 1110 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1111 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1112 | Location lhs = cond->GetLocations()->InAt(0); |
| 1113 | Location rhs = cond->GetLocations()->InAt(1); |
| 1114 | // LHS is guaranteed to be in a register (see |
| 1115 | // LocationsBuilderX86::VisitCondition). |
| 1116 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1117 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1118 | } else if (rhs.IsConstant()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame] | 1119 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1120 | if (constant == 0) { |
| 1121 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1122 | } else { |
| 1123 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1124 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1125 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1126 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1127 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1128 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1129 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1130 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1131 | if (false_target != nullptr) { |
| 1132 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1136 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| 1137 | LocationSummary* locations = |
| 1138 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1139 | HInstruction* cond = if_instr->InputAt(0); |
| 1140 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1141 | locations->SetInAt(0, Location::Any()); |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| 1146 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1147 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1148 | Label* always_true_target = true_target; |
| 1149 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1150 | if_instr->IfTrueSuccessor())) { |
| 1151 | always_true_target = nullptr; |
| 1152 | } |
| 1153 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1154 | if_instr->IfFalseSuccessor())) { |
| 1155 | false_target = nullptr; |
| 1156 | } |
| 1157 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1158 | } |
| 1159 | |
| 1160 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1161 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1162 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1163 | HInstruction* cond = deoptimize->InputAt(0); |
| 1164 | DCHECK(cond->IsCondition()); |
| 1165 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1166 | locations->SetInAt(0, Location::Any()); |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1171 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) |
| 1172 | DeoptimizationSlowPathX86(deoptimize); |
| 1173 | codegen_->AddSlowPath(slow_path); |
| 1174 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1175 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1176 | } |
| 1177 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1178 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1179 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1182 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1183 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1186 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1187 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1190 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1191 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1192 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1195 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1196 | LocationSummary* locations = |
| 1197 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1198 | switch (store->InputAt(1)->GetType()) { |
| 1199 | case Primitive::kPrimBoolean: |
| 1200 | case Primitive::kPrimByte: |
| 1201 | case Primitive::kPrimChar: |
| 1202 | case Primitive::kPrimShort: |
| 1203 | case Primitive::kPrimInt: |
| 1204 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1205 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1206 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1207 | break; |
| 1208 | |
| 1209 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1210 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1211 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1212 | break; |
| 1213 | |
| 1214 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1215 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1216 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1219 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1220 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1223 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1224 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1225 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1226 | // Handle the long/FP comparisons made in instruction simplification. |
| 1227 | switch (cond->InputAt(0)->GetType()) { |
| 1228 | case Primitive::kPrimLong: { |
| 1229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1230 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1231 | if (cond->NeedsMaterialization()) { |
| 1232 | locations->SetOut(Location::RequiresRegister()); |
| 1233 | } |
| 1234 | break; |
| 1235 | } |
| 1236 | case Primitive::kPrimFloat: |
| 1237 | case Primitive::kPrimDouble: { |
| 1238 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1239 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1240 | if (cond->NeedsMaterialization()) { |
| 1241 | locations->SetOut(Location::RequiresRegister()); |
| 1242 | } |
| 1243 | break; |
| 1244 | } |
| 1245 | default: |
| 1246 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1247 | locations->SetInAt(1, Location::Any()); |
| 1248 | if (cond->NeedsMaterialization()) { |
| 1249 | // We need a byte register. |
| 1250 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1251 | } |
| 1252 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1253 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1256 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1257 | if (!cond->NeedsMaterialization()) { |
| 1258 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1259 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1260 | |
| 1261 | LocationSummary* locations = cond->GetLocations(); |
| 1262 | Location lhs = locations->InAt(0); |
| 1263 | Location rhs = locations->InAt(1); |
| 1264 | Register reg = locations->Out().AsRegister<Register>(); |
| 1265 | Label true_label, false_label; |
| 1266 | |
| 1267 | switch (cond->InputAt(0)->GetType()) { |
| 1268 | default: { |
| 1269 | // Integer case. |
| 1270 | |
| 1271 | // Clear output register: setcc only sets the low byte. |
| 1272 | __ xorl(reg, reg); |
| 1273 | |
| 1274 | if (rhs.IsRegister()) { |
| 1275 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1276 | } else if (rhs.IsConstant()) { |
| 1277 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1278 | if (constant == 0) { |
| 1279 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1280 | } else { |
| 1281 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1282 | } |
| 1283 | } else { |
| 1284 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1285 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1286 | __ setb(X86SignedCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1287 | return; |
| 1288 | } |
| 1289 | case Primitive::kPrimLong: |
| 1290 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1291 | break; |
| 1292 | case Primitive::kPrimFloat: |
| 1293 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1294 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1295 | break; |
| 1296 | case Primitive::kPrimDouble: |
| 1297 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1298 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1299 | break; |
| 1300 | } |
| 1301 | |
| 1302 | // Convert the jumps into the result. |
| 1303 | Label done_label; |
| 1304 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1305 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1306 | __ Bind(&false_label); |
| 1307 | __ xorl(reg, reg); |
| 1308 | __ jmp(&done_label); |
| 1309 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1310 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1311 | __ Bind(&true_label); |
| 1312 | __ movl(reg, Immediate(1)); |
| 1313 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1317 | VisitCondition(comp); |
| 1318 | } |
| 1319 | |
| 1320 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1321 | VisitCondition(comp); |
| 1322 | } |
| 1323 | |
| 1324 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1325 | VisitCondition(comp); |
| 1326 | } |
| 1327 | |
| 1328 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1329 | VisitCondition(comp); |
| 1330 | } |
| 1331 | |
| 1332 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1333 | VisitCondition(comp); |
| 1334 | } |
| 1335 | |
| 1336 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1337 | VisitCondition(comp); |
| 1338 | } |
| 1339 | |
| 1340 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1341 | VisitCondition(comp); |
| 1342 | } |
| 1343 | |
| 1344 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1345 | VisitCondition(comp); |
| 1346 | } |
| 1347 | |
| 1348 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1349 | VisitCondition(comp); |
| 1350 | } |
| 1351 | |
| 1352 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1353 | VisitCondition(comp); |
| 1354 | } |
| 1355 | |
| 1356 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1357 | VisitCondition(comp); |
| 1358 | } |
| 1359 | |
| 1360 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1361 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1365 | LocationSummary* locations = |
| 1366 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1367 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1370 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1371 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1372 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1375 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1376 | LocationSummary* locations = |
| 1377 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1378 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1379 | } |
| 1380 | |
| 1381 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant) { |
| 1382 | // Will be generated at use site. |
| 1383 | UNUSED(constant); |
| 1384 | } |
| 1385 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1386 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1387 | LocationSummary* locations = |
| 1388 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1389 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 1393 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1394 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1395 | } |
| 1396 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1397 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1398 | LocationSummary* locations = |
| 1399 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1400 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1401 | } |
| 1402 | |
| 1403 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1404 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1405 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1409 | LocationSummary* locations = |
| 1410 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1411 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1412 | } |
| 1413 | |
| 1414 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1415 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1416 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1417 | } |
| 1418 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1419 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1420 | memory_barrier->SetLocations(nullptr); |
| 1421 | } |
| 1422 | |
| 1423 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1424 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1425 | } |
| 1426 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1427 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1428 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1431 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1432 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1433 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1436 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1437 | LocationSummary* locations = |
| 1438 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1439 | switch (ret->InputAt(0)->GetType()) { |
| 1440 | case Primitive::kPrimBoolean: |
| 1441 | case Primitive::kPrimByte: |
| 1442 | case Primitive::kPrimChar: |
| 1443 | case Primitive::kPrimShort: |
| 1444 | case Primitive::kPrimInt: |
| 1445 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1446 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1447 | break; |
| 1448 | |
| 1449 | case Primitive::kPrimLong: |
| 1450 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1451 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1452 | break; |
| 1453 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1454 | case Primitive::kPrimFloat: |
| 1455 | case Primitive::kPrimDouble: |
| 1456 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1457 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1458 | break; |
| 1459 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1460 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1461 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1462 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1465 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1466 | if (kIsDebugBuild) { |
| 1467 | switch (ret->InputAt(0)->GetType()) { |
| 1468 | case Primitive::kPrimBoolean: |
| 1469 | case Primitive::kPrimByte: |
| 1470 | case Primitive::kPrimChar: |
| 1471 | case Primitive::kPrimShort: |
| 1472 | case Primitive::kPrimInt: |
| 1473 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1474 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1475 | break; |
| 1476 | |
| 1477 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1478 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1479 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1480 | break; |
| 1481 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1482 | case Primitive::kPrimFloat: |
| 1483 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1484 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1485 | break; |
| 1486 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1487 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1488 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1489 | } |
| 1490 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1491 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1494 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1495 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1496 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1497 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1498 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1499 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1500 | if (intrinsic.TryDispatch(invoke)) { |
| 1501 | return; |
| 1502 | } |
| 1503 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1504 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1505 | |
| 1506 | if (codegen_->IsBaseline()) { |
| 1507 | // Baseline does not have enough registers if the current method also |
| 1508 | // needs a register. We therefore do not require a register for it, and let |
| 1509 | // the code generation of the invoke handle it. |
| 1510 | LocationSummary* locations = invoke->GetLocations(); |
| 1511 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 1512 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 1513 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 1514 | } |
| 1515 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1516 | } |
| 1517 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1518 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1519 | if (invoke->GetLocations()->Intrinsified()) { |
| 1520 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1521 | intrinsic.Dispatch(invoke); |
| 1522 | return true; |
| 1523 | } |
| 1524 | return false; |
| 1525 | } |
| 1526 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1527 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1528 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1529 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1530 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1531 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1532 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1533 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1534 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1535 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1536 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1537 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1538 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1539 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1543 | HandleInvoke(invoke); |
| 1544 | } |
| 1545 | |
| 1546 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1547 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1548 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1551 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1552 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1553 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1554 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1555 | LocationSummary* locations = invoke->GetLocations(); |
| 1556 | Location receiver = locations->InAt(0); |
| 1557 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1558 | // temp = object->GetClass(); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1559 | DCHECK(receiver.IsRegister()); |
| 1560 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1561 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1562 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1563 | // temp = temp->GetMethodAt(method_offset); |
| 1564 | __ movl(temp, Address(temp, method_offset)); |
| 1565 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1566 | __ call(Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1567 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1568 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1569 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1570 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1573 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1574 | HandleInvoke(invoke); |
| 1575 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1576 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1580 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1581 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1582 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1583 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1584 | LocationSummary* locations = invoke->GetLocations(); |
| 1585 | Location receiver = locations->InAt(0); |
| 1586 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1587 | |
| 1588 | // Set the hidden argument. |
| 1589 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1590 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1591 | |
| 1592 | // temp = object->GetClass(); |
| 1593 | if (receiver.IsStackSlot()) { |
| 1594 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1595 | __ movl(temp, Address(temp, class_offset)); |
| 1596 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1597 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1598 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1599 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1600 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1601 | // temp = temp->GetImtEntryAt(method_offset); |
| 1602 | __ movl(temp, Address(temp, method_offset)); |
| 1603 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1604 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1605 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1606 | |
| 1607 | DCHECK(!codegen_->IsLeafMethod()); |
| 1608 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1609 | } |
| 1610 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1611 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1612 | LocationSummary* locations = |
| 1613 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1614 | switch (neg->GetResultType()) { |
| 1615 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1616 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1617 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1618 | locations->SetOut(Location::SameAsFirstInput()); |
| 1619 | break; |
| 1620 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1621 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1622 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1623 | locations->SetOut(Location::SameAsFirstInput()); |
| 1624 | locations->AddTemp(Location::RequiresRegister()); |
| 1625 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1626 | break; |
| 1627 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1628 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1629 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1630 | locations->SetOut(Location::SameAsFirstInput()); |
| 1631 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1632 | break; |
| 1633 | |
| 1634 | default: |
| 1635 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1640 | LocationSummary* locations = neg->GetLocations(); |
| 1641 | Location out = locations->Out(); |
| 1642 | Location in = locations->InAt(0); |
| 1643 | switch (neg->GetResultType()) { |
| 1644 | case Primitive::kPrimInt: |
| 1645 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1646 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1647 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1648 | break; |
| 1649 | |
| 1650 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1651 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1652 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1653 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1654 | // Negation is similar to subtraction from zero. The least |
| 1655 | // significant byte triggers a borrow when it is different from |
| 1656 | // zero; to take it into account, add 1 to the most significant |
| 1657 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1658 | // operation. |
| 1659 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1660 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1661 | break; |
| 1662 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1663 | case Primitive::kPrimFloat: { |
| 1664 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1665 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1666 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1667 | // Implement float negation with an exclusive or with value |
| 1668 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1669 | // single-precision floating-point number). |
| 1670 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1671 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1672 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1673 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1674 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1675 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1676 | case Primitive::kPrimDouble: { |
| 1677 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1678 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1679 | // Implement double negation with an exclusive or with value |
| 1680 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1681 | // a double-precision floating-point number). |
| 1682 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1683 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1684 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1685 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1686 | |
| 1687 | default: |
| 1688 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1689 | } |
| 1690 | } |
| 1691 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1692 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1693 | Primitive::Type result_type = conversion->GetResultType(); |
| 1694 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1695 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1696 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1697 | // The float-to-long and double-to-long type conversions rely on a |
| 1698 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1699 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1700 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1701 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1702 | ? LocationSummary::kCall |
| 1703 | : LocationSummary::kNoCall; |
| 1704 | LocationSummary* locations = |
| 1705 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1706 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1707 | // The Java language does not allow treating boolean as an integral type but |
| 1708 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1709 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1710 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1711 | case Primitive::kPrimByte: |
| 1712 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1713 | case Primitive::kPrimBoolean: |
| 1714 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1715 | case Primitive::kPrimShort: |
| 1716 | case Primitive::kPrimInt: |
| 1717 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1718 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1719 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1720 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1721 | // the validation of the linear scan implementation |
| 1722 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1723 | break; |
| 1724 | |
| 1725 | default: |
| 1726 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1727 | << " to " << result_type; |
| 1728 | } |
| 1729 | break; |
| 1730 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1731 | case Primitive::kPrimShort: |
| 1732 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1733 | case Primitive::kPrimBoolean: |
| 1734 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1735 | case Primitive::kPrimByte: |
| 1736 | case Primitive::kPrimInt: |
| 1737 | case Primitive::kPrimChar: |
| 1738 | // Processing a Dex `int-to-short' instruction. |
| 1739 | locations->SetInAt(0, Location::Any()); |
| 1740 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1741 | break; |
| 1742 | |
| 1743 | default: |
| 1744 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1745 | << " to " << result_type; |
| 1746 | } |
| 1747 | break; |
| 1748 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1749 | case Primitive::kPrimInt: |
| 1750 | switch (input_type) { |
| 1751 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1752 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1753 | locations->SetInAt(0, Location::Any()); |
| 1754 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1755 | break; |
| 1756 | |
| 1757 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1758 | // Processing a Dex `float-to-int' instruction. |
| 1759 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1760 | locations->SetOut(Location::RequiresRegister()); |
| 1761 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1762 | break; |
| 1763 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1764 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1765 | // Processing a Dex `double-to-int' instruction. |
| 1766 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1767 | locations->SetOut(Location::RequiresRegister()); |
| 1768 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1769 | break; |
| 1770 | |
| 1771 | default: |
| 1772 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1773 | << " to " << result_type; |
| 1774 | } |
| 1775 | break; |
| 1776 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1777 | case Primitive::kPrimLong: |
| 1778 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1779 | case Primitive::kPrimBoolean: |
| 1780 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1781 | case Primitive::kPrimByte: |
| 1782 | case Primitive::kPrimShort: |
| 1783 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1784 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1785 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1786 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1787 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1788 | break; |
| 1789 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1790 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1791 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1792 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1793 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1794 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1795 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1796 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1797 | // The runtime helper puts the result in EAX, EDX. |
| 1798 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1799 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1800 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1801 | |
| 1802 | default: |
| 1803 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1804 | << " to " << result_type; |
| 1805 | } |
| 1806 | break; |
| 1807 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1808 | case Primitive::kPrimChar: |
| 1809 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1810 | case Primitive::kPrimBoolean: |
| 1811 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1812 | case Primitive::kPrimByte: |
| 1813 | case Primitive::kPrimShort: |
| 1814 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1815 | // Processing a Dex `int-to-char' instruction. |
| 1816 | locations->SetInAt(0, Location::Any()); |
| 1817 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1818 | break; |
| 1819 | |
| 1820 | default: |
| 1821 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1822 | << " to " << result_type; |
| 1823 | } |
| 1824 | break; |
| 1825 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1826 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1827 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1828 | case Primitive::kPrimBoolean: |
| 1829 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1830 | case Primitive::kPrimByte: |
| 1831 | case Primitive::kPrimShort: |
| 1832 | case Primitive::kPrimInt: |
| 1833 | case Primitive::kPrimChar: |
| 1834 | // Processing a Dex `int-to-float' instruction. |
| 1835 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1836 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1837 | break; |
| 1838 | |
| 1839 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1840 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1841 | locations->SetInAt(0, Location::Any()); |
| 1842 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1843 | break; |
| 1844 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1845 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1846 | // Processing a Dex `double-to-float' instruction. |
| 1847 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1848 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1849 | break; |
| 1850 | |
| 1851 | default: |
| 1852 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1853 | << " to " << result_type; |
| 1854 | }; |
| 1855 | break; |
| 1856 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1857 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1858 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1859 | case Primitive::kPrimBoolean: |
| 1860 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1861 | case Primitive::kPrimByte: |
| 1862 | case Primitive::kPrimShort: |
| 1863 | case Primitive::kPrimInt: |
| 1864 | case Primitive::kPrimChar: |
| 1865 | // Processing a Dex `int-to-double' instruction. |
| 1866 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1867 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1868 | break; |
| 1869 | |
| 1870 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1871 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1872 | locations->SetInAt(0, Location::Any()); |
| 1873 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1874 | break; |
| 1875 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1876 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1877 | // Processing a Dex `float-to-double' instruction. |
| 1878 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1879 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1880 | break; |
| 1881 | |
| 1882 | default: |
| 1883 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1884 | << " to " << result_type; |
| 1885 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1886 | break; |
| 1887 | |
| 1888 | default: |
| 1889 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1890 | << " to " << result_type; |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1895 | LocationSummary* locations = conversion->GetLocations(); |
| 1896 | Location out = locations->Out(); |
| 1897 | Location in = locations->InAt(0); |
| 1898 | Primitive::Type result_type = conversion->GetResultType(); |
| 1899 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1900 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1901 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1902 | case Primitive::kPrimByte: |
| 1903 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1904 | case Primitive::kPrimBoolean: |
| 1905 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1906 | case Primitive::kPrimShort: |
| 1907 | case Primitive::kPrimInt: |
| 1908 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1909 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1910 | if (in.IsRegister()) { |
| 1911 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1912 | } else { |
| 1913 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1914 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1915 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 1916 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1917 | break; |
| 1918 | |
| 1919 | default: |
| 1920 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1921 | << " to " << result_type; |
| 1922 | } |
| 1923 | break; |
| 1924 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1925 | case Primitive::kPrimShort: |
| 1926 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1927 | case Primitive::kPrimBoolean: |
| 1928 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1929 | case Primitive::kPrimByte: |
| 1930 | case Primitive::kPrimInt: |
| 1931 | case Primitive::kPrimChar: |
| 1932 | // Processing a Dex `int-to-short' instruction. |
| 1933 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1934 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1935 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1936 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1937 | } else { |
| 1938 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1939 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1940 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1941 | } |
| 1942 | break; |
| 1943 | |
| 1944 | default: |
| 1945 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1946 | << " to " << result_type; |
| 1947 | } |
| 1948 | break; |
| 1949 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1950 | case Primitive::kPrimInt: |
| 1951 | switch (input_type) { |
| 1952 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1953 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1954 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1955 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1956 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1957 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1958 | } else { |
| 1959 | DCHECK(in.IsConstant()); |
| 1960 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1961 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1962 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1963 | } |
| 1964 | break; |
| 1965 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1966 | case Primitive::kPrimFloat: { |
| 1967 | // Processing a Dex `float-to-int' instruction. |
| 1968 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1969 | Register output = out.AsRegister<Register>(); |
| 1970 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1971 | Label done, nan; |
| 1972 | |
| 1973 | __ movl(output, Immediate(kPrimIntMax)); |
| 1974 | // temp = int-to-float(output) |
| 1975 | __ cvtsi2ss(temp, output); |
| 1976 | // if input >= temp goto done |
| 1977 | __ comiss(input, temp); |
| 1978 | __ j(kAboveEqual, &done); |
| 1979 | // if input == NaN goto nan |
| 1980 | __ j(kUnordered, &nan); |
| 1981 | // output = float-to-int-truncate(input) |
| 1982 | __ cvttss2si(output, input); |
| 1983 | __ jmp(&done); |
| 1984 | __ Bind(&nan); |
| 1985 | // output = 0 |
| 1986 | __ xorl(output, output); |
| 1987 | __ Bind(&done); |
| 1988 | break; |
| 1989 | } |
| 1990 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1991 | case Primitive::kPrimDouble: { |
| 1992 | // Processing a Dex `double-to-int' instruction. |
| 1993 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1994 | Register output = out.AsRegister<Register>(); |
| 1995 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1996 | Label done, nan; |
| 1997 | |
| 1998 | __ movl(output, Immediate(kPrimIntMax)); |
| 1999 | // temp = int-to-double(output) |
| 2000 | __ cvtsi2sd(temp, output); |
| 2001 | // if input >= temp goto done |
| 2002 | __ comisd(input, temp); |
| 2003 | __ j(kAboveEqual, &done); |
| 2004 | // if input == NaN goto nan |
| 2005 | __ j(kUnordered, &nan); |
| 2006 | // output = double-to-int-truncate(input) |
| 2007 | __ cvttsd2si(output, input); |
| 2008 | __ jmp(&done); |
| 2009 | __ Bind(&nan); |
| 2010 | // output = 0 |
| 2011 | __ xorl(output, output); |
| 2012 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2013 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2014 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2015 | |
| 2016 | default: |
| 2017 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2018 | << " to " << result_type; |
| 2019 | } |
| 2020 | break; |
| 2021 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2022 | case Primitive::kPrimLong: |
| 2023 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2024 | case Primitive::kPrimBoolean: |
| 2025 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2026 | case Primitive::kPrimByte: |
| 2027 | case Primitive::kPrimShort: |
| 2028 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2029 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2030 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2031 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2032 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2033 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2034 | __ cdq(); |
| 2035 | break; |
| 2036 | |
| 2037 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2038 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2039 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2040 | conversion, |
| 2041 | conversion->GetDexPc(), |
| 2042 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2045 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2046 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2047 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2048 | conversion, |
| 2049 | conversion->GetDexPc(), |
| 2050 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2051 | break; |
| 2052 | |
| 2053 | default: |
| 2054 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2055 | << " to " << result_type; |
| 2056 | } |
| 2057 | break; |
| 2058 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2059 | case Primitive::kPrimChar: |
| 2060 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2061 | case Primitive::kPrimBoolean: |
| 2062 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2063 | case Primitive::kPrimByte: |
| 2064 | case Primitive::kPrimShort: |
| 2065 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2066 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2067 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2068 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2069 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2070 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2071 | } else { |
| 2072 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2073 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2074 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2075 | } |
| 2076 | break; |
| 2077 | |
| 2078 | default: |
| 2079 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2080 | << " to " << result_type; |
| 2081 | } |
| 2082 | break; |
| 2083 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2084 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2085 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2086 | case Primitive::kPrimBoolean: |
| 2087 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2088 | case Primitive::kPrimByte: |
| 2089 | case Primitive::kPrimShort: |
| 2090 | case Primitive::kPrimInt: |
| 2091 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2092 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2093 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2094 | break; |
| 2095 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2096 | case Primitive::kPrimLong: { |
| 2097 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2098 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2099 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2100 | // Create stack space for the call to |
| 2101 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2102 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2103 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2104 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2105 | __ subl(ESP, Immediate(adjustment)); |
| 2106 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2107 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2108 | // Load the value to the FP stack, using temporaries if needed. |
| 2109 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2110 | |
| 2111 | if (out.IsStackSlot()) { |
| 2112 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2113 | } else { |
| 2114 | __ fstps(Address(ESP, 0)); |
| 2115 | Location stack_temp = Location::StackSlot(0); |
| 2116 | codegen_->Move32(out, stack_temp); |
| 2117 | } |
| 2118 | |
| 2119 | // Remove the temporary stack space we allocated. |
| 2120 | if (adjustment != 0) { |
| 2121 | __ addl(ESP, Immediate(adjustment)); |
| 2122 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2123 | break; |
| 2124 | } |
| 2125 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2126 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2127 | // Processing a Dex `double-to-float' instruction. |
| 2128 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2129 | break; |
| 2130 | |
| 2131 | default: |
| 2132 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2133 | << " to " << result_type; |
| 2134 | }; |
| 2135 | break; |
| 2136 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2137 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2138 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2139 | case Primitive::kPrimBoolean: |
| 2140 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2141 | case Primitive::kPrimByte: |
| 2142 | case Primitive::kPrimShort: |
| 2143 | case Primitive::kPrimInt: |
| 2144 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2145 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2146 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2147 | break; |
| 2148 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2149 | case Primitive::kPrimLong: { |
| 2150 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2151 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2152 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2153 | // Create stack space for the call to |
| 2154 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2155 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2156 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2157 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2158 | __ subl(ESP, Immediate(adjustment)); |
| 2159 | } |
| 2160 | |
| 2161 | // Load the value to the FP stack, using temporaries if needed. |
| 2162 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2163 | |
| 2164 | if (out.IsDoubleStackSlot()) { |
| 2165 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2166 | } else { |
| 2167 | __ fstpl(Address(ESP, 0)); |
| 2168 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2169 | codegen_->Move64(out, stack_temp); |
| 2170 | } |
| 2171 | |
| 2172 | // Remove the temporary stack space we allocated. |
| 2173 | if (adjustment != 0) { |
| 2174 | __ addl(ESP, Immediate(adjustment)); |
| 2175 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2176 | break; |
| 2177 | } |
| 2178 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2179 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2180 | // Processing a Dex `float-to-double' instruction. |
| 2181 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2182 | break; |
| 2183 | |
| 2184 | default: |
| 2185 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2186 | << " to " << result_type; |
| 2187 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2188 | break; |
| 2189 | |
| 2190 | default: |
| 2191 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2192 | << " to " << result_type; |
| 2193 | } |
| 2194 | } |
| 2195 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2196 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2197 | LocationSummary* locations = |
| 2198 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2199 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2200 | case Primitive::kPrimInt: { |
| 2201 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2202 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2203 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2204 | break; |
| 2205 | } |
| 2206 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2207 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2208 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2209 | locations->SetInAt(1, Location::Any()); |
| 2210 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2211 | break; |
| 2212 | } |
| 2213 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2214 | case Primitive::kPrimFloat: |
| 2215 | case Primitive::kPrimDouble: { |
| 2216 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2217 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2218 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2219 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2220 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2221 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2222 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2223 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2224 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2225 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2229 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2230 | Location first = locations->InAt(0); |
| 2231 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2232 | Location out = locations->Out(); |
| 2233 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2234 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2235 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2236 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2237 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2238 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2239 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2240 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2241 | } else { |
| 2242 | __ leal(out.AsRegister<Register>(), Address( |
| 2243 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2244 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2245 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2246 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2247 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2248 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2249 | } else { |
| 2250 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2251 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2252 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2253 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2254 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2255 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2256 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2260 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2261 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2262 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2263 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2264 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2265 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2266 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2267 | } else { |
| 2268 | DCHECK(second.IsConstant()) << second; |
| 2269 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2270 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2271 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2272 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2273 | break; |
| 2274 | } |
| 2275 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2276 | case Primitive::kPrimFloat: { |
| 2277 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2278 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2279 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2280 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2281 | DCHECK(!const_area->NeedsMaterialization()); |
| 2282 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2283 | codegen_->LiteralFloatAddress( |
| 2284 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2285 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2286 | } else { |
| 2287 | DCHECK(second.IsStackSlot()); |
| 2288 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
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>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2296 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2297 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2298 | DCHECK(!const_area->NeedsMaterialization()); |
| 2299 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2300 | codegen_->LiteralDoubleAddress( |
| 2301 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2302 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2303 | } else { |
| 2304 | DCHECK(second.IsDoubleStackSlot()); |
| 2305 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2306 | } |
| 2307 | break; |
| 2308 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2309 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2310 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2311 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2312 | } |
| 2313 | } |
| 2314 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2315 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2316 | LocationSummary* locations = |
| 2317 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2318 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2319 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2320 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2321 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2322 | locations->SetInAt(1, Location::Any()); |
| 2323 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2324 | break; |
| 2325 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2326 | case Primitive::kPrimFloat: |
| 2327 | case Primitive::kPrimDouble: { |
| 2328 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2329 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2330 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2331 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2332 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2333 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2334 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2335 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2336 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2340 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2341 | Location first = locations->InAt(0); |
| 2342 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2343 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2344 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2345 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2346 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2347 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2348 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2349 | __ subl(first.AsRegister<Register>(), |
| 2350 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2351 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2352 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2353 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2354 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2358 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2359 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2360 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2361 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2362 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2363 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2364 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2365 | } else { |
| 2366 | DCHECK(second.IsConstant()) << second; |
| 2367 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2368 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2369 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2370 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2371 | break; |
| 2372 | } |
| 2373 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2374 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2375 | if (second.IsFpuRegister()) { |
| 2376 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2377 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2378 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2379 | DCHECK(!const_area->NeedsMaterialization()); |
| 2380 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2381 | codegen_->LiteralFloatAddress( |
| 2382 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2383 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2384 | } else { |
| 2385 | DCHECK(second.IsStackSlot()); |
| 2386 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2387 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2388 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2392 | if (second.IsFpuRegister()) { |
| 2393 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2394 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2395 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2396 | DCHECK(!const_area->NeedsMaterialization()); |
| 2397 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2398 | codegen_->LiteralDoubleAddress( |
| 2399 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2400 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2401 | } else { |
| 2402 | DCHECK(second.IsDoubleStackSlot()); |
| 2403 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2404 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2405 | break; |
| 2406 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2407 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2408 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2409 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2413 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2414 | LocationSummary* locations = |
| 2415 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2416 | switch (mul->GetResultType()) { |
| 2417 | case Primitive::kPrimInt: |
| 2418 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2419 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2420 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2421 | // Can use 3 operand multiply. |
| 2422 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2423 | } else { |
| 2424 | locations->SetOut(Location::SameAsFirstInput()); |
| 2425 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2426 | break; |
| 2427 | case Primitive::kPrimLong: { |
| 2428 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2429 | locations->SetInAt(1, Location::Any()); |
| 2430 | locations->SetOut(Location::SameAsFirstInput()); |
| 2431 | // Needed for imul on 32bits with 64bits output. |
| 2432 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2433 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2434 | break; |
| 2435 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2436 | case Primitive::kPrimFloat: |
| 2437 | case Primitive::kPrimDouble: { |
| 2438 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2439 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2440 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2441 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2442 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2443 | |
| 2444 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2445 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2450 | LocationSummary* locations = mul->GetLocations(); |
| 2451 | Location first = locations->InAt(0); |
| 2452 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2453 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2454 | |
| 2455 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2456 | case Primitive::kPrimInt: |
| 2457 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2458 | // problems where the output may not be the same as the first operand. |
| 2459 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2460 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2461 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2462 | } else if (second.IsRegister()) { |
| 2463 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2464 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2465 | } else { |
| 2466 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2467 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2468 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2469 | } |
| 2470 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2471 | |
| 2472 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2473 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2474 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2475 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2476 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2477 | |
| 2478 | DCHECK_EQ(EAX, eax); |
| 2479 | DCHECK_EQ(EDX, edx); |
| 2480 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2481 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2482 | // output: in1 |
| 2483 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2484 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2485 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2486 | if (second.IsConstant()) { |
| 2487 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2488 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2489 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2490 | int32_t low_value = Low32Bits(value); |
| 2491 | int32_t high_value = High32Bits(value); |
| 2492 | Immediate low(low_value); |
| 2493 | Immediate high(high_value); |
| 2494 | |
| 2495 | __ movl(eax, high); |
| 2496 | // eax <- in1.lo * in2.hi |
| 2497 | __ imull(eax, in1_lo); |
| 2498 | // in1.hi <- in1.hi * in2.lo |
| 2499 | __ imull(in1_hi, low); |
| 2500 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2501 | __ addl(in1_hi, eax); |
| 2502 | // move in2_lo to eax to prepare for double precision |
| 2503 | __ movl(eax, low); |
| 2504 | // edx:eax <- in1.lo * in2.lo |
| 2505 | __ mull(in1_lo); |
| 2506 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2507 | __ addl(in1_hi, edx); |
| 2508 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2509 | __ movl(in1_lo, eax); |
| 2510 | } else if (second.IsRegisterPair()) { |
| 2511 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2512 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2513 | |
| 2514 | __ movl(eax, in2_hi); |
| 2515 | // eax <- in1.lo * in2.hi |
| 2516 | __ imull(eax, in1_lo); |
| 2517 | // in1.hi <- in1.hi * in2.lo |
| 2518 | __ imull(in1_hi, in2_lo); |
| 2519 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2520 | __ addl(in1_hi, eax); |
| 2521 | // move in1_lo to eax to prepare for double precision |
| 2522 | __ movl(eax, in1_lo); |
| 2523 | // edx:eax <- in1.lo * in2.lo |
| 2524 | __ mull(in2_lo); |
| 2525 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2526 | __ addl(in1_hi, edx); |
| 2527 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2528 | __ movl(in1_lo, eax); |
| 2529 | } else { |
| 2530 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2531 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2532 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2533 | |
| 2534 | __ movl(eax, in2_hi); |
| 2535 | // eax <- in1.lo * in2.hi |
| 2536 | __ imull(eax, in1_lo); |
| 2537 | // in1.hi <- in1.hi * in2.lo |
| 2538 | __ imull(in1_hi, in2_lo); |
| 2539 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2540 | __ addl(in1_hi, eax); |
| 2541 | // move in1_lo to eax to prepare for double precision |
| 2542 | __ movl(eax, in1_lo); |
| 2543 | // edx:eax <- in1.lo * in2.lo |
| 2544 | __ mull(in2_lo); |
| 2545 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2546 | __ addl(in1_hi, edx); |
| 2547 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2548 | __ movl(in1_lo, eax); |
| 2549 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2550 | |
| 2551 | break; |
| 2552 | } |
| 2553 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2554 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2555 | DCHECK(first.Equals(locations->Out())); |
| 2556 | if (second.IsFpuRegister()) { |
| 2557 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2558 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2559 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2560 | DCHECK(!const_area->NeedsMaterialization()); |
| 2561 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2562 | codegen_->LiteralFloatAddress( |
| 2563 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2564 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2565 | } else { |
| 2566 | DCHECK(second.IsStackSlot()); |
| 2567 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2568 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2569 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2573 | DCHECK(first.Equals(locations->Out())); |
| 2574 | if (second.IsFpuRegister()) { |
| 2575 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2576 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2577 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2578 | DCHECK(!const_area->NeedsMaterialization()); |
| 2579 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2580 | codegen_->LiteralDoubleAddress( |
| 2581 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2582 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2583 | } else { |
| 2584 | DCHECK(second.IsDoubleStackSlot()); |
| 2585 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2586 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2587 | break; |
| 2588 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2589 | |
| 2590 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2591 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2592 | } |
| 2593 | } |
| 2594 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2595 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 2596 | uint32_t temp_offset, |
| 2597 | uint32_t stack_adjustment, |
| 2598 | bool is_fp, |
| 2599 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2600 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2601 | DCHECK(!is_wide); |
| 2602 | if (is_fp) { |
| 2603 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2604 | } else { |
| 2605 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2606 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2607 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2608 | DCHECK(is_wide); |
| 2609 | if (is_fp) { |
| 2610 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2611 | } else { |
| 2612 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2613 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2614 | } else { |
| 2615 | // 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] | 2616 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2617 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2618 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2619 | if (is_fp) { |
| 2620 | __ flds(Address(ESP, temp_offset)); |
| 2621 | } else { |
| 2622 | __ filds(Address(ESP, temp_offset)); |
| 2623 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2624 | } else { |
| 2625 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2626 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2627 | if (is_fp) { |
| 2628 | __ fldl(Address(ESP, temp_offset)); |
| 2629 | } else { |
| 2630 | __ fildl(Address(ESP, temp_offset)); |
| 2631 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2637 | Primitive::Type type = rem->GetResultType(); |
| 2638 | bool is_float = type == Primitive::kPrimFloat; |
| 2639 | size_t elem_size = Primitive::ComponentSize(type); |
| 2640 | LocationSummary* locations = rem->GetLocations(); |
| 2641 | Location first = locations->InAt(0); |
| 2642 | Location second = locations->InAt(1); |
| 2643 | Location out = locations->Out(); |
| 2644 | |
| 2645 | // Create stack space for 2 elements. |
| 2646 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2647 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2648 | |
| 2649 | // 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] | 2650 | const bool is_wide = !is_float; |
| 2651 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 2652 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2653 | |
| 2654 | // Loop doing FPREM until we stabilize. |
| 2655 | Label retry; |
| 2656 | __ Bind(&retry); |
| 2657 | __ fprem(); |
| 2658 | |
| 2659 | // Move FP status to AX. |
| 2660 | __ fstsw(); |
| 2661 | |
| 2662 | // And see if the argument reduction is complete. This is signaled by the |
| 2663 | // C2 FPU flag bit set to 0. |
| 2664 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2665 | __ j(kNotEqual, &retry); |
| 2666 | |
| 2667 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2668 | // Store FP top of stack to real stack. |
| 2669 | if (is_float) { |
| 2670 | __ fsts(Address(ESP, 0)); |
| 2671 | } else { |
| 2672 | __ fstl(Address(ESP, 0)); |
| 2673 | } |
| 2674 | |
| 2675 | // Pop the 2 items from the FP stack. |
| 2676 | __ fucompp(); |
| 2677 | |
| 2678 | // Load the value from the stack into an XMM register. |
| 2679 | DCHECK(out.IsFpuRegister()) << out; |
| 2680 | if (is_float) { |
| 2681 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2682 | } else { |
| 2683 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2684 | } |
| 2685 | |
| 2686 | // And remove the temporary stack space we allocated. |
| 2687 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2688 | } |
| 2689 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2690 | |
| 2691 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2692 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2693 | |
| 2694 | LocationSummary* locations = instruction->GetLocations(); |
| 2695 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2696 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2697 | |
| 2698 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2699 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2700 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2701 | |
| 2702 | DCHECK(imm == 1 || imm == -1); |
| 2703 | |
| 2704 | if (instruction->IsRem()) { |
| 2705 | __ xorl(out_register, out_register); |
| 2706 | } else { |
| 2707 | __ movl(out_register, input_register); |
| 2708 | if (imm == -1) { |
| 2709 | __ negl(out_register); |
| 2710 | } |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2715 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2716 | LocationSummary* locations = instruction->GetLocations(); |
| 2717 | |
| 2718 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2719 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2720 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2721 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2722 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2723 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2724 | |
| 2725 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2726 | __ testl(input_register, input_register); |
| 2727 | __ cmovl(kGreaterEqual, num, input_register); |
| 2728 | int shift = CTZ(imm); |
| 2729 | __ sarl(num, Immediate(shift)); |
| 2730 | |
| 2731 | if (imm < 0) { |
| 2732 | __ negl(num); |
| 2733 | } |
| 2734 | |
| 2735 | __ movl(out_register, num); |
| 2736 | } |
| 2737 | |
| 2738 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2739 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2740 | |
| 2741 | LocationSummary* locations = instruction->GetLocations(); |
| 2742 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2743 | |
| 2744 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2745 | Register out = locations->Out().AsRegister<Register>(); |
| 2746 | Register num; |
| 2747 | Register edx; |
| 2748 | |
| 2749 | if (instruction->IsDiv()) { |
| 2750 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2751 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2752 | } else { |
| 2753 | edx = locations->Out().AsRegister<Register>(); |
| 2754 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2755 | } |
| 2756 | |
| 2757 | DCHECK_EQ(EAX, eax); |
| 2758 | DCHECK_EQ(EDX, edx); |
| 2759 | if (instruction->IsDiv()) { |
| 2760 | DCHECK_EQ(EAX, out); |
| 2761 | } else { |
| 2762 | DCHECK_EQ(EDX, out); |
| 2763 | } |
| 2764 | |
| 2765 | int64_t magic; |
| 2766 | int shift; |
| 2767 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2768 | |
| 2769 | Label ndiv; |
| 2770 | Label end; |
| 2771 | // If numerator is 0, the result is 0, no computation needed. |
| 2772 | __ testl(eax, eax); |
| 2773 | __ j(kNotEqual, &ndiv); |
| 2774 | |
| 2775 | __ xorl(out, out); |
| 2776 | __ jmp(&end); |
| 2777 | |
| 2778 | __ Bind(&ndiv); |
| 2779 | |
| 2780 | // Save the numerator. |
| 2781 | __ movl(num, eax); |
| 2782 | |
| 2783 | // EAX = magic |
| 2784 | __ movl(eax, Immediate(magic)); |
| 2785 | |
| 2786 | // EDX:EAX = magic * numerator |
| 2787 | __ imull(num); |
| 2788 | |
| 2789 | if (imm > 0 && magic < 0) { |
| 2790 | // EDX += num |
| 2791 | __ addl(edx, num); |
| 2792 | } else if (imm < 0 && magic > 0) { |
| 2793 | __ subl(edx, num); |
| 2794 | } |
| 2795 | |
| 2796 | // Shift if needed. |
| 2797 | if (shift != 0) { |
| 2798 | __ sarl(edx, Immediate(shift)); |
| 2799 | } |
| 2800 | |
| 2801 | // EDX += 1 if EDX < 0 |
| 2802 | __ movl(eax, edx); |
| 2803 | __ shrl(edx, Immediate(31)); |
| 2804 | __ addl(edx, eax); |
| 2805 | |
| 2806 | if (instruction->IsRem()) { |
| 2807 | __ movl(eax, num); |
| 2808 | __ imull(edx, Immediate(imm)); |
| 2809 | __ subl(eax, edx); |
| 2810 | __ movl(edx, eax); |
| 2811 | } else { |
| 2812 | __ movl(eax, edx); |
| 2813 | } |
| 2814 | __ Bind(&end); |
| 2815 | } |
| 2816 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2817 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2818 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2819 | |
| 2820 | LocationSummary* locations = instruction->GetLocations(); |
| 2821 | Location out = locations->Out(); |
| 2822 | Location first = locations->InAt(0); |
| 2823 | Location second = locations->InAt(1); |
| 2824 | bool is_div = instruction->IsDiv(); |
| 2825 | |
| 2826 | switch (instruction->GetResultType()) { |
| 2827 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2828 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2829 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2830 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2831 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2832 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2833 | |
| 2834 | if (imm == 0) { |
| 2835 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2836 | } else if (imm == 1 || imm == -1) { |
| 2837 | DivRemOneOrMinusOne(instruction); |
| 2838 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2839 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2840 | } else { |
| 2841 | DCHECK(imm <= -2 || imm >= 2); |
| 2842 | GenerateDivRemWithAnyConstant(instruction); |
| 2843 | } |
| 2844 | } else { |
| 2845 | SlowPathCodeX86* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2846 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2847 | is_div); |
| 2848 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2849 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2850 | Register second_reg = second.AsRegister<Register>(); |
| 2851 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2852 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2853 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2854 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2855 | __ cmpl(second_reg, Immediate(-1)); |
| 2856 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2857 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2858 | // edx:eax <- sign-extended of eax |
| 2859 | __ cdq(); |
| 2860 | // eax = quotient, edx = remainder |
| 2861 | __ idivl(second_reg); |
| 2862 | __ Bind(slow_path->GetExitLabel()); |
| 2863 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2864 | break; |
| 2865 | } |
| 2866 | |
| 2867 | case Primitive::kPrimLong: { |
| 2868 | InvokeRuntimeCallingConvention calling_convention; |
| 2869 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2870 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2871 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2872 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2873 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2874 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2875 | |
| 2876 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2877 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2878 | instruction, |
| 2879 | instruction->GetDexPc(), |
| 2880 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2881 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2882 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 2883 | instruction, |
| 2884 | instruction->GetDexPc(), |
| 2885 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2886 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2887 | break; |
| 2888 | } |
| 2889 | |
| 2890 | default: |
| 2891 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 2892 | } |
| 2893 | } |
| 2894 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2895 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2896 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2897 | ? LocationSummary::kCall |
| 2898 | : LocationSummary::kNoCall; |
| 2899 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2900 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2901 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2902 | case Primitive::kPrimInt: { |
| 2903 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2904 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2905 | locations->SetOut(Location::SameAsFirstInput()); |
| 2906 | // Intel uses edx:eax as the dividend. |
| 2907 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2908 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2909 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 2910 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2911 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2912 | locations->AddTemp(Location::RequiresRegister()); |
| 2913 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2914 | break; |
| 2915 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2916 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2917 | InvokeRuntimeCallingConvention calling_convention; |
| 2918 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2919 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2920 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2921 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2922 | // Runtime helper puts the result in EAX, EDX. |
| 2923 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2924 | break; |
| 2925 | } |
| 2926 | case Primitive::kPrimFloat: |
| 2927 | case Primitive::kPrimDouble: { |
| 2928 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2929 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2930 | locations->SetOut(Location::SameAsFirstInput()); |
| 2931 | break; |
| 2932 | } |
| 2933 | |
| 2934 | default: |
| 2935 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 2940 | LocationSummary* locations = div->GetLocations(); |
| 2941 | Location first = locations->InAt(0); |
| 2942 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2943 | |
| 2944 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2945 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2946 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2947 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | } |
| 2950 | |
| 2951 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2952 | if (second.IsFpuRegister()) { |
| 2953 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2954 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2955 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2956 | DCHECK(!const_area->NeedsMaterialization()); |
| 2957 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 2958 | codegen_->LiteralFloatAddress( |
| 2959 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2960 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2961 | } else { |
| 2962 | DCHECK(second.IsStackSlot()); |
| 2963 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2964 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2965 | break; |
| 2966 | } |
| 2967 | |
| 2968 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 2969 | if (second.IsFpuRegister()) { |
| 2970 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2971 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2972 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2973 | DCHECK(!const_area->NeedsMaterialization()); |
| 2974 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 2975 | codegen_->LiteralDoubleAddress( |
| 2976 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2977 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2978 | } else { |
| 2979 | DCHECK(second.IsDoubleStackSlot()); |
| 2980 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2981 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2982 | break; |
| 2983 | } |
| 2984 | |
| 2985 | default: |
| 2986 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2987 | } |
| 2988 | } |
| 2989 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2990 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2991 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2992 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2993 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 2994 | ? LocationSummary::kCall |
| 2995 | : LocationSummary::kNoCall; |
| 2996 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2997 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2998 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2999 | case Primitive::kPrimInt: { |
| 3000 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3001 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3002 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3003 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3004 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3005 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3006 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3007 | locations->AddTemp(Location::RequiresRegister()); |
| 3008 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3009 | break; |
| 3010 | } |
| 3011 | case Primitive::kPrimLong: { |
| 3012 | InvokeRuntimeCallingConvention calling_convention; |
| 3013 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3014 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3015 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3016 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3017 | // Runtime helper puts the result in EAX, EDX. |
| 3018 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3019 | break; |
| 3020 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3021 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3022 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3023 | locations->SetInAt(0, Location::Any()); |
| 3024 | locations->SetInAt(1, Location::Any()); |
| 3025 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3026 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3027 | break; |
| 3028 | } |
| 3029 | |
| 3030 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3031 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3036 | Primitive::Type type = rem->GetResultType(); |
| 3037 | switch (type) { |
| 3038 | case Primitive::kPrimInt: |
| 3039 | case Primitive::kPrimLong: { |
| 3040 | GenerateDivRemIntegral(rem); |
| 3041 | break; |
| 3042 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3043 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3044 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3045 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3046 | break; |
| 3047 | } |
| 3048 | default: |
| 3049 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3050 | } |
| 3051 | } |
| 3052 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3053 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3054 | LocationSummary* locations = |
| 3055 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3056 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3057 | case Primitive::kPrimByte: |
| 3058 | case Primitive::kPrimChar: |
| 3059 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3060 | case Primitive::kPrimInt: { |
| 3061 | locations->SetInAt(0, Location::Any()); |
| 3062 | break; |
| 3063 | } |
| 3064 | case Primitive::kPrimLong: { |
| 3065 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3066 | if (!instruction->IsConstant()) { |
| 3067 | locations->AddTemp(Location::RequiresRegister()); |
| 3068 | } |
| 3069 | break; |
| 3070 | } |
| 3071 | default: |
| 3072 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3073 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3074 | if (instruction->HasUses()) { |
| 3075 | locations->SetOut(Location::SameAsFirstInput()); |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3080 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 3081 | codegen_->AddSlowPath(slow_path); |
| 3082 | |
| 3083 | LocationSummary* locations = instruction->GetLocations(); |
| 3084 | Location value = locations->InAt(0); |
| 3085 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3086 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3087 | case Primitive::kPrimByte: |
| 3088 | case Primitive::kPrimChar: |
| 3089 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3090 | case Primitive::kPrimInt: { |
| 3091 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3092 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3093 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3094 | } else if (value.IsStackSlot()) { |
| 3095 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3096 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3097 | } else { |
| 3098 | DCHECK(value.IsConstant()) << value; |
| 3099 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3100 | __ jmp(slow_path->GetEntryLabel()); |
| 3101 | } |
| 3102 | } |
| 3103 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3104 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3105 | case Primitive::kPrimLong: { |
| 3106 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3107 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3108 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3109 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3110 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3111 | } else { |
| 3112 | DCHECK(value.IsConstant()) << value; |
| 3113 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3114 | __ jmp(slow_path->GetEntryLabel()); |
| 3115 | } |
| 3116 | } |
| 3117 | break; |
| 3118 | } |
| 3119 | default: |
| 3120 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3121 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3124 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3125 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3126 | |
| 3127 | LocationSummary* locations = |
| 3128 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3129 | |
| 3130 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3131 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3132 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3133 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3134 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3135 | // The shift count needs to be in CL or a constant. |
| 3136 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3137 | locations->SetOut(Location::SameAsFirstInput()); |
| 3138 | break; |
| 3139 | } |
| 3140 | default: |
| 3141 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3142 | } |
| 3143 | } |
| 3144 | |
| 3145 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3146 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3147 | |
| 3148 | LocationSummary* locations = op->GetLocations(); |
| 3149 | Location first = locations->InAt(0); |
| 3150 | Location second = locations->InAt(1); |
| 3151 | DCHECK(first.Equals(locations->Out())); |
| 3152 | |
| 3153 | switch (op->GetResultType()) { |
| 3154 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3155 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3156 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3157 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3158 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3159 | DCHECK_EQ(ECX, second_reg); |
| 3160 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3161 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3162 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3163 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3164 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3165 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3166 | } |
| 3167 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3168 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3169 | if (shift == 0) { |
| 3170 | return; |
| 3171 | } |
| 3172 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3173 | if (op->IsShl()) { |
| 3174 | __ shll(first_reg, imm); |
| 3175 | } else if (op->IsShr()) { |
| 3176 | __ sarl(first_reg, imm); |
| 3177 | } else { |
| 3178 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3179 | } |
| 3180 | } |
| 3181 | break; |
| 3182 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3183 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3184 | if (second.IsRegister()) { |
| 3185 | Register second_reg = second.AsRegister<Register>(); |
| 3186 | DCHECK_EQ(ECX, second_reg); |
| 3187 | if (op->IsShl()) { |
| 3188 | GenerateShlLong(first, second_reg); |
| 3189 | } else if (op->IsShr()) { |
| 3190 | GenerateShrLong(first, second_reg); |
| 3191 | } else { |
| 3192 | GenerateUShrLong(first, second_reg); |
| 3193 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3194 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3195 | // Shift by a constant. |
| 3196 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3197 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3198 | if (shift != 0) { |
| 3199 | if (op->IsShl()) { |
| 3200 | GenerateShlLong(first, shift); |
| 3201 | } else if (op->IsShr()) { |
| 3202 | GenerateShrLong(first, shift); |
| 3203 | } else { |
| 3204 | GenerateUShrLong(first, shift); |
| 3205 | } |
| 3206 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3207 | } |
| 3208 | break; |
| 3209 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3210 | default: |
| 3211 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3212 | } |
| 3213 | } |
| 3214 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3215 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3216 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3217 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3218 | if (shift == 1) { |
| 3219 | // This is just an addition. |
| 3220 | __ addl(low, low); |
| 3221 | __ adcl(high, high); |
| 3222 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3223 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3224 | codegen_->EmitParallelMoves( |
| 3225 | loc.ToLow(), |
| 3226 | loc.ToHigh(), |
| 3227 | Primitive::kPrimInt, |
| 3228 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3229 | loc.ToLow(), |
| 3230 | Primitive::kPrimInt); |
| 3231 | } else if (shift > 32) { |
| 3232 | // Low part becomes 0. High part is low part << (shift-32). |
| 3233 | __ movl(high, low); |
| 3234 | __ shll(high, Immediate(shift - 32)); |
| 3235 | __ xorl(low, low); |
| 3236 | } else { |
| 3237 | // Between 1 and 31. |
| 3238 | __ shld(high, low, Immediate(shift)); |
| 3239 | __ shll(low, Immediate(shift)); |
| 3240 | } |
| 3241 | } |
| 3242 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3243 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| 3244 | Label done; |
| 3245 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3246 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3247 | __ testl(shifter, Immediate(32)); |
| 3248 | __ j(kEqual, &done); |
| 3249 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3250 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3251 | __ Bind(&done); |
| 3252 | } |
| 3253 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3254 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3255 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3256 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3257 | if (shift == 32) { |
| 3258 | // Need to copy the sign. |
| 3259 | DCHECK_NE(low, high); |
| 3260 | __ movl(low, high); |
| 3261 | __ sarl(high, Immediate(31)); |
| 3262 | } else if (shift > 32) { |
| 3263 | DCHECK_NE(low, high); |
| 3264 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3265 | __ movl(low, high); |
| 3266 | __ sarl(high, Immediate(31)); |
| 3267 | __ sarl(low, Immediate(shift - 32)); |
| 3268 | } else { |
| 3269 | // Between 1 and 31. |
| 3270 | __ shrd(low, high, Immediate(shift)); |
| 3271 | __ sarl(high, Immediate(shift)); |
| 3272 | } |
| 3273 | } |
| 3274 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3275 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| 3276 | Label done; |
| 3277 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3278 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3279 | __ testl(shifter, Immediate(32)); |
| 3280 | __ j(kEqual, &done); |
| 3281 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3282 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3283 | __ Bind(&done); |
| 3284 | } |
| 3285 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3286 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3287 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3288 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3289 | if (shift == 32) { |
| 3290 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3291 | codegen_->EmitParallelMoves( |
| 3292 | loc.ToHigh(), |
| 3293 | loc.ToLow(), |
| 3294 | Primitive::kPrimInt, |
| 3295 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3296 | loc.ToHigh(), |
| 3297 | Primitive::kPrimInt); |
| 3298 | } else if (shift > 32) { |
| 3299 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3300 | __ movl(low, high); |
| 3301 | __ shrl(low, Immediate(shift - 32)); |
| 3302 | __ xorl(high, high); |
| 3303 | } else { |
| 3304 | // Between 1 and 31. |
| 3305 | __ shrd(low, high, Immediate(shift)); |
| 3306 | __ shrl(high, Immediate(shift)); |
| 3307 | } |
| 3308 | } |
| 3309 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3310 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| 3311 | Label done; |
| 3312 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3313 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3314 | __ testl(shifter, Immediate(32)); |
| 3315 | __ j(kEqual, &done); |
| 3316 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3317 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3318 | __ Bind(&done); |
| 3319 | } |
| 3320 | |
| 3321 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3322 | HandleShift(shl); |
| 3323 | } |
| 3324 | |
| 3325 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3326 | HandleShift(shl); |
| 3327 | } |
| 3328 | |
| 3329 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3330 | HandleShift(shr); |
| 3331 | } |
| 3332 | |
| 3333 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3334 | HandleShift(shr); |
| 3335 | } |
| 3336 | |
| 3337 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3338 | HandleShift(ushr); |
| 3339 | } |
| 3340 | |
| 3341 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3342 | HandleShift(ushr); |
| 3343 | } |
| 3344 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3345 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3346 | LocationSummary* locations = |
| 3347 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3348 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3349 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3350 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3351 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 3355 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3356 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3357 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3358 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3359 | codegen_->InvokeRuntime( |
| 3360 | Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint())), |
| 3361 | instruction, |
| 3362 | instruction->GetDexPc(), |
| 3363 | nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3364 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3365 | } |
| 3366 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3367 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3368 | LocationSummary* locations = |
| 3369 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3370 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3371 | InvokeRuntimeCallingConvention calling_convention; |
| 3372 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3373 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3374 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3378 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3379 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 3380 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3381 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3382 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3383 | codegen_->InvokeRuntime( |
| 3384 | Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint())), |
| 3385 | instruction, |
| 3386 | instruction->GetDexPc(), |
| 3387 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3388 | DCHECK(!codegen_->IsLeafMethod()); |
| 3389 | } |
| 3390 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3391 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3392 | LocationSummary* locations = |
| 3393 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3394 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3395 | if (location.IsStackSlot()) { |
| 3396 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3397 | } else if (location.IsDoubleStackSlot()) { |
| 3398 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3399 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3400 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3401 | } |
| 3402 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3403 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3404 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3405 | } |
| 3406 | |
| 3407 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3408 | LocationSummary* locations = |
| 3409 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3410 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3411 | } |
| 3412 | |
| 3413 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3414 | } |
| 3415 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3416 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3417 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3418 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3419 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3420 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3421 | } |
| 3422 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3423 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3424 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3425 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3426 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3427 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3428 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3429 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3430 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3431 | break; |
| 3432 | |
| 3433 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3434 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3435 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3436 | break; |
| 3437 | |
| 3438 | default: |
| 3439 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3440 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3441 | } |
| 3442 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3443 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3444 | LocationSummary* locations = |
| 3445 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3446 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3447 | locations->SetOut(Location::SameAsFirstInput()); |
| 3448 | } |
| 3449 | |
| 3450 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3451 | LocationSummary* locations = bool_not->GetLocations(); |
| 3452 | Location in = locations->InAt(0); |
| 3453 | Location out = locations->Out(); |
| 3454 | DCHECK(in.Equals(out)); |
| 3455 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3456 | } |
| 3457 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3458 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3459 | LocationSummary* locations = |
| 3460 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3461 | switch (compare->InputAt(0)->GetType()) { |
| 3462 | case Primitive::kPrimLong: { |
| 3463 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3464 | locations->SetInAt(1, Location::Any()); |
| 3465 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3466 | break; |
| 3467 | } |
| 3468 | case Primitive::kPrimFloat: |
| 3469 | case Primitive::kPrimDouble: { |
| 3470 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3471 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3472 | locations->SetOut(Location::RequiresRegister()); |
| 3473 | break; |
| 3474 | } |
| 3475 | default: |
| 3476 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3477 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3481 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3482 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3483 | Location left = locations->InAt(0); |
| 3484 | Location right = locations->InAt(1); |
| 3485 | |
| 3486 | Label less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3487 | switch (compare->InputAt(0)->GetType()) { |
| 3488 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3489 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 3490 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 3491 | int32_t val_low = 0; |
| 3492 | int32_t val_high = 0; |
| 3493 | bool right_is_const = false; |
| 3494 | |
| 3495 | if (right.IsConstant()) { |
| 3496 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 3497 | right_is_const = true; |
| 3498 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 3499 | val_low = Low32Bits(val); |
| 3500 | val_high = High32Bits(val); |
| 3501 | } |
| 3502 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3503 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3504 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3505 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3506 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3507 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3508 | DCHECK(right_is_const) << right; |
| 3509 | if (val_high == 0) { |
| 3510 | __ testl(left_high, left_high); |
| 3511 | } else { |
| 3512 | __ cmpl(left_high, Immediate(val_high)); |
| 3513 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3514 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3515 | __ j(kLess, &less); // Signed compare. |
| 3516 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3517 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3518 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3519 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3520 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3521 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3522 | DCHECK(right_is_const) << right; |
| 3523 | if (val_low == 0) { |
| 3524 | __ testl(left_low, left_low); |
| 3525 | } else { |
| 3526 | __ cmpl(left_low, Immediate(val_low)); |
| 3527 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3528 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3529 | break; |
| 3530 | } |
| 3531 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3532 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3533 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3534 | break; |
| 3535 | } |
| 3536 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3537 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3538 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3539 | break; |
| 3540 | } |
| 3541 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3542 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3543 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3544 | __ movl(out, Immediate(0)); |
| 3545 | __ j(kEqual, &done); |
| 3546 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3547 | |
| 3548 | __ Bind(&greater); |
| 3549 | __ movl(out, Immediate(1)); |
| 3550 | __ jmp(&done); |
| 3551 | |
| 3552 | __ Bind(&less); |
| 3553 | __ movl(out, Immediate(-1)); |
| 3554 | |
| 3555 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3556 | } |
| 3557 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3558 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3559 | LocationSummary* locations = |
| 3560 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3561 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3562 | locations->SetInAt(i, Location::Any()); |
| 3563 | } |
| 3564 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3568 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3569 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3570 | } |
| 3571 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3572 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3573 | /* |
| 3574 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3575 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3576 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3577 | */ |
| 3578 | switch (kind) { |
| 3579 | case MemBarrierKind::kAnyAny: { |
| 3580 | __ mfence(); |
| 3581 | break; |
| 3582 | } |
| 3583 | case MemBarrierKind::kAnyStore: |
| 3584 | case MemBarrierKind::kLoadAny: |
| 3585 | case MemBarrierKind::kStoreStore: { |
| 3586 | // nop |
| 3587 | break; |
| 3588 | } |
| 3589 | default: |
| 3590 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3591 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3592 | } |
| 3593 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3594 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3595 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 3596 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3597 | switch (invoke->GetMethodLoadKind()) { |
| 3598 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3599 | // temp = thread->string_init_entrypoint |
| 3600 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 3601 | break; |
| 3602 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 3603 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3604 | break; |
| 3605 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3606 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 3607 | break; |
| 3608 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3609 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 3610 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3611 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 3612 | break; |
| 3613 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 3614 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 3615 | FALLTHROUGH_INTENDED; |
| 3616 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 3617 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3618 | Register method_reg; |
| 3619 | Register reg = temp.AsRegister<Register>(); |
| 3620 | if (current_method.IsRegister()) { |
| 3621 | method_reg = current_method.AsRegister<Register>(); |
| 3622 | } else { |
| 3623 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 3624 | DCHECK(!current_method.IsValid()); |
| 3625 | method_reg = reg; |
| 3626 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 3627 | } |
| 3628 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3629 | __ movl(reg, Address(method_reg, |
| 3630 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3631 | // temp = temp[index_in_cache] |
| 3632 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3633 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 3634 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3635 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | switch (invoke->GetCodePtrLocation()) { |
| 3639 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3640 | __ call(GetFrameEntryLabel()); |
| 3641 | break; |
| 3642 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3643 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3644 | Label* label = &relative_call_patches_.back().label; |
| 3645 | __ call(label); // Bind to the patch label, override at link time. |
| 3646 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 3647 | break; |
| 3648 | } |
| 3649 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3650 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3651 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 3652 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 3653 | FALLTHROUGH_INTENDED; |
| 3654 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3655 | // (callee_method + offset_of_quick_compiled_code)() |
| 3656 | __ call(Address(callee_method.AsRegister<Register>(), |
| 3657 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3658 | kX86WordSize).Int32Value())); |
| 3659 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3663 | } |
| 3664 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3665 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3666 | DCHECK(linker_patches->empty()); |
| 3667 | linker_patches->reserve(method_patches_.size() + relative_call_patches_.size()); |
| 3668 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 3669 | // The label points to the end of the "movl" insn but the literal offset for method |
| 3670 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3671 | uint32_t literal_offset = info.label.Position() - 4; |
| 3672 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 3673 | info.target_method.dex_file, |
| 3674 | info.target_method.dex_method_index)); |
| 3675 | } |
| 3676 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 3677 | // The label points to the end of the "call" insn but the literal offset for method |
| 3678 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3679 | uint32_t literal_offset = info.label.Position() - 4; |
| 3680 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 3681 | info.target_method.dex_file, |
| 3682 | info.target_method.dex_method_index)); |
| 3683 | } |
| 3684 | } |
| 3685 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3686 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 3687 | Register card, |
| 3688 | Register object, |
| 3689 | Register value, |
| 3690 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3691 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3692 | if (value_can_be_null) { |
| 3693 | __ testl(value, value); |
| 3694 | __ j(kEqual, &is_null); |
| 3695 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3696 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3697 | __ movl(temp, object); |
| 3698 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3699 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3700 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3701 | if (value_can_be_null) { |
| 3702 | __ Bind(&is_null); |
| 3703 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3704 | } |
| 3705 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3706 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3707 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3708 | LocationSummary* locations = |
| 3709 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3710 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3711 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3712 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3713 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3714 | } else { |
| 3715 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3716 | // the object's location. |
| 3717 | locations->SetOut(Location::RequiresRegister(), |
| 3718 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3719 | : Location::kNoOutputOverlap); |
| 3720 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3721 | |
| 3722 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3723 | // Long values can be loaded atomically into an XMM using movsd. |
| 3724 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3725 | // and then copy the XMM into the output 32bits at a time). |
| 3726 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3727 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3728 | } |
| 3729 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3730 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3731 | const FieldInfo& field_info) { |
| 3732 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3733 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3734 | LocationSummary* locations = instruction->GetLocations(); |
| 3735 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3736 | Location out = locations->Out(); |
| 3737 | bool is_volatile = field_info.IsVolatile(); |
| 3738 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3739 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3740 | |
| 3741 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3742 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3743 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3744 | break; |
| 3745 | } |
| 3746 | |
| 3747 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3748 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3749 | break; |
| 3750 | } |
| 3751 | |
| 3752 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3753 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3754 | break; |
| 3755 | } |
| 3756 | |
| 3757 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3758 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3759 | break; |
| 3760 | } |
| 3761 | |
| 3762 | case Primitive::kPrimInt: |
| 3763 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3764 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3765 | break; |
| 3766 | } |
| 3767 | |
| 3768 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3769 | if (is_volatile) { |
| 3770 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3771 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3772 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3773 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3774 | __ psrlq(temp, Immediate(32)); |
| 3775 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3776 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3777 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3778 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3779 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3780 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3781 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3782 | break; |
| 3783 | } |
| 3784 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3785 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3786 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3787 | break; |
| 3788 | } |
| 3789 | |
| 3790 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3791 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3792 | break; |
| 3793 | } |
| 3794 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3795 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3796 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3797 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3798 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3799 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3800 | // Longs are handled in the switch. |
| 3801 | if (field_type != Primitive::kPrimLong) { |
| 3802 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3803 | } |
| 3804 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3805 | if (is_volatile) { |
| 3806 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3807 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3808 | |
| 3809 | if (field_type == Primitive::kPrimNot) { |
| 3810 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3811 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3815 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3816 | |
| 3817 | LocationSummary* locations = |
| 3818 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3819 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3820 | bool is_volatile = field_info.IsVolatile(); |
| 3821 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3822 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3823 | || (field_type == Primitive::kPrimByte); |
| 3824 | |
| 3825 | // The register allocator does not support multiple |
| 3826 | // inputs that die at entry with one in a specific register. |
| 3827 | if (is_byte_type) { |
| 3828 | // Ensure the value is in a byte register. |
| 3829 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3830 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3831 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3832 | } else { |
| 3833 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3834 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3835 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3836 | // Temporary registers for the write barrier. |
| 3837 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3838 | // Ensure the card is in a byte register. |
| 3839 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3840 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3841 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3842 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3843 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3844 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3845 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3846 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3847 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3852 | const FieldInfo& field_info, |
| 3853 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3854 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3855 | |
| 3856 | LocationSummary* locations = instruction->GetLocations(); |
| 3857 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3858 | Location value = locations->InAt(1); |
| 3859 | bool is_volatile = field_info.IsVolatile(); |
| 3860 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3861 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3862 | bool needs_write_barrier = |
| 3863 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3864 | |
| 3865 | if (is_volatile) { |
| 3866 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3867 | } |
| 3868 | |
| 3869 | switch (field_type) { |
| 3870 | case Primitive::kPrimBoolean: |
| 3871 | case Primitive::kPrimByte: { |
| 3872 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 3873 | break; |
| 3874 | } |
| 3875 | |
| 3876 | case Primitive::kPrimShort: |
| 3877 | case Primitive::kPrimChar: { |
| 3878 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 3879 | break; |
| 3880 | } |
| 3881 | |
| 3882 | case Primitive::kPrimInt: |
| 3883 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3884 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3885 | // Note that in the case where `value` is a null reference, |
| 3886 | // we do not enter this block, as the reference does not |
| 3887 | // need poisoning. |
| 3888 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3889 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3890 | __ movl(temp, value.AsRegister<Register>()); |
| 3891 | __ PoisonHeapReference(temp); |
| 3892 | __ movl(Address(base, offset), temp); |
| 3893 | } else { |
| 3894 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 3895 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3896 | break; |
| 3897 | } |
| 3898 | |
| 3899 | case Primitive::kPrimLong: { |
| 3900 | if (is_volatile) { |
| 3901 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3902 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 3903 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 3904 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 3905 | __ punpckldq(temp1, temp2); |
| 3906 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3907 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3908 | } else { |
| 3909 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3910 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3911 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 3912 | } |
| 3913 | break; |
| 3914 | } |
| 3915 | |
| 3916 | case Primitive::kPrimFloat: { |
| 3917 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3918 | break; |
| 3919 | } |
| 3920 | |
| 3921 | case Primitive::kPrimDouble: { |
| 3922 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3923 | break; |
| 3924 | } |
| 3925 | |
| 3926 | case Primitive::kPrimVoid: |
| 3927 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3928 | UNREACHABLE(); |
| 3929 | } |
| 3930 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3931 | // Longs are handled in the switch. |
| 3932 | if (field_type != Primitive::kPrimLong) { |
| 3933 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3934 | } |
| 3935 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3936 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3937 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3938 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3939 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3942 | if (is_volatile) { |
| 3943 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3948 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3949 | } |
| 3950 | |
| 3951 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3952 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3953 | } |
| 3954 | |
| 3955 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3956 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3957 | } |
| 3958 | |
| 3959 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3960 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3964 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3965 | } |
| 3966 | |
| 3967 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3968 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3972 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3973 | } |
| 3974 | |
| 3975 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3976 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3980 | LocationSummary* locations = |
| 3981 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3982 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3983 | ? Location::RequiresRegister() |
| 3984 | : Location::Any(); |
| 3985 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3986 | if (instruction->HasUses()) { |
| 3987 | locations->SetOut(Location::SameAsFirstInput()); |
| 3988 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3989 | } |
| 3990 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3991 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3992 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3993 | return; |
| 3994 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3995 | LocationSummary* locations = instruction->GetLocations(); |
| 3996 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3997 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3998 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 3999 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4000 | } |
| 4001 | |
| 4002 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 4003 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4004 | codegen_->AddSlowPath(slow_path); |
| 4005 | |
| 4006 | LocationSummary* locations = instruction->GetLocations(); |
| 4007 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4008 | |
| 4009 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4010 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4011 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4012 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4013 | } else { |
| 4014 | DCHECK(obj.IsConstant()) << obj; |
| 4015 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 4016 | __ jmp(slow_path->GetEntryLabel()); |
| 4017 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4018 | } |
| 4019 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4020 | } |
| 4021 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4022 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| 4023 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 4024 | GenerateImplicitNullCheck(instruction); |
| 4025 | } else { |
| 4026 | GenerateExplicitNullCheck(instruction); |
| 4027 | } |
| 4028 | } |
| 4029 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4030 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4031 | LocationSummary* locations = |
| 4032 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4033 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4034 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4035 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4036 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4037 | } else { |
| 4038 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 4039 | // the array's location. |
| 4040 | locations->SetOut(Location::RequiresRegister(), |
| 4041 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 4042 | : Location::kNoOutputOverlap); |
| 4043 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4047 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4048 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4049 | Location index = locations->InAt(1); |
| 4050 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4051 | Primitive::Type type = instruction->GetType(); |
| 4052 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4053 | case Primitive::kPrimBoolean: { |
| 4054 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4055 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4056 | if (index.IsConstant()) { |
| 4057 | __ movzxb(out, Address(obj, |
| 4058 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4059 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4060 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4061 | } |
| 4062 | break; |
| 4063 | } |
| 4064 | |
| 4065 | case Primitive::kPrimByte: { |
| 4066 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4067 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4068 | if (index.IsConstant()) { |
| 4069 | __ movsxb(out, Address(obj, |
| 4070 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4071 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4072 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4073 | } |
| 4074 | break; |
| 4075 | } |
| 4076 | |
| 4077 | case Primitive::kPrimShort: { |
| 4078 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4079 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4080 | if (index.IsConstant()) { |
| 4081 | __ movsxw(out, Address(obj, |
| 4082 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4083 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4084 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4085 | } |
| 4086 | break; |
| 4087 | } |
| 4088 | |
| 4089 | case Primitive::kPrimChar: { |
| 4090 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4091 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4092 | if (index.IsConstant()) { |
| 4093 | __ movzxw(out, Address(obj, |
| 4094 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4095 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4096 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4097 | } |
| 4098 | break; |
| 4099 | } |
| 4100 | |
| 4101 | case Primitive::kPrimInt: |
| 4102 | case Primitive::kPrimNot: { |
| 4103 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4104 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4105 | if (index.IsConstant()) { |
| 4106 | __ movl(out, Address(obj, |
| 4107 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4108 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4109 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4110 | } |
| 4111 | break; |
| 4112 | } |
| 4113 | |
| 4114 | case Primitive::kPrimLong: { |
| 4115 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4116 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4117 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4118 | if (index.IsConstant()) { |
| 4119 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4120 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4121 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4122 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4123 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4124 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4125 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4126 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4127 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4128 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4129 | } |
| 4130 | break; |
| 4131 | } |
| 4132 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4133 | case Primitive::kPrimFloat: { |
| 4134 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4135 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4136 | if (index.IsConstant()) { |
| 4137 | __ movss(out, Address(obj, |
| 4138 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4139 | } else { |
| 4140 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4141 | } |
| 4142 | break; |
| 4143 | } |
| 4144 | |
| 4145 | case Primitive::kPrimDouble: { |
| 4146 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4147 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4148 | if (index.IsConstant()) { |
| 4149 | __ movsd(out, Address(obj, |
| 4150 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4151 | } else { |
| 4152 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 4153 | } |
| 4154 | break; |
| 4155 | } |
| 4156 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4157 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4158 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4159 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4160 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4161 | |
| 4162 | if (type != Primitive::kPrimLong) { |
| 4163 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4164 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4165 | |
| 4166 | if (type == Primitive::kPrimNot) { |
| 4167 | Register out = locations->Out().AsRegister<Register>(); |
| 4168 | __ MaybeUnpoisonHeapReference(out); |
| 4169 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4170 | } |
| 4171 | |
| 4172 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4173 | // This location builder might end up asking to up to four registers, which is |
| 4174 | // not currently possible for baseline. The situation in which we need four |
| 4175 | // registers cannot be met by baseline though, because it has not run any |
| 4176 | // optimization. |
| 4177 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4178 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4179 | bool needs_write_barrier = |
| 4180 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 4181 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4182 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4183 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4184 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4185 | instruction, |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4186 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4187 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4188 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4189 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4190 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4191 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4192 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4193 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4194 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4195 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4196 | // 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] | 4197 | // In case of a byte operation, the register allocator does not support multiple |
| 4198 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4199 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4200 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4201 | if (is_byte_type) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4202 | // Ensure the value is in a byte register. |
| 4203 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4204 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 4205 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4206 | } else { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4207 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4208 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4209 | if (needs_write_barrier) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4210 | // Temporary registers for the write barrier. |
| 4211 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4212 | // Ensure the card is in a byte register. |
| 4213 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4214 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4215 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4219 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4220 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4221 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4222 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4223 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4224 | bool needs_runtime_call = locations->WillCall(); |
| 4225 | bool needs_write_barrier = |
| 4226 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4227 | |
| 4228 | switch (value_type) { |
| 4229 | case Primitive::kPrimBoolean: |
| 4230 | case Primitive::kPrimByte: { |
| 4231 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4232 | if (index.IsConstant()) { |
| 4233 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4234 | if (value.IsRegister()) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4235 | __ movb(Address(obj, offset), value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4236 | } else { |
| 4237 | __ movb(Address(obj, offset), |
| 4238 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4239 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4240 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4241 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4242 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4243 | value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4244 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4245 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4246 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4247 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4248 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4249 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4250 | break; |
| 4251 | } |
| 4252 | |
| 4253 | case Primitive::kPrimShort: |
| 4254 | case Primitive::kPrimChar: { |
| 4255 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4256 | if (index.IsConstant()) { |
| 4257 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4258 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4259 | __ movw(Address(obj, offset), value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4260 | } else { |
| 4261 | __ movw(Address(obj, offset), |
| 4262 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4263 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4264 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4265 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4266 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
| 4267 | value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4268 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4269 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4270 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4271 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4272 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4273 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4274 | break; |
| 4275 | } |
| 4276 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4277 | case Primitive::kPrimInt: |
| 4278 | case Primitive::kPrimNot: { |
| 4279 | if (!needs_runtime_call) { |
| 4280 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4281 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4282 | size_t offset = |
| 4283 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4284 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4285 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4286 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4287 | __ movl(temp, value.AsRegister<Register>()); |
| 4288 | __ PoisonHeapReference(temp); |
| 4289 | __ movl(Address(obj, offset), temp); |
| 4290 | } else { |
| 4291 | __ movl(Address(obj, offset), value.AsRegister<Register>()); |
| 4292 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4293 | } else { |
| 4294 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4295 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4296 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4297 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4298 | // Note: if heap poisoning is enabled, no need to poison |
| 4299 | // (negate) `v` if it is a reference, as it would be null. |
| 4300 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4301 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4302 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4303 | DCHECK(index.IsRegister()) << index; |
| 4304 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4305 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4306 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4307 | __ movl(temp, value.AsRegister<Register>()); |
| 4308 | __ PoisonHeapReference(temp); |
| 4309 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), temp); |
| 4310 | } else { |
| 4311 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4312 | value.AsRegister<Register>()); |
| 4313 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4314 | } else { |
| 4315 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4316 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4317 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4318 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4319 | // Note: if heap poisoning is enabled, no need to poison |
| 4320 | // (negate) `v` if it is a reference, as it would be null. |
| 4321 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4322 | } |
| 4323 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4324 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4325 | |
| 4326 | if (needs_write_barrier) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4327 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4328 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4329 | codegen_->MarkGCCard( |
| 4330 | temp, card, obj, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4331 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4332 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4333 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4334 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4335 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4336 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4337 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4338 | instruction, |
| 4339 | instruction->GetDexPc(), |
| 4340 | nullptr); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4341 | } |
| 4342 | break; |
| 4343 | } |
| 4344 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4345 | case Primitive::kPrimLong: { |
| 4346 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4347 | if (index.IsConstant()) { |
| 4348 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4349 | if (value.IsRegisterPair()) { |
| 4350 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4351 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4352 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4353 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4354 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4355 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4356 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4357 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4358 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 4359 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4360 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4361 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4362 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4363 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4364 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4365 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4366 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4367 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4368 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4369 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4370 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4371 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4372 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4373 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4374 | Immediate(High32Bits(val))); |
| 4375 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4376 | } |
| 4377 | break; |
| 4378 | } |
| 4379 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4380 | case Primitive::kPrimFloat: { |
| 4381 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4382 | DCHECK(value.IsFpuRegister()); |
| 4383 | if (index.IsConstant()) { |
| 4384 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4385 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4386 | } else { |
| 4387 | __ movss(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4388 | value.AsFpuRegister<XmmRegister>()); |
| 4389 | } |
| 4390 | break; |
| 4391 | } |
| 4392 | |
| 4393 | case Primitive::kPrimDouble: { |
| 4394 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4395 | DCHECK(value.IsFpuRegister()); |
| 4396 | if (index.IsConstant()) { |
| 4397 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4398 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4399 | } else { |
| 4400 | __ movsd(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
| 4401 | value.AsFpuRegister<XmmRegister>()); |
| 4402 | } |
| 4403 | break; |
| 4404 | } |
| 4405 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4406 | case Primitive::kPrimVoid: |
| 4407 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4408 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 4413 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4414 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4415 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 4419 | LocationSummary* locations = instruction->GetLocations(); |
| 4420 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4421 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4422 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4423 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4424 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4428 | LocationSummary* locations = |
| 4429 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4430 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4431 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4432 | if (instruction->HasUses()) { |
| 4433 | locations->SetOut(Location::SameAsFirstInput()); |
| 4434 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4438 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4439 | Location index_loc = locations->InAt(0); |
| 4440 | Location length_loc = locations->InAt(1); |
| 4441 | SlowPathCodeX86* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4442 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4443 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4444 | if (length_loc.IsConstant()) { |
| 4445 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4446 | if (index_loc.IsConstant()) { |
| 4447 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4448 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4449 | if (index < 0 || index >= length) { |
| 4450 | codegen_->AddSlowPath(slow_path); |
| 4451 | __ jmp(slow_path->GetEntryLabel()); |
| 4452 | } else { |
| 4453 | // Some optimization after BCE may have generated this, and we should not |
| 4454 | // generate a bounds check if it is a valid range. |
| 4455 | } |
| 4456 | return; |
| 4457 | } |
| 4458 | |
| 4459 | // We have to reverse the jump condition because the length is the constant. |
| 4460 | Register index_reg = index_loc.AsRegister<Register>(); |
| 4461 | __ cmpl(index_reg, Immediate(length)); |
| 4462 | codegen_->AddSlowPath(slow_path); |
| 4463 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4464 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4465 | Register length = length_loc.AsRegister<Register>(); |
| 4466 | if (index_loc.IsConstant()) { |
| 4467 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4468 | __ cmpl(length, Immediate(value)); |
| 4469 | } else { |
| 4470 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 4471 | } |
| 4472 | codegen_->AddSlowPath(slow_path); |
| 4473 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4474 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4475 | } |
| 4476 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4477 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 4478 | temp->SetLocations(nullptr); |
| 4479 | } |
| 4480 | |
| 4481 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 4482 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4483 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4484 | } |
| 4485 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4486 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4487 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4488 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4492 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4493 | } |
| 4494 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4495 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4496 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4497 | } |
| 4498 | |
| 4499 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4500 | HBasicBlock* block = instruction->GetBlock(); |
| 4501 | if (block->GetLoopInformation() != nullptr) { |
| 4502 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4503 | // The back edge will generate the suspend check. |
| 4504 | return; |
| 4505 | } |
| 4506 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4507 | // The goto will generate the suspend check. |
| 4508 | return; |
| 4509 | } |
| 4510 | GenerateSuspendCheck(instruction, nullptr); |
| 4511 | } |
| 4512 | |
| 4513 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4514 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4515 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4516 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 4517 | if (slow_path == nullptr) { |
| 4518 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 4519 | instruction->SetSlowPath(slow_path); |
| 4520 | codegen_->AddSlowPath(slow_path); |
| 4521 | if (successor != nullptr) { |
| 4522 | DCHECK(successor->IsLoopHeader()); |
| 4523 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4524 | } |
| 4525 | } else { |
| 4526 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4527 | } |
| 4528 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4529 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4530 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4531 | if (successor == nullptr) { |
| 4532 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4533 | __ Bind(slow_path->GetReturnLabel()); |
| 4534 | } else { |
| 4535 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4536 | __ jmp(slow_path->GetEntryLabel()); |
| 4537 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4538 | } |
| 4539 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4540 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 4541 | return codegen_->GetAssembler(); |
| 4542 | } |
| 4543 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4544 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4545 | ScratchRegisterScope ensure_scratch( |
| 4546 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4547 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4548 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4549 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4550 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4551 | } |
| 4552 | |
| 4553 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4554 | ScratchRegisterScope ensure_scratch( |
| 4555 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4556 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4557 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4558 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4559 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 4560 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 4561 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 4565 | MoveOperands* move = moves_.Get(index); |
| 4566 | Location source = move->GetSource(); |
| 4567 | Location destination = move->GetDestination(); |
| 4568 | |
| 4569 | if (source.IsRegister()) { |
| 4570 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4571 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4572 | } else { |
| 4573 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4574 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4575 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4576 | } else if (source.IsFpuRegister()) { |
| 4577 | if (destination.IsFpuRegister()) { |
| 4578 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4579 | } else if (destination.IsStackSlot()) { |
| 4580 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4581 | } else { |
| 4582 | DCHECK(destination.IsDoubleStackSlot()); |
| 4583 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4584 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4585 | } else if (source.IsStackSlot()) { |
| 4586 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4587 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4588 | } else if (destination.IsFpuRegister()) { |
| 4589 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4590 | } else { |
| 4591 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4592 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4593 | } |
| 4594 | } else if (source.IsDoubleStackSlot()) { |
| 4595 | if (destination.IsFpuRegister()) { |
| 4596 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 4597 | } else { |
| 4598 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4599 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4600 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4601 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4602 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4603 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4604 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4605 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4606 | if (value == 0) { |
| 4607 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4608 | } else { |
| 4609 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 4610 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4611 | } else { |
| 4612 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4613 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4614 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4615 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4616 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4617 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4618 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4619 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4620 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4621 | if (value == 0) { |
| 4622 | // Easy handling of 0.0. |
| 4623 | __ xorps(dest, dest); |
| 4624 | } else { |
| 4625 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4626 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4627 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4628 | __ movl(temp, Immediate(value)); |
| 4629 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4630 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4631 | } else { |
| 4632 | DCHECK(destination.IsStackSlot()) << destination; |
| 4633 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 4634 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4635 | } else if (constant->IsLongConstant()) { |
| 4636 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4637 | int32_t low_value = Low32Bits(value); |
| 4638 | int32_t high_value = High32Bits(value); |
| 4639 | Immediate low(low_value); |
| 4640 | Immediate high(high_value); |
| 4641 | if (destination.IsDoubleStackSlot()) { |
| 4642 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4643 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4644 | } else { |
| 4645 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 4646 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 4647 | } |
| 4648 | } else { |
| 4649 | DCHECK(constant->IsDoubleConstant()); |
| 4650 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4651 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4652 | int32_t low_value = Low32Bits(value); |
| 4653 | int32_t high_value = High32Bits(value); |
| 4654 | Immediate low(low_value); |
| 4655 | Immediate high(high_value); |
| 4656 | if (destination.IsFpuRegister()) { |
| 4657 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4658 | if (value == 0) { |
| 4659 | // Easy handling of 0.0. |
| 4660 | __ xorpd(dest, dest); |
| 4661 | } else { |
| 4662 | __ pushl(high); |
| 4663 | __ pushl(low); |
| 4664 | __ movsd(dest, Address(ESP, 0)); |
| 4665 | __ addl(ESP, Immediate(8)); |
| 4666 | } |
| 4667 | } else { |
| 4668 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4669 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4670 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4671 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4672 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4673 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4674 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4675 | } |
| 4676 | } |
| 4677 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4678 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4679 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4680 | ScratchRegisterScope ensure_scratch( |
| 4681 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4682 | |
| 4683 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4684 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4685 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4686 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4687 | } |
| 4688 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4689 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4690 | ScratchRegisterScope ensure_scratch( |
| 4691 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4692 | |
| 4693 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4694 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4695 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4696 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4697 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4698 | } |
| 4699 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4700 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4701 | ScratchRegisterScope ensure_scratch1( |
| 4702 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4703 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4704 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4705 | ScratchRegisterScope ensure_scratch2( |
| 4706 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4707 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4708 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4709 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4710 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4711 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4712 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4713 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 4717 | MoveOperands* move = moves_.Get(index); |
| 4718 | Location source = move->GetSource(); |
| 4719 | Location destination = move->GetDestination(); |
| 4720 | |
| 4721 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 4722 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 4723 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4724 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4725 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4726 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4727 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4728 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4729 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4730 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4731 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4732 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4733 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4734 | // Use XOR Swap algorithm to avoid a temporary. |
| 4735 | DCHECK_NE(source.reg(), destination.reg()); |
| 4736 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4737 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4738 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4739 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4740 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4741 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4742 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4743 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4744 | // Take advantage of the 16 bytes in the XMM register. |
| 4745 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4746 | Address stack(ESP, destination.GetStackIndex()); |
| 4747 | // Load the double into the high doubleword. |
| 4748 | __ movhpd(reg, stack); |
| 4749 | |
| 4750 | // Store the low double into the destination. |
| 4751 | __ movsd(stack, reg); |
| 4752 | |
| 4753 | // Move the high double to the low double. |
| 4754 | __ psrldq(reg, Immediate(8)); |
| 4755 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4756 | // Take advantage of the 16 bytes in the XMM register. |
| 4757 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4758 | Address stack(ESP, source.GetStackIndex()); |
| 4759 | // Load the double into the high doubleword. |
| 4760 | __ movhpd(reg, stack); |
| 4761 | |
| 4762 | // Store the low double into the destination. |
| 4763 | __ movsd(stack, reg); |
| 4764 | |
| 4765 | // Move the high double to the low double. |
| 4766 | __ psrldq(reg, Immediate(8)); |
| 4767 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4768 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4769 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4770 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4771 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4772 | } |
| 4773 | } |
| 4774 | |
| 4775 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4776 | __ pushl(static_cast<Register>(reg)); |
| 4777 | } |
| 4778 | |
| 4779 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4780 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4781 | } |
| 4782 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4783 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4784 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4785 | ? LocationSummary::kCallOnSlowPath |
| 4786 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4787 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4788 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4789 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4790 | locations->SetOut(Location::RequiresRegister()); |
| 4791 | } |
| 4792 | |
| 4793 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4794 | LocationSummary* locations = cls->GetLocations(); |
| 4795 | Register out = locations->Out().AsRegister<Register>(); |
| 4796 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4797 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4798 | DCHECK(!cls->CanCallRuntime()); |
| 4799 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4800 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4801 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4802 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4803 | __ movl(out, Address( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4804 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4805 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4806 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4807 | |
| 4808 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4809 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4810 | codegen_->AddSlowPath(slow_path); |
| 4811 | __ testl(out, out); |
| 4812 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4813 | if (cls->MustGenerateClinitCheck()) { |
| 4814 | GenerateClassInitializationCheck(slow_path, out); |
| 4815 | } else { |
| 4816 | __ Bind(slow_path->GetExitLabel()); |
| 4817 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4818 | } |
| 4819 | } |
| 4820 | |
| 4821 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 4822 | LocationSummary* locations = |
| 4823 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4824 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4825 | if (check->HasUses()) { |
| 4826 | locations->SetOut(Location::SameAsFirstInput()); |
| 4827 | } |
| 4828 | } |
| 4829 | |
| 4830 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4831 | // We assume the class to not be null. |
| 4832 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4833 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4834 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4835 | GenerateClassInitializationCheck(slow_path, |
| 4836 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4837 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4838 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4839 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 4840 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4841 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4842 | Immediate(mirror::Class::kStatusInitialized)); |
| 4843 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4844 | __ Bind(slow_path->GetExitLabel()); |
| 4845 | // No need for memory fence, thanks to the X86 memory model. |
| 4846 | } |
| 4847 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4848 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 4849 | LocationSummary* locations = |
| 4850 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4851 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4852 | locations->SetOut(Location::RequiresRegister()); |
| 4853 | } |
| 4854 | |
| 4855 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 4856 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 4857 | codegen_->AddSlowPath(slow_path); |
| 4858 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4859 | LocationSummary* locations = load->GetLocations(); |
| 4860 | Register out = locations->Out().AsRegister<Register>(); |
| 4861 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4862 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4863 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4864 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4865 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4866 | __ testl(out, out); |
| 4867 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4868 | __ Bind(slow_path->GetExitLabel()); |
| 4869 | } |
| 4870 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4871 | static Address GetExceptionTlsAddress() { |
| 4872 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 4873 | } |
| 4874 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4875 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 4876 | LocationSummary* locations = |
| 4877 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4878 | locations->SetOut(Location::RequiresRegister()); |
| 4879 | } |
| 4880 | |
| 4881 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4882 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 4883 | } |
| 4884 | |
| 4885 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 4886 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4887 | } |
| 4888 | |
| 4889 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4890 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4891 | } |
| 4892 | |
| 4893 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 4894 | LocationSummary* locations = |
| 4895 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4896 | InvokeRuntimeCallingConvention calling_convention; |
| 4897 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4898 | } |
| 4899 | |
| 4900 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4901 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4902 | instruction, |
| 4903 | instruction->GetDexPc(), |
| 4904 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4907 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4908 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4909 | ? LocationSummary::kNoCall |
| 4910 | : LocationSummary::kCallOnSlowPath; |
| 4911 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4912 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4913 | locations->SetInAt(1, Location::Any()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4914 | // Note that TypeCheckSlowPathX86 uses this register too. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4915 | locations->SetOut(Location::RequiresRegister()); |
| 4916 | } |
| 4917 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4918 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4919 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4920 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4921 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4922 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4923 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4924 | Label done, zero; |
| 4925 | SlowPathCodeX86* slow_path = nullptr; |
| 4926 | |
| 4927 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4928 | // Avoid null check if we know obj is not null. |
| 4929 | if (instruction->MustDoNullCheck()) { |
| 4930 | __ testl(obj, obj); |
| 4931 | __ j(kEqual, &zero); |
| 4932 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4933 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4934 | __ movl(out, Address(obj, class_offset)); |
| 4935 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4936 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4937 | __ cmpl(out, cls.AsRegister<Register>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4938 | } else { |
| 4939 | DCHECK(cls.IsStackSlot()) << cls; |
| 4940 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 4941 | } |
| 4942 | |
| 4943 | if (instruction->IsClassFinal()) { |
| 4944 | // Classes must be equal for the instanceof to succeed. |
| 4945 | __ j(kNotEqual, &zero); |
| 4946 | __ movl(out, Immediate(1)); |
| 4947 | __ jmp(&done); |
| 4948 | } else { |
| 4949 | // If the classes are not equal, we go into a slow path. |
| 4950 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4951 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4952 | codegen_->AddSlowPath(slow_path); |
| 4953 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4954 | __ movl(out, Immediate(1)); |
| 4955 | __ jmp(&done); |
| 4956 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4957 | |
| 4958 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4959 | __ Bind(&zero); |
| 4960 | __ movl(out, Immediate(0)); |
| 4961 | } |
| 4962 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4963 | if (slow_path != nullptr) { |
| 4964 | __ Bind(slow_path->GetExitLabel()); |
| 4965 | } |
| 4966 | __ Bind(&done); |
| 4967 | } |
| 4968 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4969 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| 4970 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4971 | instruction, LocationSummary::kCallOnSlowPath); |
| 4972 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4973 | locations->SetInAt(1, Location::Any()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4974 | // Note that TypeCheckSlowPathX86 uses this register too. |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4975 | locations->AddTemp(Location::RequiresRegister()); |
| 4976 | } |
| 4977 | |
| 4978 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 4979 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4980 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4981 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4982 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4983 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4984 | SlowPathCodeX86* slow_path = |
| 4985 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4986 | codegen_->AddSlowPath(slow_path); |
| 4987 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4988 | // Avoid null check if we know obj is not null. |
| 4989 | if (instruction->MustDoNullCheck()) { |
| 4990 | __ testl(obj, obj); |
| 4991 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4992 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4993 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4994 | __ movl(temp, Address(obj, class_offset)); |
| 4995 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4996 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4997 | __ cmpl(temp, cls.AsRegister<Register>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4998 | } else { |
| 4999 | DCHECK(cls.IsStackSlot()) << cls; |
| 5000 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5001 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5002 | // The checkcast succeeds if the classes are equal (fast path). |
| 5003 | // 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] | 5004 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5005 | __ Bind(slow_path->GetExitLabel()); |
| 5006 | } |
| 5007 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5008 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5009 | LocationSummary* locations = |
| 5010 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5011 | InvokeRuntimeCallingConvention calling_convention; |
| 5012 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5013 | } |
| 5014 | |
| 5015 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5016 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5017 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5018 | instruction, |
| 5019 | instruction->GetDexPc(), |
| 5020 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5021 | } |
| 5022 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5023 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5024 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5025 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5026 | |
| 5027 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5028 | LocationSummary* locations = |
| 5029 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5030 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5031 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5032 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5033 | locations->SetInAt(1, Location::Any()); |
| 5034 | locations->SetOut(Location::SameAsFirstInput()); |
| 5035 | } |
| 5036 | |
| 5037 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 5038 | HandleBitwiseOperation(instruction); |
| 5039 | } |
| 5040 | |
| 5041 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 5042 | HandleBitwiseOperation(instruction); |
| 5043 | } |
| 5044 | |
| 5045 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 5046 | HandleBitwiseOperation(instruction); |
| 5047 | } |
| 5048 | |
| 5049 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5050 | LocationSummary* locations = instruction->GetLocations(); |
| 5051 | Location first = locations->InAt(0); |
| 5052 | Location second = locations->InAt(1); |
| 5053 | DCHECK(first.Equals(locations->Out())); |
| 5054 | |
| 5055 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5056 | if (second.IsRegister()) { |
| 5057 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5058 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5059 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5060 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5061 | } else { |
| 5062 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5063 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5064 | } |
| 5065 | } else if (second.IsConstant()) { |
| 5066 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5067 | __ andl(first.AsRegister<Register>(), |
| 5068 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5069 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5070 | __ orl(first.AsRegister<Register>(), |
| 5071 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5072 | } else { |
| 5073 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5074 | __ xorl(first.AsRegister<Register>(), |
| 5075 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5076 | } |
| 5077 | } else { |
| 5078 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5079 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5080 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5081 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5082 | } else { |
| 5083 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5084 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5085 | } |
| 5086 | } |
| 5087 | } else { |
| 5088 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5089 | if (second.IsRegisterPair()) { |
| 5090 | if (instruction->IsAnd()) { |
| 5091 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5092 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5093 | } else if (instruction->IsOr()) { |
| 5094 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5095 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5096 | } else { |
| 5097 | DCHECK(instruction->IsXor()); |
| 5098 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5099 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5100 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5101 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5102 | if (instruction->IsAnd()) { |
| 5103 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5104 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 5105 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5106 | } else if (instruction->IsOr()) { |
| 5107 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5108 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 5109 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5110 | } else { |
| 5111 | DCHECK(instruction->IsXor()); |
| 5112 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5113 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 5114 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5115 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5116 | } else { |
| 5117 | DCHECK(second.IsConstant()) << second; |
| 5118 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5119 | int32_t low_value = Low32Bits(value); |
| 5120 | int32_t high_value = High32Bits(value); |
| 5121 | Immediate low(low_value); |
| 5122 | Immediate high(high_value); |
| 5123 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5124 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5125 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5126 | if (low_value == 0) { |
| 5127 | __ xorl(first_low, first_low); |
| 5128 | } else if (low_value != -1) { |
| 5129 | __ andl(first_low, low); |
| 5130 | } |
| 5131 | if (high_value == 0) { |
| 5132 | __ xorl(first_high, first_high); |
| 5133 | } else if (high_value != -1) { |
| 5134 | __ andl(first_high, high); |
| 5135 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5136 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5137 | if (low_value != 0) { |
| 5138 | __ orl(first_low, low); |
| 5139 | } |
| 5140 | if (high_value != 0) { |
| 5141 | __ orl(first_high, high); |
| 5142 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5143 | } else { |
| 5144 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5145 | if (low_value != 0) { |
| 5146 | __ xorl(first_low, low); |
| 5147 | } |
| 5148 | if (high_value != 0) { |
| 5149 | __ xorl(first_high, high); |
| 5150 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5151 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5152 | } |
| 5153 | } |
| 5154 | } |
| 5155 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5156 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 5157 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5158 | UNUSED(instruction); |
| 5159 | LOG(FATAL) << "Unreachable"; |
| 5160 | } |
| 5161 | |
| 5162 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 5163 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5164 | UNUSED(instruction); |
| 5165 | LOG(FATAL) << "Unreachable"; |
| 5166 | } |
| 5167 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5168 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 5169 | DCHECK(codegen_->IsBaseline()); |
| 5170 | LocationSummary* locations = |
| 5171 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5172 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5173 | } |
| 5174 | |
| 5175 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5176 | DCHECK(codegen_->IsBaseline()); |
| 5177 | // Will be generated at use site. |
| 5178 | } |
| 5179 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame^] | 5180 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 5181 | HX86ComputeBaseMethodAddress* insn) { |
| 5182 | LocationSummary* locations = |
| 5183 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5184 | locations->SetOut(Location::RequiresRegister()); |
| 5185 | } |
| 5186 | |
| 5187 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 5188 | HX86ComputeBaseMethodAddress* insn) { |
| 5189 | LocationSummary* locations = insn->GetLocations(); |
| 5190 | Register reg = locations->Out().AsRegister<Register>(); |
| 5191 | |
| 5192 | // Generate call to next instruction. |
| 5193 | Label next_instruction; |
| 5194 | __ call(&next_instruction); |
| 5195 | __ Bind(&next_instruction); |
| 5196 | |
| 5197 | // Remember this offset for later use with constant area. |
| 5198 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 5199 | |
| 5200 | // Grab the return address off the stack. |
| 5201 | __ popl(reg); |
| 5202 | } |
| 5203 | |
| 5204 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 5205 | HX86LoadFromConstantTable* insn) { |
| 5206 | LocationSummary* locations = |
| 5207 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5208 | |
| 5209 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5210 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 5211 | |
| 5212 | // If we don't need to be materialized, we only need the inputs to be set. |
| 5213 | if (!insn->NeedsMaterialization()) { |
| 5214 | return; |
| 5215 | } |
| 5216 | |
| 5217 | switch (insn->GetType()) { |
| 5218 | case Primitive::kPrimFloat: |
| 5219 | case Primitive::kPrimDouble: |
| 5220 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5221 | break; |
| 5222 | |
| 5223 | case Primitive::kPrimInt: |
| 5224 | locations->SetOut(Location::RequiresRegister()); |
| 5225 | break; |
| 5226 | |
| 5227 | default: |
| 5228 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5229 | } |
| 5230 | } |
| 5231 | |
| 5232 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 5233 | if (!insn->NeedsMaterialization()) { |
| 5234 | return; |
| 5235 | } |
| 5236 | |
| 5237 | LocationSummary* locations = insn->GetLocations(); |
| 5238 | Location out = locations->Out(); |
| 5239 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 5240 | HConstant *value = insn->GetConstant(); |
| 5241 | |
| 5242 | switch (insn->GetType()) { |
| 5243 | case Primitive::kPrimFloat: |
| 5244 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 5245 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 5246 | break; |
| 5247 | |
| 5248 | case Primitive::kPrimDouble: |
| 5249 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 5250 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 5251 | break; |
| 5252 | |
| 5253 | case Primitive::kPrimInt: |
| 5254 | __ movl(out.AsRegister<Register>(), |
| 5255 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 5256 | break; |
| 5257 | |
| 5258 | default: |
| 5259 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5260 | } |
| 5261 | } |
| 5262 | |
| 5263 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 5264 | // Generate the constant area if needed. |
| 5265 | X86Assembler* assembler = GetAssembler(); |
| 5266 | if (!assembler->IsConstantAreaEmpty()) { |
| 5267 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 5268 | // byte values. |
| 5269 | assembler->Align(4, 0); |
| 5270 | constant_area_start_ = assembler->CodeSize(); |
| 5271 | assembler->AddConstantArea(); |
| 5272 | } |
| 5273 | |
| 5274 | // And finish up. |
| 5275 | CodeGenerator::Finalize(allocator); |
| 5276 | } |
| 5277 | |
| 5278 | /** |
| 5279 | * Class to handle late fixup of offsets into constant area. |
| 5280 | */ |
| 5281 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 5282 | public: |
| 5283 | RIPFixup(const CodeGeneratorX86& codegen, int offset) |
| 5284 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 5285 | |
| 5286 | private: |
| 5287 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5288 | // Patch the correct offset for the instruction. The place to patch is the |
| 5289 | // last 4 bytes of the instruction. |
| 5290 | // The value to patch is the distance from the offset in the constant area |
| 5291 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| 5292 | int32_t constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 5293 | int32_t relative_position = constant_offset - codegen_.GetMethodAddressOffset();; |
| 5294 | |
| 5295 | // Patch in the right value. |
| 5296 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5297 | } |
| 5298 | |
| 5299 | const CodeGeneratorX86& codegen_; |
| 5300 | |
| 5301 | // Location in constant area that the fixup refers to. |
| 5302 | int offset_into_constant_area_; |
| 5303 | }; |
| 5304 | |
| 5305 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 5306 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5307 | return Address(reg, kDummy32BitOffset, fixup); |
| 5308 | } |
| 5309 | |
| 5310 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 5311 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5312 | return Address(reg, kDummy32BitOffset, fixup); |
| 5313 | } |
| 5314 | |
| 5315 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 5316 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5317 | return Address(reg, kDummy32BitOffset, fixup); |
| 5318 | } |
| 5319 | |
| 5320 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 5321 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5322 | return Address(reg, kDummy32BitOffset, fixup); |
| 5323 | } |
| 5324 | |
| 5325 | /** |
| 5326 | * Finds instructions that need the constant area base as an input. |
| 5327 | */ |
| 5328 | class ConstantHandlerVisitor : public HGraphVisitor { |
| 5329 | public: |
| 5330 | explicit ConstantHandlerVisitor(HGraph* graph) : HGraphVisitor(graph), base_(nullptr) {} |
| 5331 | |
| 5332 | private: |
| 5333 | void VisitAdd(HAdd* add) OVERRIDE { |
| 5334 | BinaryFP(add); |
| 5335 | } |
| 5336 | |
| 5337 | void VisitSub(HSub* sub) OVERRIDE { |
| 5338 | BinaryFP(sub); |
| 5339 | } |
| 5340 | |
| 5341 | void VisitMul(HMul* mul) OVERRIDE { |
| 5342 | BinaryFP(mul); |
| 5343 | } |
| 5344 | |
| 5345 | void VisitDiv(HDiv* div) OVERRIDE { |
| 5346 | BinaryFP(div); |
| 5347 | } |
| 5348 | |
| 5349 | void VisitReturn(HReturn* ret) OVERRIDE { |
| 5350 | HConstant* value = ret->InputAt(0)->AsConstant(); |
| 5351 | if ((value != nullptr && Primitive::IsFloatingPointType(value->GetType()))) { |
| 5352 | ReplaceInput(ret, value, 0, true); |
| 5353 | } |
| 5354 | } |
| 5355 | |
| 5356 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE { |
| 5357 | HandleInvoke(invoke); |
| 5358 | } |
| 5359 | |
| 5360 | void VisitInvokeVirtual(HInvokeVirtual* invoke) OVERRIDE { |
| 5361 | HandleInvoke(invoke); |
| 5362 | } |
| 5363 | |
| 5364 | void VisitInvokeInterface(HInvokeInterface* invoke) OVERRIDE { |
| 5365 | HandleInvoke(invoke); |
| 5366 | } |
| 5367 | |
| 5368 | void BinaryFP(HBinaryOperation* bin) { |
| 5369 | HConstant* rhs = bin->InputAt(1)->AsConstant(); |
| 5370 | if (rhs != nullptr && Primitive::IsFloatingPointType(bin->GetResultType())) { |
| 5371 | ReplaceInput(bin, rhs, 1, false); |
| 5372 | } |
| 5373 | } |
| 5374 | |
| 5375 | void InitializeConstantAreaPointer(HInstruction* user) { |
| 5376 | // Ensure we only initialize the pointer once. |
| 5377 | if (base_ != nullptr) { |
| 5378 | return; |
| 5379 | } |
| 5380 | |
| 5381 | HGraph* graph = GetGraph(); |
| 5382 | HBasicBlock* entry = graph->GetEntryBlock(); |
| 5383 | base_ = new (graph->GetArena()) HX86ComputeBaseMethodAddress(); |
| 5384 | HInstruction* insert_pos = (user->GetBlock() == entry) ? user : entry->GetLastInstruction(); |
| 5385 | entry->InsertInstructionBefore(base_, insert_pos); |
| 5386 | DCHECK(base_ != nullptr); |
| 5387 | } |
| 5388 | |
| 5389 | void ReplaceInput(HInstruction* insn, HConstant* value, int input_index, bool materialize) { |
| 5390 | InitializeConstantAreaPointer(insn); |
| 5391 | HGraph* graph = GetGraph(); |
| 5392 | HBasicBlock* block = insn->GetBlock(); |
| 5393 | HX86LoadFromConstantTable* load_constant = |
| 5394 | new (graph->GetArena()) HX86LoadFromConstantTable(base_, value, materialize); |
| 5395 | block->InsertInstructionBefore(load_constant, insn); |
| 5396 | insn->ReplaceInput(load_constant, input_index); |
| 5397 | } |
| 5398 | |
| 5399 | void HandleInvoke(HInvoke* invoke) { |
| 5400 | // Ensure that we can load FP arguments from the constant area. |
| 5401 | for (size_t i = 0, e = invoke->InputCount(); i < e; i++) { |
| 5402 | HConstant* input = invoke->InputAt(i)->AsConstant(); |
| 5403 | if (input != nullptr && Primitive::IsFloatingPointType(input->GetType())) { |
| 5404 | ReplaceInput(invoke, input, i, true); |
| 5405 | } |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | // The generated HX86ComputeBaseMethodAddress in the entry block needed as an |
| 5410 | // input to the HX86LoadFromConstantTable instructions. |
| 5411 | HX86ComputeBaseMethodAddress* base_; |
| 5412 | }; |
| 5413 | |
| 5414 | void ConstantAreaFixups::Run() { |
| 5415 | ConstantHandlerVisitor visitor(graph_); |
| 5416 | visitor.VisitInsertionOrder(); |
| 5417 | } |
| 5418 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5419 | #undef __ |
| 5420 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5421 | } // namespace x86 |
| 5422 | } // namespace art |