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())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 50 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
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()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 59 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 60 | // Live registers will be restored in the catch block if caught. |
| 61 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 62 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 63 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 64 | instruction_, |
| 65 | instruction_->GetDexPc(), |
| 66 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 69 | bool IsFatal() const OVERRIDE { return true; } |
| 70 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 71 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 72 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 74 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 76 | }; |
| 77 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 78 | class DivZeroCheckSlowPathX86 : public SlowPathCodeX86 { |
| 79 | public: |
| 80 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 81 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 82 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 83 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 84 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 85 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 86 | // Live registers will be restored in the catch block if caught. |
| 87 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 88 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 89 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 90 | instruction_, |
| 91 | instruction_->GetDexPc(), |
| 92 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | bool IsFatal() const OVERRIDE { return true; } |
| 96 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 98 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | private: |
| 100 | HDivZeroCheck* const instruction_; |
| 101 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 102 | }; |
| 103 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 104 | class DivRemMinusOneSlowPathX86 : public SlowPathCodeX86 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 106 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 108 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 110 | if (is_div_) { |
| 111 | __ negl(reg_); |
| 112 | } else { |
| 113 | __ movl(reg_, Immediate(0)); |
| 114 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | __ jmp(GetExitLabel()); |
| 116 | } |
| 117 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 118 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 119 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | private: |
| 121 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 122 | bool is_div_; |
| 123 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 126 | class BoundsCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 127 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 128 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 130 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 131 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 132 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 134 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 135 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 136 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 137 | // Live registers will be restored in the catch block if caught. |
| 138 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 139 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 141 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 142 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 143 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 144 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 145 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 146 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 147 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 148 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 149 | instruction_, |
| 150 | instruction_->GetDexPc(), |
| 151 | this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 154 | bool IsFatal() const OVERRIDE { return true; } |
| 155 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 156 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 157 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 158 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 159 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | |
| 161 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 162 | }; |
| 163 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 164 | class SuspendCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 165 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 166 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 167 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 168 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 169 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 170 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 172 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 173 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 174 | instruction_, |
| 175 | instruction_->GetDexPc(), |
| 176 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 177 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 178 | if (successor_ == nullptr) { |
| 179 | __ jmp(GetReturnLabel()); |
| 180 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 181 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 182 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 185 | Label* GetReturnLabel() { |
| 186 | DCHECK(successor_ == nullptr); |
| 187 | return &return_label_; |
| 188 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 190 | HBasicBlock* GetSuccessor() const { |
| 191 | return successor_; |
| 192 | } |
| 193 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 194 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 195 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 196 | private: |
| 197 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 198 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 199 | Label return_label_; |
| 200 | |
| 201 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 202 | }; |
| 203 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 204 | class LoadStringSlowPathX86 : public SlowPathCodeX86 { |
| 205 | public: |
| 206 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 207 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 208 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 209 | LocationSummary* locations = instruction_->GetLocations(); |
| 210 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 211 | |
| 212 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 213 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 214 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 215 | |
| 216 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 217 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 218 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 219 | instruction_, |
| 220 | instruction_->GetDexPc(), |
| 221 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 222 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 223 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 224 | |
| 225 | __ jmp(GetExitLabel()); |
| 226 | } |
| 227 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 228 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 229 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 230 | private: |
| 231 | HLoadString* const instruction_; |
| 232 | |
| 233 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 234 | }; |
| 235 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 236 | class LoadClassSlowPathX86 : public SlowPathCodeX86 { |
| 237 | public: |
| 238 | LoadClassSlowPathX86(HLoadClass* cls, |
| 239 | HInstruction* at, |
| 240 | uint32_t dex_pc, |
| 241 | bool do_clinit) |
| 242 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 243 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 244 | } |
| 245 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 246 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 247 | LocationSummary* locations = at_->GetLocations(); |
| 248 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 249 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 250 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 251 | |
| 252 | InvokeRuntimeCallingConvention calling_convention; |
| 253 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 254 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 255 | : QUICK_ENTRY_POINT(pInitializeType), |
| 256 | at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 257 | |
| 258 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 259 | Location out = locations->Out(); |
| 260 | if (out.IsValid()) { |
| 261 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 262 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 263 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 264 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 265 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | __ jmp(GetExitLabel()); |
| 267 | } |
| 268 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 269 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 270 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | private: |
| 272 | // The class this slow path will load. |
| 273 | HLoadClass* const cls_; |
| 274 | |
| 275 | // The instruction where this slow path is happening. |
| 276 | // (Might be the load class or an initialization check). |
| 277 | HInstruction* const at_; |
| 278 | |
| 279 | // The dex PC of `at_`. |
| 280 | const uint32_t dex_pc_; |
| 281 | |
| 282 | // Whether to initialize the class. |
| 283 | const bool do_clinit_; |
| 284 | |
| 285 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 286 | }; |
| 287 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 288 | class TypeCheckSlowPathX86 : public SlowPathCodeX86 { |
| 289 | public: |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 290 | explicit TypeCheckSlowPathX86(HInstruction* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 291 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 292 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 293 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 294 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 295 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 296 | DCHECK(instruction_->IsCheckCast() |
| 297 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 298 | |
| 299 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 300 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 301 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 302 | |
| 303 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 304 | // move resolver. |
| 305 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 306 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 307 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 308 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 309 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 310 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 311 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 312 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 313 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 314 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 315 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 316 | instruction_, |
| 317 | instruction_->GetDexPc(), |
| 318 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 319 | } else { |
| 320 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 321 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 322 | instruction_, |
| 323 | instruction_->GetDexPc(), |
| 324 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 327 | if (instruction_->IsInstanceOf()) { |
| 328 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 329 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 330 | RestoreLiveRegisters(codegen, locations); |
| 331 | |
| 332 | __ jmp(GetExitLabel()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 335 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
| 336 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 337 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | HInstruction* const instruction_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | |
| 340 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 341 | }; |
| 342 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 343 | class DeoptimizationSlowPathX86 : public SlowPathCodeX86 { |
| 344 | public: |
| 345 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 346 | : instruction_(instruction) {} |
| 347 | |
| 348 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 9859620 | 2015-08-19 11:33:36 +0100 | [diff] [blame] | 349 | DCHECK(instruction_->IsDeoptimize()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 350 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 351 | __ Bind(GetEntryLabel()); |
| 352 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 353 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 354 | instruction_, |
| 355 | instruction_->GetDexPc(), |
| 356 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 359 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 360 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 361 | private: |
| 362 | HInstruction* const instruction_; |
| 363 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 364 | }; |
| 365 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 366 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 367 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 368 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 369 | inline Condition X86SignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 370 | switch (cond) { |
| 371 | case kCondEQ: return kEqual; |
| 372 | case kCondNE: return kNotEqual; |
| 373 | case kCondLT: return kLess; |
| 374 | case kCondLE: return kLessEqual; |
| 375 | case kCondGT: return kGreater; |
| 376 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 377 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 378 | LOG(FATAL) << "Unreachable"; |
| 379 | UNREACHABLE(); |
| 380 | } |
| 381 | |
| 382 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 383 | switch (cond) { |
| 384 | case kCondEQ: return kEqual; |
| 385 | case kCondNE: return kNotEqual; |
| 386 | case kCondLT: return kBelow; |
| 387 | case kCondLE: return kBelowEqual; |
| 388 | case kCondGT: return kAbove; |
| 389 | case kCondGE: return kAboveEqual; |
| 390 | } |
| 391 | LOG(FATAL) << "Unreachable"; |
| 392 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 395 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 396 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 400 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 401 | } |
| 402 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 403 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 404 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 405 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 406 | } |
| 407 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 408 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 409 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 410 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 413 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 414 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 415 | return GetFloatingPointSpillSlotSize(); |
| 416 | } |
| 417 | |
| 418 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 419 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 420 | return GetFloatingPointSpillSlotSize(); |
| 421 | } |
| 422 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 423 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 424 | HInstruction* instruction, |
| 425 | uint32_t dex_pc, |
| 426 | SlowPathCode* slow_path) { |
| 427 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 428 | instruction, |
| 429 | dex_pc, |
| 430 | slow_path); |
| 431 | } |
| 432 | |
| 433 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 434 | HInstruction* instruction, |
| 435 | uint32_t dex_pc, |
| 436 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 437 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 438 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 439 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 442 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| 443 | const X86InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 444 | const CompilerOptions& compiler_options, |
| 445 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 446 | : CodeGenerator(graph, |
| 447 | kNumberOfCpuRegisters, |
| 448 | kNumberOfXmmRegisters, |
| 449 | kNumberOfRegisterPairs, |
| 450 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 451 | arraysize(kCoreCalleeSaves)) |
| 452 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 453 | 0, |
| 454 | compiler_options, |
| 455 | stats), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 456 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 457 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 458 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 459 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 460 | isa_features_(isa_features), |
| 461 | method_patches_(graph->GetArena()->Adapter()), |
| 462 | relative_call_patches_(graph->GetArena()->Adapter()) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 463 | // Use a fake return address register to mimic Quick. |
| 464 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 465 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 466 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 467 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 468 | switch (type) { |
| 469 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 470 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 471 | X86ManagedRegister pair = |
| 472 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 473 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 474 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 475 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 476 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 477 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 478 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | case Primitive::kPrimByte: |
| 482 | case Primitive::kPrimBoolean: |
| 483 | case Primitive::kPrimChar: |
| 484 | case Primitive::kPrimShort: |
| 485 | case Primitive::kPrimInt: |
| 486 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 487 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 488 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 489 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 490 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 491 | X86ManagedRegister current = |
| 492 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 493 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 494 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 495 | } |
| 496 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 497 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 501 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 502 | return Location::FpuRegisterLocation( |
| 503 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 504 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 505 | |
| 506 | case Primitive::kPrimVoid: |
| 507 | LOG(FATAL) << "Unreachable type " << type; |
| 508 | } |
| 509 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 510 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 511 | } |
| 512 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 513 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 514 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 515 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 516 | |
| 517 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 518 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 519 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 520 | if (is_baseline) { |
| 521 | blocked_core_registers_[EBP] = true; |
| 522 | blocked_core_registers_[ESI] = true; |
| 523 | blocked_core_registers_[EDI] = true; |
| 524 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 525 | |
| 526 | UpdateBlockedPairRegisters(); |
| 527 | } |
| 528 | |
| 529 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 530 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 531 | X86ManagedRegister current = |
| 532 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 533 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 534 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 535 | blocked_register_pairs_[i] = true; |
| 536 | } |
| 537 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 538 | } |
| 539 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 540 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 541 | : HGraphVisitor(graph), |
| 542 | assembler_(codegen->GetAssembler()), |
| 543 | codegen_(codegen) {} |
| 544 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 545 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 546 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 547 | } |
| 548 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 549 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 550 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 551 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 552 | bool skip_overflow_check = |
| 553 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 554 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 555 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 556 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 557 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 558 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 559 | } |
| 560 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 561 | if (HasEmptyFrame()) { |
| 562 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 563 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 564 | |
| 565 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 566 | Register reg = kCoreCalleeSaves[i]; |
| 567 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 568 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 569 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 570 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 574 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 575 | __ subl(ESP, Immediate(adjust)); |
| 576 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 577 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 581 | __ cfi().RememberState(); |
| 582 | if (!HasEmptyFrame()) { |
| 583 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 584 | __ addl(ESP, Immediate(adjust)); |
| 585 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 586 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 587 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 588 | Register reg = kCoreCalleeSaves[i]; |
| 589 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 590 | __ popl(reg); |
| 591 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 592 | __ cfi().Restore(DWARFReg(reg)); |
| 593 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 594 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 595 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 596 | __ ret(); |
| 597 | __ cfi().RestoreState(); |
| 598 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 601 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 602 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 605 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 606 | switch (load->GetType()) { |
| 607 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 608 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 609 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 610 | |
| 611 | case Primitive::kPrimInt: |
| 612 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 613 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 614 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 615 | |
| 616 | case Primitive::kPrimBoolean: |
| 617 | case Primitive::kPrimByte: |
| 618 | case Primitive::kPrimChar: |
| 619 | case Primitive::kPrimShort: |
| 620 | case Primitive::kPrimVoid: |
| 621 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 622 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 626 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 627 | } |
| 628 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 629 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 630 | switch (type) { |
| 631 | case Primitive::kPrimBoolean: |
| 632 | case Primitive::kPrimByte: |
| 633 | case Primitive::kPrimChar: |
| 634 | case Primitive::kPrimShort: |
| 635 | case Primitive::kPrimInt: |
| 636 | case Primitive::kPrimNot: |
| 637 | return Location::RegisterLocation(EAX); |
| 638 | |
| 639 | case Primitive::kPrimLong: |
| 640 | return Location::RegisterPairLocation(EAX, EDX); |
| 641 | |
| 642 | case Primitive::kPrimVoid: |
| 643 | return Location::NoLocation(); |
| 644 | |
| 645 | case Primitive::kPrimDouble: |
| 646 | case Primitive::kPrimFloat: |
| 647 | return Location::FpuRegisterLocation(XMM0); |
| 648 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 649 | |
| 650 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 654 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 655 | } |
| 656 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 657 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 658 | switch (type) { |
| 659 | case Primitive::kPrimBoolean: |
| 660 | case Primitive::kPrimByte: |
| 661 | case Primitive::kPrimChar: |
| 662 | case Primitive::kPrimShort: |
| 663 | case Primitive::kPrimInt: |
| 664 | case Primitive::kPrimNot: { |
| 665 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 666 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 667 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 668 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 669 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 670 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 671 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 672 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 673 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 674 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 675 | uint32_t index = gp_index_; |
| 676 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 677 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 678 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 679 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 680 | calling_convention.GetRegisterPairAt(index)); |
| 681 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 682 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 683 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 688 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 689 | stack_index_++; |
| 690 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 691 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 692 | } else { |
| 693 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 698 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 699 | stack_index_ += 2; |
| 700 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 701 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 702 | } else { |
| 703 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 707 | case Primitive::kPrimVoid: |
| 708 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 709 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 710 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 711 | return Location(); |
| 712 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 713 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 714 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 715 | if (source.Equals(destination)) { |
| 716 | return; |
| 717 | } |
| 718 | if (destination.IsRegister()) { |
| 719 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 720 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 721 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 722 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 723 | } else { |
| 724 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 725 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 726 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 727 | } else if (destination.IsFpuRegister()) { |
| 728 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 729 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 730 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 731 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 732 | } else { |
| 733 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 734 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 735 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 736 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 737 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 738 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 739 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 740 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 741 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 742 | } else if (source.IsConstant()) { |
| 743 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 744 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 745 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 746 | } else { |
| 747 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 748 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 749 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 755 | if (source.Equals(destination)) { |
| 756 | return; |
| 757 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 758 | if (destination.IsRegisterPair()) { |
| 759 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 760 | EmitParallelMoves( |
| 761 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 762 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 763 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 764 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 765 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 766 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 767 | } else if (source.IsFpuRegister()) { |
| 768 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 769 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 770 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 771 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 772 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 773 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 774 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 775 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 776 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 777 | if (source.IsFpuRegister()) { |
| 778 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 779 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 780 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 781 | } else { |
| 782 | LOG(FATAL) << "Unimplemented"; |
| 783 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 784 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 785 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 786 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 787 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 788 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 789 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 790 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 791 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 792 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 793 | } else if (source.IsConstant()) { |
| 794 | HConstant* constant = source.GetConstant(); |
| 795 | int64_t value; |
| 796 | if (constant->IsLongConstant()) { |
| 797 | value = constant->AsLongConstant()->GetValue(); |
| 798 | } else { |
| 799 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 800 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 801 | } |
| 802 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 803 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 804 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 805 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 806 | EmitParallelMoves( |
| 807 | Location::StackSlot(source.GetStackIndex()), |
| 808 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 809 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 810 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 811 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 812 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | } |
| 816 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 817 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 818 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 819 | if (instruction->IsCurrentMethod()) { |
| 820 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 821 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 822 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 823 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 824 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 825 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 826 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 827 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 828 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 829 | } else if (location.IsStackSlot()) { |
| 830 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 831 | } else { |
| 832 | DCHECK(location.IsConstant()); |
| 833 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 834 | } |
| 835 | } else if (const_to_move->IsLongConstant()) { |
| 836 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 837 | if (location.IsRegisterPair()) { |
| 838 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 839 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 840 | } else if (location.IsDoubleStackSlot()) { |
| 841 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 842 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 843 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 844 | } else { |
| 845 | DCHECK(location.IsConstant()); |
| 846 | DCHECK_EQ(location.GetConstant(), instruction); |
| 847 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 848 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 849 | } else if (instruction->IsTemporary()) { |
| 850 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 851 | if (temp_location.IsStackSlot()) { |
| 852 | Move32(location, temp_location); |
| 853 | } else { |
| 854 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 855 | Move64(location, temp_location); |
| 856 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 857 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 858 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 859 | switch (instruction->GetType()) { |
| 860 | case Primitive::kPrimBoolean: |
| 861 | case Primitive::kPrimByte: |
| 862 | case Primitive::kPrimChar: |
| 863 | case Primitive::kPrimShort: |
| 864 | case Primitive::kPrimInt: |
| 865 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 866 | case Primitive::kPrimFloat: |
| 867 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 871 | case Primitive::kPrimDouble: |
| 872 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 873 | break; |
| 874 | |
| 875 | default: |
| 876 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 877 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 878 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 879 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 880 | switch (instruction->GetType()) { |
| 881 | case Primitive::kPrimBoolean: |
| 882 | case Primitive::kPrimByte: |
| 883 | case Primitive::kPrimChar: |
| 884 | case Primitive::kPrimShort: |
| 885 | case Primitive::kPrimInt: |
| 886 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 887 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 888 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 892 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 893 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 897 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 898 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 902 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 903 | DCHECK(location.IsRegister()); |
| 904 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 905 | } |
| 906 | |
Calin Juravle | 23a8e35 | 2015-09-08 19:56:31 +0100 | [diff] [blame] | 907 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 908 | if (location.IsRegister()) { |
| 909 | locations->AddTemp(location); |
| 910 | } else if (location.IsRegisterPair()) { |
| 911 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 912 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 913 | } else { |
| 914 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | void CodeGeneratorX86::MoveLocationToTemp(Location source, |
| 919 | const LocationSummary& locations, |
| 920 | int temp_index, |
| 921 | Primitive::Type type) { |
| 922 | if (!Primitive::IsFloatingPointType(type)) { |
| 923 | UNIMPLEMENTED(FATAL) << "MoveLocationToTemp not implemented for type " << type; |
| 924 | } |
| 925 | |
| 926 | DCHECK(source.IsFpuRegister()) << source; |
| 927 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 928 | if (type == Primitive::kPrimFloat) { |
| 929 | __ movd(locations.GetTemp(temp_index).AsRegister<Register>(), src_reg); |
| 930 | } else { |
| 931 | DCHECK(type == Primitive::kPrimDouble); |
| 932 | __ movd(locations.GetTemp(temp_index).AsRegister<Register>(), src_reg); |
| 933 | __ psrlq(src_reg, Immediate(32)); |
| 934 | __ movd(locations.GetTemp(temp_index + 1).AsRegister<Register>(), src_reg); |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | void CodeGeneratorX86::MoveTempToLocation(const LocationSummary& locations, |
| 939 | int temp_index, |
| 940 | Location destination, |
| 941 | Primitive::Type type) { |
| 942 | if (!Primitive::IsFloatingPointType(type)) { |
| 943 | UNIMPLEMENTED(FATAL) << "MoveLocationToTemp not implemented for type " << type; |
| 944 | } |
| 945 | |
| 946 | DCHECK(destination.IsFpuRegister()) << destination; |
| 947 | XmmRegister dst_reg = destination.AsFpuRegister<XmmRegister>(); |
| 948 | if (type == Primitive::kPrimFloat) { |
| 949 | __ movd(dst_reg, locations.GetTemp(temp_index).AsRegister<Register>()); |
| 950 | } else { |
| 951 | DCHECK(type == Primitive::kPrimDouble); |
| 952 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 953 | // Create stack space for 2 elements. |
| 954 | __ subl(ESP, Immediate(2 * elem_size)); |
| 955 | __ movl(Address(ESP, 0), locations.GetTemp(temp_index).AsRegister<Register>()); |
| 956 | __ movl(Address(ESP, elem_size), locations.GetTemp(temp_index + 1).AsRegister<Register>()); |
| 957 | __ movsd(dst_reg, Address(ESP, 0)); |
| 958 | // And remove the temporary stack space we allocated. |
| 959 | __ addl(ESP, Immediate(2 * elem_size)); |
| 960 | } |
| 961 | } |
| 962 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 963 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 964 | DCHECK(!successor->IsExitBlock()); |
| 965 | |
| 966 | HBasicBlock* block = got->GetBlock(); |
| 967 | HInstruction* previous = got->GetPrevious(); |
| 968 | |
| 969 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 970 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 971 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 972 | return; |
| 973 | } |
| 974 | |
| 975 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 976 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 977 | } |
| 978 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 979 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 983 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 984 | got->SetLocations(nullptr); |
| 985 | } |
| 986 | |
| 987 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 988 | HandleGoto(got, got->GetSuccessor()); |
| 989 | } |
| 990 | |
| 991 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 992 | try_boundary->SetLocations(nullptr); |
| 993 | } |
| 994 | |
| 995 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 996 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 997 | if (!successor->IsExitBlock()) { |
| 998 | HandleGoto(try_boundary, successor); |
| 999 | } |
| 1000 | } |
| 1001 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1002 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1003 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1006 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1007 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1010 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 1011 | Label* true_label, |
| 1012 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1013 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1014 | __ j(kUnordered, true_label); |
| 1015 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1016 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1017 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1018 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 1022 | Label* true_label, |
| 1023 | Label* false_label) { |
| 1024 | LocationSummary* locations = cond->GetLocations(); |
| 1025 | Location left = locations->InAt(0); |
| 1026 | Location right = locations->InAt(1); |
| 1027 | IfCondition if_cond = cond->GetCondition(); |
| 1028 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1029 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1030 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1031 | IfCondition true_high_cond = if_cond; |
| 1032 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1033 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1034 | |
| 1035 | // Set the conditions for the test, remembering that == needs to be |
| 1036 | // decided using the low words. |
| 1037 | switch (if_cond) { |
| 1038 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1039 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1040 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1041 | break; |
| 1042 | case kCondLT: |
| 1043 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1044 | break; |
| 1045 | case kCondLE: |
| 1046 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1047 | break; |
| 1048 | case kCondGT: |
| 1049 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1050 | break; |
| 1051 | case kCondGE: |
| 1052 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1053 | break; |
| 1054 | } |
| 1055 | |
| 1056 | if (right.IsConstant()) { |
| 1057 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1058 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1059 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1060 | |
| 1061 | if (val_high == 0) { |
| 1062 | __ testl(left_high, left_high); |
| 1063 | } else { |
| 1064 | __ cmpl(left_high, Immediate(val_high)); |
| 1065 | } |
| 1066 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1067 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1068 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1069 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1070 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1071 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1072 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1073 | } |
| 1074 | // Must be equal high, so compare the lows. |
| 1075 | if (val_low == 0) { |
| 1076 | __ testl(left_low, left_low); |
| 1077 | } else { |
| 1078 | __ cmpl(left_low, Immediate(val_low)); |
| 1079 | } |
| 1080 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1081 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1082 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1083 | |
| 1084 | __ cmpl(left_high, right_high); |
| 1085 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1086 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1087 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1088 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1089 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1090 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1091 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1092 | } |
| 1093 | // Must be equal high, so compare the lows. |
| 1094 | __ cmpl(left_low, right_low); |
| 1095 | } |
| 1096 | // The last comparison might be unsigned. |
| 1097 | __ j(final_condition, true_label); |
| 1098 | } |
| 1099 | |
| 1100 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1101 | HCondition* condition, |
| 1102 | Label* true_target, |
| 1103 | Label* false_target, |
| 1104 | Label* always_true_target) { |
| 1105 | LocationSummary* locations = condition->GetLocations(); |
| 1106 | Location left = locations->InAt(0); |
| 1107 | Location right = locations->InAt(1); |
| 1108 | |
| 1109 | // We don't want true_target as a nullptr. |
| 1110 | if (true_target == nullptr) { |
| 1111 | true_target = always_true_target; |
| 1112 | } |
| 1113 | bool falls_through = (false_target == nullptr); |
| 1114 | |
| 1115 | // FP compares don't like null false_targets. |
| 1116 | if (false_target == nullptr) { |
| 1117 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1118 | } |
| 1119 | |
| 1120 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1121 | switch (type) { |
| 1122 | case Primitive::kPrimLong: |
| 1123 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1124 | break; |
| 1125 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1126 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1127 | GenerateFPJumps(condition, true_target, false_target); |
| 1128 | break; |
| 1129 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1130 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1131 | GenerateFPJumps(condition, true_target, false_target); |
| 1132 | break; |
| 1133 | default: |
| 1134 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1135 | } |
| 1136 | |
| 1137 | if (!falls_through) { |
| 1138 | __ jmp(false_target); |
| 1139 | } |
| 1140 | } |
| 1141 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1142 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| 1143 | Label* true_target, |
| 1144 | Label* false_target, |
| 1145 | Label* always_true_target) { |
| 1146 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1147 | if (cond->IsIntConstant()) { |
| 1148 | // Constant condition, statically compared against 1. |
| 1149 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1150 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1151 | if (always_true_target != nullptr) { |
| 1152 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1153 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1154 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1155 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1156 | DCHECK_EQ(cond_value, 0); |
| 1157 | } |
| 1158 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1159 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1160 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1161 | // Moves do not affect the eflags register, so if the condition is |
| 1162 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1163 | // again. We can't use the eflags on long/FP conditions if they are |
| 1164 | // materialized due to the complex branching. |
| 1165 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1166 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1167 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1168 | && (type != Primitive::kPrimLong && !Primitive::IsFloatingPointType(type)); |
| 1169 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1170 | if (!eflags_set) { |
| 1171 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1172 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1173 | if (lhs.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1174 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1175 | } else { |
| 1176 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1177 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1178 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1179 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1180 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1181 | } |
| 1182 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1183 | // Condition has not been materialized, use its inputs as the |
| 1184 | // comparison and its condition as the branch condition. |
| 1185 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1186 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1187 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1188 | // Generate the comparison directly. |
| 1189 | GenerateCompareTestAndBranch(instruction->AsIf(), |
| 1190 | cond->AsCondition(), |
| 1191 | true_target, |
| 1192 | false_target, |
| 1193 | always_true_target); |
| 1194 | return; |
| 1195 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1196 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1197 | Location lhs = cond->GetLocations()->InAt(0); |
| 1198 | Location rhs = cond->GetLocations()->InAt(1); |
| 1199 | // LHS is guaranteed to be in a register (see |
| 1200 | // LocationsBuilderX86::VisitCondition). |
| 1201 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1202 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1203 | } else if (rhs.IsConstant()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame] | 1204 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1205 | if (constant == 0) { |
| 1206 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1207 | } else { |
| 1208 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1209 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1210 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1211 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1212 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1213 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1214 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1215 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1216 | if (false_target != nullptr) { |
| 1217 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1221 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| 1222 | LocationSummary* locations = |
| 1223 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1224 | HInstruction* cond = if_instr->InputAt(0); |
| 1225 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1226 | locations->SetInAt(0, Location::Any()); |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| 1231 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1232 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1233 | Label* always_true_target = true_target; |
| 1234 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1235 | if_instr->IfTrueSuccessor())) { |
| 1236 | always_true_target = nullptr; |
| 1237 | } |
| 1238 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1239 | if_instr->IfFalseSuccessor())) { |
| 1240 | false_target = nullptr; |
| 1241 | } |
| 1242 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1243 | } |
| 1244 | |
| 1245 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1246 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1247 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1248 | HInstruction* cond = deoptimize->InputAt(0); |
| 1249 | DCHECK(cond->IsCondition()); |
| 1250 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1251 | locations->SetInAt(0, Location::Any()); |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1256 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) |
| 1257 | DeoptimizationSlowPathX86(deoptimize); |
| 1258 | codegen_->AddSlowPath(slow_path); |
| 1259 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1260 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1261 | } |
| 1262 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1263 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1264 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1267 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1268 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1271 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1272 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1275 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1276 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1277 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1280 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1281 | LocationSummary* locations = |
| 1282 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1283 | switch (store->InputAt(1)->GetType()) { |
| 1284 | case Primitive::kPrimBoolean: |
| 1285 | case Primitive::kPrimByte: |
| 1286 | case Primitive::kPrimChar: |
| 1287 | case Primitive::kPrimShort: |
| 1288 | case Primitive::kPrimInt: |
| 1289 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1290 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1291 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1292 | break; |
| 1293 | |
| 1294 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1295 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1296 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1297 | break; |
| 1298 | |
| 1299 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1300 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1301 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1304 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1305 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1308 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1309 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1310 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1311 | // Handle the long/FP comparisons made in instruction simplification. |
| 1312 | switch (cond->InputAt(0)->GetType()) { |
| 1313 | case Primitive::kPrimLong: { |
| 1314 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1315 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1316 | if (cond->NeedsMaterialization()) { |
| 1317 | locations->SetOut(Location::RequiresRegister()); |
| 1318 | } |
| 1319 | break; |
| 1320 | } |
| 1321 | case Primitive::kPrimFloat: |
| 1322 | case Primitive::kPrimDouble: { |
| 1323 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1324 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1325 | if (cond->NeedsMaterialization()) { |
| 1326 | locations->SetOut(Location::RequiresRegister()); |
| 1327 | } |
| 1328 | break; |
| 1329 | } |
| 1330 | default: |
| 1331 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1332 | locations->SetInAt(1, Location::Any()); |
| 1333 | if (cond->NeedsMaterialization()) { |
| 1334 | // We need a byte register. |
| 1335 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1336 | } |
| 1337 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1338 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1341 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1342 | if (!cond->NeedsMaterialization()) { |
| 1343 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1344 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1345 | |
| 1346 | LocationSummary* locations = cond->GetLocations(); |
| 1347 | Location lhs = locations->InAt(0); |
| 1348 | Location rhs = locations->InAt(1); |
| 1349 | Register reg = locations->Out().AsRegister<Register>(); |
| 1350 | Label true_label, false_label; |
| 1351 | |
| 1352 | switch (cond->InputAt(0)->GetType()) { |
| 1353 | default: { |
| 1354 | // Integer case. |
| 1355 | |
| 1356 | // Clear output register: setcc only sets the low byte. |
| 1357 | __ xorl(reg, reg); |
| 1358 | |
| 1359 | if (rhs.IsRegister()) { |
| 1360 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1361 | } else if (rhs.IsConstant()) { |
| 1362 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1363 | if (constant == 0) { |
| 1364 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1365 | } else { |
| 1366 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1367 | } |
| 1368 | } else { |
| 1369 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1370 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1371 | __ setb(X86SignedCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1372 | return; |
| 1373 | } |
| 1374 | case Primitive::kPrimLong: |
| 1375 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1376 | break; |
| 1377 | case Primitive::kPrimFloat: |
| 1378 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1379 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1380 | break; |
| 1381 | case Primitive::kPrimDouble: |
| 1382 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1383 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1384 | break; |
| 1385 | } |
| 1386 | |
| 1387 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1388 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1389 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1390 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1391 | __ Bind(&false_label); |
| 1392 | __ xorl(reg, reg); |
| 1393 | __ jmp(&done_label); |
| 1394 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1395 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1396 | __ Bind(&true_label); |
| 1397 | __ movl(reg, Immediate(1)); |
| 1398 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1402 | VisitCondition(comp); |
| 1403 | } |
| 1404 | |
| 1405 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1406 | VisitCondition(comp); |
| 1407 | } |
| 1408 | |
| 1409 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1410 | VisitCondition(comp); |
| 1411 | } |
| 1412 | |
| 1413 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1414 | VisitCondition(comp); |
| 1415 | } |
| 1416 | |
| 1417 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1418 | VisitCondition(comp); |
| 1419 | } |
| 1420 | |
| 1421 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1422 | VisitCondition(comp); |
| 1423 | } |
| 1424 | |
| 1425 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1426 | VisitCondition(comp); |
| 1427 | } |
| 1428 | |
| 1429 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1430 | VisitCondition(comp); |
| 1431 | } |
| 1432 | |
| 1433 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1434 | VisitCondition(comp); |
| 1435 | } |
| 1436 | |
| 1437 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1438 | VisitCondition(comp); |
| 1439 | } |
| 1440 | |
| 1441 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1442 | VisitCondition(comp); |
| 1443 | } |
| 1444 | |
| 1445 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1446 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1450 | LocationSummary* locations = |
| 1451 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1452 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1455 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1456 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1457 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1460 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1461 | LocationSummary* locations = |
| 1462 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1463 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1464 | } |
| 1465 | |
| 1466 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant) { |
| 1467 | // Will be generated at use site. |
| 1468 | UNUSED(constant); |
| 1469 | } |
| 1470 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1471 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1472 | LocationSummary* locations = |
| 1473 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1474 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 1478 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1479 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1480 | } |
| 1481 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1482 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1483 | LocationSummary* locations = |
| 1484 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1485 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1486 | } |
| 1487 | |
| 1488 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1489 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1490 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1494 | LocationSummary* locations = |
| 1495 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1496 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1497 | } |
| 1498 | |
| 1499 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1500 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1501 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1502 | } |
| 1503 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1504 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1505 | memory_barrier->SetLocations(nullptr); |
| 1506 | } |
| 1507 | |
| 1508 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1509 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1510 | } |
| 1511 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1512 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1513 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1516 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1517 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1518 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1521 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1522 | LocationSummary* locations = |
| 1523 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1524 | switch (ret->InputAt(0)->GetType()) { |
| 1525 | case Primitive::kPrimBoolean: |
| 1526 | case Primitive::kPrimByte: |
| 1527 | case Primitive::kPrimChar: |
| 1528 | case Primitive::kPrimShort: |
| 1529 | case Primitive::kPrimInt: |
| 1530 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1531 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1532 | break; |
| 1533 | |
| 1534 | case Primitive::kPrimLong: |
| 1535 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1536 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1537 | break; |
| 1538 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1539 | case Primitive::kPrimFloat: |
| 1540 | case Primitive::kPrimDouble: |
| 1541 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1542 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1543 | break; |
| 1544 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1545 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1546 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1547 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1550 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1551 | if (kIsDebugBuild) { |
| 1552 | switch (ret->InputAt(0)->GetType()) { |
| 1553 | case Primitive::kPrimBoolean: |
| 1554 | case Primitive::kPrimByte: |
| 1555 | case Primitive::kPrimChar: |
| 1556 | case Primitive::kPrimShort: |
| 1557 | case Primitive::kPrimInt: |
| 1558 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1559 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1560 | break; |
| 1561 | |
| 1562 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1563 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1564 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1565 | break; |
| 1566 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1567 | case Primitive::kPrimFloat: |
| 1568 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1569 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1570 | break; |
| 1571 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1572 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1573 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1574 | } |
| 1575 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1576 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1579 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1580 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1581 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1582 | // the method_idx. |
| 1583 | HandleInvoke(invoke); |
| 1584 | } |
| 1585 | |
| 1586 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1587 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1588 | } |
| 1589 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1590 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1591 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1592 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1593 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1594 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1595 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1596 | if (intrinsic.TryDispatch(invoke)) { |
| 1597 | return; |
| 1598 | } |
| 1599 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1600 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1601 | |
| 1602 | if (codegen_->IsBaseline()) { |
| 1603 | // Baseline does not have enough registers if the current method also |
| 1604 | // needs a register. We therefore do not require a register for it, and let |
| 1605 | // the code generation of the invoke handle it. |
| 1606 | LocationSummary* locations = invoke->GetLocations(); |
| 1607 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 1608 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 1609 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 1610 | } |
| 1611 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1612 | } |
| 1613 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1614 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1615 | if (invoke->GetLocations()->Intrinsified()) { |
| 1616 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1617 | intrinsic.Dispatch(invoke); |
| 1618 | return true; |
| 1619 | } |
| 1620 | return false; |
| 1621 | } |
| 1622 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1623 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1624 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1625 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1626 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1627 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1628 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1629 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1630 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1631 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1632 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1633 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1634 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1635 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1639 | HandleInvoke(invoke); |
| 1640 | } |
| 1641 | |
| 1642 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1643 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1644 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1647 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1648 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1649 | return; |
| 1650 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1651 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1652 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1653 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1654 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1657 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1658 | HandleInvoke(invoke); |
| 1659 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1660 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1664 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1665 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1666 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1667 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1668 | LocationSummary* locations = invoke->GetLocations(); |
| 1669 | Location receiver = locations->InAt(0); |
| 1670 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1671 | |
| 1672 | // Set the hidden argument. |
| 1673 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1674 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1675 | |
| 1676 | // temp = object->GetClass(); |
| 1677 | if (receiver.IsStackSlot()) { |
| 1678 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1679 | __ movl(temp, Address(temp, class_offset)); |
| 1680 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1681 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1682 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1683 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1684 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1685 | // temp = temp->GetImtEntryAt(method_offset); |
| 1686 | __ movl(temp, Address(temp, method_offset)); |
| 1687 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1688 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1689 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1690 | |
| 1691 | DCHECK(!codegen_->IsLeafMethod()); |
| 1692 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1693 | } |
| 1694 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1695 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1696 | LocationSummary* locations = |
| 1697 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1698 | switch (neg->GetResultType()) { |
| 1699 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1700 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1701 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1702 | locations->SetOut(Location::SameAsFirstInput()); |
| 1703 | break; |
| 1704 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1705 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1706 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1707 | locations->SetOut(Location::SameAsFirstInput()); |
| 1708 | locations->AddTemp(Location::RequiresRegister()); |
| 1709 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1710 | break; |
| 1711 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1712 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1713 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1714 | locations->SetOut(Location::SameAsFirstInput()); |
| 1715 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1716 | break; |
| 1717 | |
| 1718 | default: |
| 1719 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1724 | LocationSummary* locations = neg->GetLocations(); |
| 1725 | Location out = locations->Out(); |
| 1726 | Location in = locations->InAt(0); |
| 1727 | switch (neg->GetResultType()) { |
| 1728 | case Primitive::kPrimInt: |
| 1729 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1730 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1731 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1732 | break; |
| 1733 | |
| 1734 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1735 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1736 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1737 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1738 | // Negation is similar to subtraction from zero. The least |
| 1739 | // significant byte triggers a borrow when it is different from |
| 1740 | // zero; to take it into account, add 1 to the most significant |
| 1741 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1742 | // operation. |
| 1743 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1744 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1745 | break; |
| 1746 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1747 | case Primitive::kPrimFloat: { |
| 1748 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1749 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1750 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1751 | // Implement float negation with an exclusive or with value |
| 1752 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1753 | // single-precision floating-point number). |
| 1754 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1755 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1756 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1757 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1758 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1759 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1760 | case Primitive::kPrimDouble: { |
| 1761 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1762 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1763 | // Implement double negation with an exclusive or with value |
| 1764 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1765 | // a double-precision floating-point number). |
| 1766 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1767 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1768 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1769 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1770 | |
| 1771 | default: |
| 1772 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1773 | } |
| 1774 | } |
| 1775 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1776 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1777 | Primitive::Type result_type = conversion->GetResultType(); |
| 1778 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1779 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1780 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1781 | // The float-to-long and double-to-long type conversions rely on a |
| 1782 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1783 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1784 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1785 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1786 | ? LocationSummary::kCall |
| 1787 | : LocationSummary::kNoCall; |
| 1788 | LocationSummary* locations = |
| 1789 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1790 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1791 | // The Java language does not allow treating boolean as an integral type but |
| 1792 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1793 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1794 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1795 | case Primitive::kPrimByte: |
| 1796 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1797 | case Primitive::kPrimBoolean: |
| 1798 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1799 | case Primitive::kPrimShort: |
| 1800 | case Primitive::kPrimInt: |
| 1801 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1802 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1803 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1804 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1805 | // the validation of the linear scan implementation |
| 1806 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | |
| 1809 | default: |
| 1810 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1811 | << " to " << result_type; |
| 1812 | } |
| 1813 | break; |
| 1814 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1815 | case Primitive::kPrimShort: |
| 1816 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1817 | case Primitive::kPrimBoolean: |
| 1818 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1819 | case Primitive::kPrimByte: |
| 1820 | case Primitive::kPrimInt: |
| 1821 | case Primitive::kPrimChar: |
| 1822 | // Processing a Dex `int-to-short' instruction. |
| 1823 | locations->SetInAt(0, Location::Any()); |
| 1824 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1825 | break; |
| 1826 | |
| 1827 | default: |
| 1828 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1829 | << " to " << result_type; |
| 1830 | } |
| 1831 | break; |
| 1832 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1833 | case Primitive::kPrimInt: |
| 1834 | switch (input_type) { |
| 1835 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1836 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1837 | locations->SetInAt(0, Location::Any()); |
| 1838 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1839 | break; |
| 1840 | |
| 1841 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1842 | // Processing a Dex `float-to-int' instruction. |
| 1843 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1844 | locations->SetOut(Location::RequiresRegister()); |
| 1845 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1846 | break; |
| 1847 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1848 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1849 | // Processing a Dex `double-to-int' instruction. |
| 1850 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1851 | locations->SetOut(Location::RequiresRegister()); |
| 1852 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1853 | break; |
| 1854 | |
| 1855 | default: |
| 1856 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1857 | << " to " << result_type; |
| 1858 | } |
| 1859 | break; |
| 1860 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1861 | case Primitive::kPrimLong: |
| 1862 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1863 | case Primitive::kPrimBoolean: |
| 1864 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1865 | case Primitive::kPrimByte: |
| 1866 | case Primitive::kPrimShort: |
| 1867 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1868 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1869 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1870 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1871 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1872 | break; |
| 1873 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1874 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1875 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1876 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1877 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1878 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1879 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1880 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1881 | // The runtime helper puts the result in EAX, EDX. |
| 1882 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1883 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1884 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1885 | |
| 1886 | default: |
| 1887 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1888 | << " to " << result_type; |
| 1889 | } |
| 1890 | break; |
| 1891 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1892 | case Primitive::kPrimChar: |
| 1893 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1894 | case Primitive::kPrimBoolean: |
| 1895 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1896 | case Primitive::kPrimByte: |
| 1897 | case Primitive::kPrimShort: |
| 1898 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1899 | // Processing a Dex `int-to-char' instruction. |
| 1900 | locations->SetInAt(0, Location::Any()); |
| 1901 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1902 | break; |
| 1903 | |
| 1904 | default: |
| 1905 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1906 | << " to " << result_type; |
| 1907 | } |
| 1908 | break; |
| 1909 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1910 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1911 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1912 | case Primitive::kPrimBoolean: |
| 1913 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1914 | case Primitive::kPrimByte: |
| 1915 | case Primitive::kPrimShort: |
| 1916 | case Primitive::kPrimInt: |
| 1917 | case Primitive::kPrimChar: |
| 1918 | // Processing a Dex `int-to-float' instruction. |
| 1919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1920 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1921 | break; |
| 1922 | |
| 1923 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1924 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1925 | locations->SetInAt(0, Location::Any()); |
| 1926 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1927 | break; |
| 1928 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1929 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1930 | // Processing a Dex `double-to-float' instruction. |
| 1931 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1932 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1933 | break; |
| 1934 | |
| 1935 | default: |
| 1936 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1937 | << " to " << result_type; |
| 1938 | }; |
| 1939 | break; |
| 1940 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1941 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1942 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1943 | case Primitive::kPrimBoolean: |
| 1944 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1945 | case Primitive::kPrimByte: |
| 1946 | case Primitive::kPrimShort: |
| 1947 | case Primitive::kPrimInt: |
| 1948 | case Primitive::kPrimChar: |
| 1949 | // Processing a Dex `int-to-double' instruction. |
| 1950 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1951 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1952 | break; |
| 1953 | |
| 1954 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1955 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1956 | locations->SetInAt(0, Location::Any()); |
| 1957 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1958 | break; |
| 1959 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1960 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1961 | // Processing a Dex `float-to-double' instruction. |
| 1962 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1963 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1964 | break; |
| 1965 | |
| 1966 | default: |
| 1967 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1968 | << " to " << result_type; |
| 1969 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1970 | break; |
| 1971 | |
| 1972 | default: |
| 1973 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1974 | << " to " << result_type; |
| 1975 | } |
| 1976 | } |
| 1977 | |
| 1978 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1979 | LocationSummary* locations = conversion->GetLocations(); |
| 1980 | Location out = locations->Out(); |
| 1981 | Location in = locations->InAt(0); |
| 1982 | Primitive::Type result_type = conversion->GetResultType(); |
| 1983 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1984 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1985 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1986 | case Primitive::kPrimByte: |
| 1987 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1988 | case Primitive::kPrimBoolean: |
| 1989 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1990 | case Primitive::kPrimShort: |
| 1991 | case Primitive::kPrimInt: |
| 1992 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1993 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1994 | if (in.IsRegister()) { |
| 1995 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1996 | } else { |
| 1997 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1998 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1999 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2000 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2001 | break; |
| 2002 | |
| 2003 | default: |
| 2004 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2005 | << " to " << result_type; |
| 2006 | } |
| 2007 | break; |
| 2008 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2009 | case Primitive::kPrimShort: |
| 2010 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2011 | case Primitive::kPrimBoolean: |
| 2012 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2013 | case Primitive::kPrimByte: |
| 2014 | case Primitive::kPrimInt: |
| 2015 | case Primitive::kPrimChar: |
| 2016 | // Processing a Dex `int-to-short' instruction. |
| 2017 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2018 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2019 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2020 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2021 | } else { |
| 2022 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2023 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2024 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2025 | } |
| 2026 | break; |
| 2027 | |
| 2028 | default: |
| 2029 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2030 | << " to " << result_type; |
| 2031 | } |
| 2032 | break; |
| 2033 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2034 | case Primitive::kPrimInt: |
| 2035 | switch (input_type) { |
| 2036 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2037 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2038 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2039 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2040 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2041 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2042 | } else { |
| 2043 | DCHECK(in.IsConstant()); |
| 2044 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2045 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2046 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2047 | } |
| 2048 | break; |
| 2049 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2050 | case Primitive::kPrimFloat: { |
| 2051 | // Processing a Dex `float-to-int' instruction. |
| 2052 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2053 | Register output = out.AsRegister<Register>(); |
| 2054 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2055 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2056 | |
| 2057 | __ movl(output, Immediate(kPrimIntMax)); |
| 2058 | // temp = int-to-float(output) |
| 2059 | __ cvtsi2ss(temp, output); |
| 2060 | // if input >= temp goto done |
| 2061 | __ comiss(input, temp); |
| 2062 | __ j(kAboveEqual, &done); |
| 2063 | // if input == NaN goto nan |
| 2064 | __ j(kUnordered, &nan); |
| 2065 | // output = float-to-int-truncate(input) |
| 2066 | __ cvttss2si(output, input); |
| 2067 | __ jmp(&done); |
| 2068 | __ Bind(&nan); |
| 2069 | // output = 0 |
| 2070 | __ xorl(output, output); |
| 2071 | __ Bind(&done); |
| 2072 | break; |
| 2073 | } |
| 2074 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2075 | case Primitive::kPrimDouble: { |
| 2076 | // Processing a Dex `double-to-int' instruction. |
| 2077 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2078 | Register output = out.AsRegister<Register>(); |
| 2079 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2080 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2081 | |
| 2082 | __ movl(output, Immediate(kPrimIntMax)); |
| 2083 | // temp = int-to-double(output) |
| 2084 | __ cvtsi2sd(temp, output); |
| 2085 | // if input >= temp goto done |
| 2086 | __ comisd(input, temp); |
| 2087 | __ j(kAboveEqual, &done); |
| 2088 | // if input == NaN goto nan |
| 2089 | __ j(kUnordered, &nan); |
| 2090 | // output = double-to-int-truncate(input) |
| 2091 | __ cvttsd2si(output, input); |
| 2092 | __ jmp(&done); |
| 2093 | __ Bind(&nan); |
| 2094 | // output = 0 |
| 2095 | __ xorl(output, output); |
| 2096 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2097 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2098 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2099 | |
| 2100 | default: |
| 2101 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2102 | << " to " << result_type; |
| 2103 | } |
| 2104 | break; |
| 2105 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2106 | case Primitive::kPrimLong: |
| 2107 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2108 | case Primitive::kPrimBoolean: |
| 2109 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2110 | case Primitive::kPrimByte: |
| 2111 | case Primitive::kPrimShort: |
| 2112 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2113 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2114 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2115 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2116 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2117 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2118 | __ cdq(); |
| 2119 | break; |
| 2120 | |
| 2121 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2122 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2123 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2124 | conversion, |
| 2125 | conversion->GetDexPc(), |
| 2126 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2127 | break; |
| 2128 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2129 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2130 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2131 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2132 | conversion, |
| 2133 | conversion->GetDexPc(), |
| 2134 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2135 | break; |
| 2136 | |
| 2137 | default: |
| 2138 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2139 | << " to " << result_type; |
| 2140 | } |
| 2141 | break; |
| 2142 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2143 | case Primitive::kPrimChar: |
| 2144 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2145 | case Primitive::kPrimBoolean: |
| 2146 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2147 | case Primitive::kPrimByte: |
| 2148 | case Primitive::kPrimShort: |
| 2149 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2150 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2151 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2152 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2153 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2154 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2155 | } else { |
| 2156 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2157 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2158 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2159 | } |
| 2160 | break; |
| 2161 | |
| 2162 | default: |
| 2163 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2164 | << " to " << result_type; |
| 2165 | } |
| 2166 | break; |
| 2167 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2168 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2169 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2170 | case Primitive::kPrimBoolean: |
| 2171 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2172 | case Primitive::kPrimByte: |
| 2173 | case Primitive::kPrimShort: |
| 2174 | case Primitive::kPrimInt: |
| 2175 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2176 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2177 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2178 | break; |
| 2179 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2180 | case Primitive::kPrimLong: { |
| 2181 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2182 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2183 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2184 | // Create stack space for the call to |
| 2185 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2186 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2187 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2188 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2189 | __ subl(ESP, Immediate(adjustment)); |
| 2190 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2191 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2192 | // Load the value to the FP stack, using temporaries if needed. |
| 2193 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2194 | |
| 2195 | if (out.IsStackSlot()) { |
| 2196 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2197 | } else { |
| 2198 | __ fstps(Address(ESP, 0)); |
| 2199 | Location stack_temp = Location::StackSlot(0); |
| 2200 | codegen_->Move32(out, stack_temp); |
| 2201 | } |
| 2202 | |
| 2203 | // Remove the temporary stack space we allocated. |
| 2204 | if (adjustment != 0) { |
| 2205 | __ addl(ESP, Immediate(adjustment)); |
| 2206 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2207 | break; |
| 2208 | } |
| 2209 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2210 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2211 | // Processing a Dex `double-to-float' instruction. |
| 2212 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2213 | break; |
| 2214 | |
| 2215 | default: |
| 2216 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2217 | << " to " << result_type; |
| 2218 | }; |
| 2219 | break; |
| 2220 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2221 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2222 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2223 | case Primitive::kPrimBoolean: |
| 2224 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2225 | case Primitive::kPrimByte: |
| 2226 | case Primitive::kPrimShort: |
| 2227 | case Primitive::kPrimInt: |
| 2228 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2229 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2230 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2231 | break; |
| 2232 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2233 | case Primitive::kPrimLong: { |
| 2234 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2235 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2236 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2237 | // Create stack space for the call to |
| 2238 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2239 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2240 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2241 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2242 | __ subl(ESP, Immediate(adjustment)); |
| 2243 | } |
| 2244 | |
| 2245 | // Load the value to the FP stack, using temporaries if needed. |
| 2246 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2247 | |
| 2248 | if (out.IsDoubleStackSlot()) { |
| 2249 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2250 | } else { |
| 2251 | __ fstpl(Address(ESP, 0)); |
| 2252 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2253 | codegen_->Move64(out, stack_temp); |
| 2254 | } |
| 2255 | |
| 2256 | // Remove the temporary stack space we allocated. |
| 2257 | if (adjustment != 0) { |
| 2258 | __ addl(ESP, Immediate(adjustment)); |
| 2259 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2260 | break; |
| 2261 | } |
| 2262 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2263 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2264 | // Processing a Dex `float-to-double' instruction. |
| 2265 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2266 | break; |
| 2267 | |
| 2268 | default: |
| 2269 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2270 | << " to " << result_type; |
| 2271 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2272 | break; |
| 2273 | |
| 2274 | default: |
| 2275 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2276 | << " to " << result_type; |
| 2277 | } |
| 2278 | } |
| 2279 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2280 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2281 | LocationSummary* locations = |
| 2282 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2283 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2284 | case Primitive::kPrimInt: { |
| 2285 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2286 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2287 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2288 | break; |
| 2289 | } |
| 2290 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2291 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2292 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2293 | locations->SetInAt(1, Location::Any()); |
| 2294 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2295 | break; |
| 2296 | } |
| 2297 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2298 | case Primitive::kPrimFloat: |
| 2299 | case Primitive::kPrimDouble: { |
| 2300 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2301 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2302 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2303 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2304 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2305 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2306 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2307 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2308 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2309 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2313 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2314 | Location first = locations->InAt(0); |
| 2315 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2316 | Location out = locations->Out(); |
| 2317 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2318 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2319 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2320 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2321 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2322 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2323 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2324 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2325 | } else { |
| 2326 | __ leal(out.AsRegister<Register>(), Address( |
| 2327 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2328 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2329 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2330 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2331 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2332 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2333 | } else { |
| 2334 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2335 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2336 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2337 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2338 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2339 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2340 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2344 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2345 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2346 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2347 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2348 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2349 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2350 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2351 | } else { |
| 2352 | DCHECK(second.IsConstant()) << second; |
| 2353 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2354 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2355 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2356 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2357 | break; |
| 2358 | } |
| 2359 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2360 | case Primitive::kPrimFloat: { |
| 2361 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2362 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2363 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2364 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2365 | DCHECK(!const_area->NeedsMaterialization()); |
| 2366 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2367 | codegen_->LiteralFloatAddress( |
| 2368 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2369 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2370 | } else { |
| 2371 | DCHECK(second.IsStackSlot()); |
| 2372 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2373 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2374 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | case Primitive::kPrimDouble: { |
| 2378 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2379 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2380 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2381 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2382 | DCHECK(!const_area->NeedsMaterialization()); |
| 2383 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2384 | codegen_->LiteralDoubleAddress( |
| 2385 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2386 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2387 | } else { |
| 2388 | DCHECK(second.IsDoubleStackSlot()); |
| 2389 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2390 | } |
| 2391 | break; |
| 2392 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2393 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2394 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2395 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2396 | } |
| 2397 | } |
| 2398 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2399 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2400 | LocationSummary* locations = |
| 2401 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2402 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2403 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2404 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2405 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2406 | locations->SetInAt(1, Location::Any()); |
| 2407 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2408 | break; |
| 2409 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2410 | case Primitive::kPrimFloat: |
| 2411 | case Primitive::kPrimDouble: { |
| 2412 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2413 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2414 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2415 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2416 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2417 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2418 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2419 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2420 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2424 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2425 | Location first = locations->InAt(0); |
| 2426 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2427 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2428 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2429 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2430 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2431 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2432 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2433 | __ subl(first.AsRegister<Register>(), |
| 2434 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2435 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2436 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2437 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2438 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2442 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2443 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2444 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2445 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2446 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2447 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2448 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2449 | } else { |
| 2450 | DCHECK(second.IsConstant()) << second; |
| 2451 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2452 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2453 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2454 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2455 | break; |
| 2456 | } |
| 2457 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2458 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2459 | if (second.IsFpuRegister()) { |
| 2460 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2461 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2462 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2463 | DCHECK(!const_area->NeedsMaterialization()); |
| 2464 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2465 | codegen_->LiteralFloatAddress( |
| 2466 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2467 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2468 | } else { |
| 2469 | DCHECK(second.IsStackSlot()); |
| 2470 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2471 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2472 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2476 | if (second.IsFpuRegister()) { |
| 2477 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2478 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2479 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2480 | DCHECK(!const_area->NeedsMaterialization()); |
| 2481 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2482 | codegen_->LiteralDoubleAddress( |
| 2483 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2484 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2485 | } else { |
| 2486 | DCHECK(second.IsDoubleStackSlot()); |
| 2487 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2488 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2489 | break; |
| 2490 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2491 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2492 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2493 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2494 | } |
| 2495 | } |
| 2496 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2497 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2498 | LocationSummary* locations = |
| 2499 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2500 | switch (mul->GetResultType()) { |
| 2501 | case Primitive::kPrimInt: |
| 2502 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2503 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2504 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2505 | // Can use 3 operand multiply. |
| 2506 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2507 | } else { |
| 2508 | locations->SetOut(Location::SameAsFirstInput()); |
| 2509 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2510 | break; |
| 2511 | case Primitive::kPrimLong: { |
| 2512 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2513 | locations->SetInAt(1, Location::Any()); |
| 2514 | locations->SetOut(Location::SameAsFirstInput()); |
| 2515 | // Needed for imul on 32bits with 64bits output. |
| 2516 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2517 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2518 | break; |
| 2519 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2520 | case Primitive::kPrimFloat: |
| 2521 | case Primitive::kPrimDouble: { |
| 2522 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2523 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2524 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2525 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2526 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2527 | |
| 2528 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2529 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2534 | LocationSummary* locations = mul->GetLocations(); |
| 2535 | Location first = locations->InAt(0); |
| 2536 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2537 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2538 | |
| 2539 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2540 | case Primitive::kPrimInt: |
| 2541 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2542 | // problems where the output may not be the same as the first operand. |
| 2543 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2544 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2545 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2546 | } else if (second.IsRegister()) { |
| 2547 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2548 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2549 | } else { |
| 2550 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2551 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2552 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2553 | } |
| 2554 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2555 | |
| 2556 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2557 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2558 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2559 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2560 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2561 | |
| 2562 | DCHECK_EQ(EAX, eax); |
| 2563 | DCHECK_EQ(EDX, edx); |
| 2564 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2565 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2566 | // output: in1 |
| 2567 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2568 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2569 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2570 | if (second.IsConstant()) { |
| 2571 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2572 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2573 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2574 | int32_t low_value = Low32Bits(value); |
| 2575 | int32_t high_value = High32Bits(value); |
| 2576 | Immediate low(low_value); |
| 2577 | Immediate high(high_value); |
| 2578 | |
| 2579 | __ movl(eax, high); |
| 2580 | // eax <- in1.lo * in2.hi |
| 2581 | __ imull(eax, in1_lo); |
| 2582 | // in1.hi <- in1.hi * in2.lo |
| 2583 | __ imull(in1_hi, low); |
| 2584 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2585 | __ addl(in1_hi, eax); |
| 2586 | // move in2_lo to eax to prepare for double precision |
| 2587 | __ movl(eax, low); |
| 2588 | // edx:eax <- in1.lo * in2.lo |
| 2589 | __ mull(in1_lo); |
| 2590 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2591 | __ addl(in1_hi, edx); |
| 2592 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2593 | __ movl(in1_lo, eax); |
| 2594 | } else if (second.IsRegisterPair()) { |
| 2595 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2596 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2597 | |
| 2598 | __ movl(eax, in2_hi); |
| 2599 | // eax <- in1.lo * in2.hi |
| 2600 | __ imull(eax, in1_lo); |
| 2601 | // in1.hi <- in1.hi * in2.lo |
| 2602 | __ imull(in1_hi, in2_lo); |
| 2603 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2604 | __ addl(in1_hi, eax); |
| 2605 | // move in1_lo to eax to prepare for double precision |
| 2606 | __ movl(eax, in1_lo); |
| 2607 | // edx:eax <- in1.lo * in2.lo |
| 2608 | __ mull(in2_lo); |
| 2609 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2610 | __ addl(in1_hi, edx); |
| 2611 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2612 | __ movl(in1_lo, eax); |
| 2613 | } else { |
| 2614 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2615 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2616 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2617 | |
| 2618 | __ movl(eax, in2_hi); |
| 2619 | // eax <- in1.lo * in2.hi |
| 2620 | __ imull(eax, in1_lo); |
| 2621 | // in1.hi <- in1.hi * in2.lo |
| 2622 | __ imull(in1_hi, in2_lo); |
| 2623 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2624 | __ addl(in1_hi, eax); |
| 2625 | // move in1_lo to eax to prepare for double precision |
| 2626 | __ movl(eax, in1_lo); |
| 2627 | // edx:eax <- in1.lo * in2.lo |
| 2628 | __ mull(in2_lo); |
| 2629 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2630 | __ addl(in1_hi, edx); |
| 2631 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2632 | __ movl(in1_lo, eax); |
| 2633 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2634 | |
| 2635 | break; |
| 2636 | } |
| 2637 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2638 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2639 | DCHECK(first.Equals(locations->Out())); |
| 2640 | if (second.IsFpuRegister()) { |
| 2641 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2642 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2643 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2644 | DCHECK(!const_area->NeedsMaterialization()); |
| 2645 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2646 | codegen_->LiteralFloatAddress( |
| 2647 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2648 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2649 | } else { |
| 2650 | DCHECK(second.IsStackSlot()); |
| 2651 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2652 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2653 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2657 | DCHECK(first.Equals(locations->Out())); |
| 2658 | if (second.IsFpuRegister()) { |
| 2659 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2660 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2661 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2662 | DCHECK(!const_area->NeedsMaterialization()); |
| 2663 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2664 | codegen_->LiteralDoubleAddress( |
| 2665 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2666 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2667 | } else { |
| 2668 | DCHECK(second.IsDoubleStackSlot()); |
| 2669 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2670 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2671 | break; |
| 2672 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2673 | |
| 2674 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2675 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2676 | } |
| 2677 | } |
| 2678 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2679 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 2680 | uint32_t temp_offset, |
| 2681 | uint32_t stack_adjustment, |
| 2682 | bool is_fp, |
| 2683 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2684 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2685 | DCHECK(!is_wide); |
| 2686 | if (is_fp) { |
| 2687 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2688 | } else { |
| 2689 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2690 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2691 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2692 | DCHECK(is_wide); |
| 2693 | if (is_fp) { |
| 2694 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2695 | } else { |
| 2696 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2697 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2698 | } else { |
| 2699 | // 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] | 2700 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2701 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2702 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2703 | if (is_fp) { |
| 2704 | __ flds(Address(ESP, temp_offset)); |
| 2705 | } else { |
| 2706 | __ filds(Address(ESP, temp_offset)); |
| 2707 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2708 | } else { |
| 2709 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2710 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2711 | if (is_fp) { |
| 2712 | __ fldl(Address(ESP, temp_offset)); |
| 2713 | } else { |
| 2714 | __ fildl(Address(ESP, temp_offset)); |
| 2715 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2716 | } |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2721 | Primitive::Type type = rem->GetResultType(); |
| 2722 | bool is_float = type == Primitive::kPrimFloat; |
| 2723 | size_t elem_size = Primitive::ComponentSize(type); |
| 2724 | LocationSummary* locations = rem->GetLocations(); |
| 2725 | Location first = locations->InAt(0); |
| 2726 | Location second = locations->InAt(1); |
| 2727 | Location out = locations->Out(); |
| 2728 | |
| 2729 | // Create stack space for 2 elements. |
| 2730 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2731 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2732 | |
| 2733 | // 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] | 2734 | const bool is_wide = !is_float; |
| 2735 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 2736 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2737 | |
| 2738 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2739 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2740 | __ Bind(&retry); |
| 2741 | __ fprem(); |
| 2742 | |
| 2743 | // Move FP status to AX. |
| 2744 | __ fstsw(); |
| 2745 | |
| 2746 | // And see if the argument reduction is complete. This is signaled by the |
| 2747 | // C2 FPU flag bit set to 0. |
| 2748 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2749 | __ j(kNotEqual, &retry); |
| 2750 | |
| 2751 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2752 | // Store FP top of stack to real stack. |
| 2753 | if (is_float) { |
| 2754 | __ fsts(Address(ESP, 0)); |
| 2755 | } else { |
| 2756 | __ fstl(Address(ESP, 0)); |
| 2757 | } |
| 2758 | |
| 2759 | // Pop the 2 items from the FP stack. |
| 2760 | __ fucompp(); |
| 2761 | |
| 2762 | // Load the value from the stack into an XMM register. |
| 2763 | DCHECK(out.IsFpuRegister()) << out; |
| 2764 | if (is_float) { |
| 2765 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2766 | } else { |
| 2767 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2768 | } |
| 2769 | |
| 2770 | // And remove the temporary stack space we allocated. |
| 2771 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2772 | } |
| 2773 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2774 | |
| 2775 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2776 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2777 | |
| 2778 | LocationSummary* locations = instruction->GetLocations(); |
| 2779 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2780 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2781 | |
| 2782 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2783 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2784 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2785 | |
| 2786 | DCHECK(imm == 1 || imm == -1); |
| 2787 | |
| 2788 | if (instruction->IsRem()) { |
| 2789 | __ xorl(out_register, out_register); |
| 2790 | } else { |
| 2791 | __ movl(out_register, input_register); |
| 2792 | if (imm == -1) { |
| 2793 | __ negl(out_register); |
| 2794 | } |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2799 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2800 | LocationSummary* locations = instruction->GetLocations(); |
| 2801 | |
| 2802 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2803 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2804 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2805 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2806 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2807 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2808 | |
| 2809 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2810 | __ testl(input_register, input_register); |
| 2811 | __ cmovl(kGreaterEqual, num, input_register); |
| 2812 | int shift = CTZ(imm); |
| 2813 | __ sarl(num, Immediate(shift)); |
| 2814 | |
| 2815 | if (imm < 0) { |
| 2816 | __ negl(num); |
| 2817 | } |
| 2818 | |
| 2819 | __ movl(out_register, num); |
| 2820 | } |
| 2821 | |
| 2822 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2823 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2824 | |
| 2825 | LocationSummary* locations = instruction->GetLocations(); |
| 2826 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2827 | |
| 2828 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2829 | Register out = locations->Out().AsRegister<Register>(); |
| 2830 | Register num; |
| 2831 | Register edx; |
| 2832 | |
| 2833 | if (instruction->IsDiv()) { |
| 2834 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2835 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2836 | } else { |
| 2837 | edx = locations->Out().AsRegister<Register>(); |
| 2838 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2839 | } |
| 2840 | |
| 2841 | DCHECK_EQ(EAX, eax); |
| 2842 | DCHECK_EQ(EDX, edx); |
| 2843 | if (instruction->IsDiv()) { |
| 2844 | DCHECK_EQ(EAX, out); |
| 2845 | } else { |
| 2846 | DCHECK_EQ(EDX, out); |
| 2847 | } |
| 2848 | |
| 2849 | int64_t magic; |
| 2850 | int shift; |
| 2851 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2852 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2853 | NearLabel ndiv; |
| 2854 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2855 | // If numerator is 0, the result is 0, no computation needed. |
| 2856 | __ testl(eax, eax); |
| 2857 | __ j(kNotEqual, &ndiv); |
| 2858 | |
| 2859 | __ xorl(out, out); |
| 2860 | __ jmp(&end); |
| 2861 | |
| 2862 | __ Bind(&ndiv); |
| 2863 | |
| 2864 | // Save the numerator. |
| 2865 | __ movl(num, eax); |
| 2866 | |
| 2867 | // EAX = magic |
| 2868 | __ movl(eax, Immediate(magic)); |
| 2869 | |
| 2870 | // EDX:EAX = magic * numerator |
| 2871 | __ imull(num); |
| 2872 | |
| 2873 | if (imm > 0 && magic < 0) { |
| 2874 | // EDX += num |
| 2875 | __ addl(edx, num); |
| 2876 | } else if (imm < 0 && magic > 0) { |
| 2877 | __ subl(edx, num); |
| 2878 | } |
| 2879 | |
| 2880 | // Shift if needed. |
| 2881 | if (shift != 0) { |
| 2882 | __ sarl(edx, Immediate(shift)); |
| 2883 | } |
| 2884 | |
| 2885 | // EDX += 1 if EDX < 0 |
| 2886 | __ movl(eax, edx); |
| 2887 | __ shrl(edx, Immediate(31)); |
| 2888 | __ addl(edx, eax); |
| 2889 | |
| 2890 | if (instruction->IsRem()) { |
| 2891 | __ movl(eax, num); |
| 2892 | __ imull(edx, Immediate(imm)); |
| 2893 | __ subl(eax, edx); |
| 2894 | __ movl(edx, eax); |
| 2895 | } else { |
| 2896 | __ movl(eax, edx); |
| 2897 | } |
| 2898 | __ Bind(&end); |
| 2899 | } |
| 2900 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2901 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2902 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2903 | |
| 2904 | LocationSummary* locations = instruction->GetLocations(); |
| 2905 | Location out = locations->Out(); |
| 2906 | Location first = locations->InAt(0); |
| 2907 | Location second = locations->InAt(1); |
| 2908 | bool is_div = instruction->IsDiv(); |
| 2909 | |
| 2910 | switch (instruction->GetResultType()) { |
| 2911 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2912 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2913 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2914 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2915 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2916 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2917 | |
| 2918 | if (imm == 0) { |
| 2919 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2920 | } else if (imm == 1 || imm == -1) { |
| 2921 | DivRemOneOrMinusOne(instruction); |
| 2922 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2923 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2924 | } else { |
| 2925 | DCHECK(imm <= -2 || imm >= 2); |
| 2926 | GenerateDivRemWithAnyConstant(instruction); |
| 2927 | } |
| 2928 | } else { |
| 2929 | SlowPathCodeX86* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2930 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2931 | is_div); |
| 2932 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2933 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2934 | Register second_reg = second.AsRegister<Register>(); |
| 2935 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2936 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2937 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2938 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2939 | __ cmpl(second_reg, Immediate(-1)); |
| 2940 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2941 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2942 | // edx:eax <- sign-extended of eax |
| 2943 | __ cdq(); |
| 2944 | // eax = quotient, edx = remainder |
| 2945 | __ idivl(second_reg); |
| 2946 | __ Bind(slow_path->GetExitLabel()); |
| 2947 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | } |
| 2950 | |
| 2951 | case Primitive::kPrimLong: { |
| 2952 | InvokeRuntimeCallingConvention calling_convention; |
| 2953 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2954 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2955 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2956 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2957 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2958 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2959 | |
| 2960 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2961 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2962 | instruction, |
| 2963 | instruction->GetDexPc(), |
| 2964 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2965 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2966 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 2967 | instruction, |
| 2968 | instruction->GetDexPc(), |
| 2969 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2970 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2971 | break; |
| 2972 | } |
| 2973 | |
| 2974 | default: |
| 2975 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 2976 | } |
| 2977 | } |
| 2978 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2979 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2980 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2981 | ? LocationSummary::kCall |
| 2982 | : LocationSummary::kNoCall; |
| 2983 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2984 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2985 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2986 | case Primitive::kPrimInt: { |
| 2987 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2988 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2989 | locations->SetOut(Location::SameAsFirstInput()); |
| 2990 | // Intel uses edx:eax as the dividend. |
| 2991 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2992 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2993 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 2994 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2995 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2996 | locations->AddTemp(Location::RequiresRegister()); |
| 2997 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2998 | break; |
| 2999 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3000 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3001 | InvokeRuntimeCallingConvention calling_convention; |
| 3002 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3003 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3004 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3005 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3006 | // Runtime helper puts the result in EAX, EDX. |
| 3007 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3008 | break; |
| 3009 | } |
| 3010 | case Primitive::kPrimFloat: |
| 3011 | case Primitive::kPrimDouble: { |
| 3012 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3013 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3014 | locations->SetOut(Location::SameAsFirstInput()); |
| 3015 | break; |
| 3016 | } |
| 3017 | |
| 3018 | default: |
| 3019 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3020 | } |
| 3021 | } |
| 3022 | |
| 3023 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3024 | LocationSummary* locations = div->GetLocations(); |
| 3025 | Location first = locations->InAt(0); |
| 3026 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3027 | |
| 3028 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3029 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3030 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3031 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3032 | break; |
| 3033 | } |
| 3034 | |
| 3035 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3036 | if (second.IsFpuRegister()) { |
| 3037 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3038 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3039 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3040 | DCHECK(!const_area->NeedsMaterialization()); |
| 3041 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3042 | codegen_->LiteralFloatAddress( |
| 3043 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3044 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3045 | } else { |
| 3046 | DCHECK(second.IsStackSlot()); |
| 3047 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3048 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3049 | break; |
| 3050 | } |
| 3051 | |
| 3052 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3053 | if (second.IsFpuRegister()) { |
| 3054 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3055 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3056 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3057 | DCHECK(!const_area->NeedsMaterialization()); |
| 3058 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3059 | codegen_->LiteralDoubleAddress( |
| 3060 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3061 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3062 | } else { |
| 3063 | DCHECK(second.IsDoubleStackSlot()); |
| 3064 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3065 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3066 | break; |
| 3067 | } |
| 3068 | |
| 3069 | default: |
| 3070 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3071 | } |
| 3072 | } |
| 3073 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3074 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3075 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3076 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3077 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3078 | ? LocationSummary::kCall |
| 3079 | : LocationSummary::kNoCall; |
| 3080 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3081 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3082 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3083 | case Primitive::kPrimInt: { |
| 3084 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3085 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3086 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3087 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3088 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3089 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3090 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3091 | locations->AddTemp(Location::RequiresRegister()); |
| 3092 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3093 | break; |
| 3094 | } |
| 3095 | case Primitive::kPrimLong: { |
| 3096 | InvokeRuntimeCallingConvention calling_convention; |
| 3097 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3098 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3099 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3100 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3101 | // Runtime helper puts the result in EAX, EDX. |
| 3102 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3103 | break; |
| 3104 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3105 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3106 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3107 | locations->SetInAt(0, Location::Any()); |
| 3108 | locations->SetInAt(1, Location::Any()); |
| 3109 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3110 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3111 | break; |
| 3112 | } |
| 3113 | |
| 3114 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3115 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3120 | Primitive::Type type = rem->GetResultType(); |
| 3121 | switch (type) { |
| 3122 | case Primitive::kPrimInt: |
| 3123 | case Primitive::kPrimLong: { |
| 3124 | GenerateDivRemIntegral(rem); |
| 3125 | break; |
| 3126 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3127 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3128 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3129 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3130 | break; |
| 3131 | } |
| 3132 | default: |
| 3133 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3134 | } |
| 3135 | } |
| 3136 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3137 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3138 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3139 | ? LocationSummary::kCallOnSlowPath |
| 3140 | : LocationSummary::kNoCall; |
| 3141 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3142 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3143 | case Primitive::kPrimByte: |
| 3144 | case Primitive::kPrimChar: |
| 3145 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3146 | case Primitive::kPrimInt: { |
| 3147 | locations->SetInAt(0, Location::Any()); |
| 3148 | break; |
| 3149 | } |
| 3150 | case Primitive::kPrimLong: { |
| 3151 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3152 | if (!instruction->IsConstant()) { |
| 3153 | locations->AddTemp(Location::RequiresRegister()); |
| 3154 | } |
| 3155 | break; |
| 3156 | } |
| 3157 | default: |
| 3158 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3159 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3160 | if (instruction->HasUses()) { |
| 3161 | locations->SetOut(Location::SameAsFirstInput()); |
| 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3166 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 3167 | codegen_->AddSlowPath(slow_path); |
| 3168 | |
| 3169 | LocationSummary* locations = instruction->GetLocations(); |
| 3170 | Location value = locations->InAt(0); |
| 3171 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3172 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3173 | case Primitive::kPrimByte: |
| 3174 | case Primitive::kPrimChar: |
| 3175 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3176 | case Primitive::kPrimInt: { |
| 3177 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3178 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3179 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3180 | } else if (value.IsStackSlot()) { |
| 3181 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3182 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3183 | } else { |
| 3184 | DCHECK(value.IsConstant()) << value; |
| 3185 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3186 | __ jmp(slow_path->GetEntryLabel()); |
| 3187 | } |
| 3188 | } |
| 3189 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3190 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3191 | case Primitive::kPrimLong: { |
| 3192 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3193 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3194 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3195 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3196 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3197 | } else { |
| 3198 | DCHECK(value.IsConstant()) << value; |
| 3199 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3200 | __ jmp(slow_path->GetEntryLabel()); |
| 3201 | } |
| 3202 | } |
| 3203 | break; |
| 3204 | } |
| 3205 | default: |
| 3206 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3207 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3210 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3211 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3212 | |
| 3213 | LocationSummary* locations = |
| 3214 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3215 | |
| 3216 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3217 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3218 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3219 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3220 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3221 | // The shift count needs to be in CL or a constant. |
| 3222 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3223 | locations->SetOut(Location::SameAsFirstInput()); |
| 3224 | break; |
| 3225 | } |
| 3226 | default: |
| 3227 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3232 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3233 | |
| 3234 | LocationSummary* locations = op->GetLocations(); |
| 3235 | Location first = locations->InAt(0); |
| 3236 | Location second = locations->InAt(1); |
| 3237 | DCHECK(first.Equals(locations->Out())); |
| 3238 | |
| 3239 | switch (op->GetResultType()) { |
| 3240 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3241 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3242 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3243 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3244 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3245 | DCHECK_EQ(ECX, second_reg); |
| 3246 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3247 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3248 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3249 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3250 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3251 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3252 | } |
| 3253 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3254 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3255 | if (shift == 0) { |
| 3256 | return; |
| 3257 | } |
| 3258 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3259 | if (op->IsShl()) { |
| 3260 | __ shll(first_reg, imm); |
| 3261 | } else if (op->IsShr()) { |
| 3262 | __ sarl(first_reg, imm); |
| 3263 | } else { |
| 3264 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3265 | } |
| 3266 | } |
| 3267 | break; |
| 3268 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3269 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3270 | if (second.IsRegister()) { |
| 3271 | Register second_reg = second.AsRegister<Register>(); |
| 3272 | DCHECK_EQ(ECX, second_reg); |
| 3273 | if (op->IsShl()) { |
| 3274 | GenerateShlLong(first, second_reg); |
| 3275 | } else if (op->IsShr()) { |
| 3276 | GenerateShrLong(first, second_reg); |
| 3277 | } else { |
| 3278 | GenerateUShrLong(first, second_reg); |
| 3279 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3280 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3281 | // Shift by a constant. |
| 3282 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3283 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3284 | if (shift != 0) { |
| 3285 | if (op->IsShl()) { |
| 3286 | GenerateShlLong(first, shift); |
| 3287 | } else if (op->IsShr()) { |
| 3288 | GenerateShrLong(first, shift); |
| 3289 | } else { |
| 3290 | GenerateUShrLong(first, shift); |
| 3291 | } |
| 3292 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3293 | } |
| 3294 | break; |
| 3295 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3296 | default: |
| 3297 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3298 | } |
| 3299 | } |
| 3300 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3301 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3302 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3303 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3304 | if (shift == 1) { |
| 3305 | // This is just an addition. |
| 3306 | __ addl(low, low); |
| 3307 | __ adcl(high, high); |
| 3308 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3309 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3310 | codegen_->EmitParallelMoves( |
| 3311 | loc.ToLow(), |
| 3312 | loc.ToHigh(), |
| 3313 | Primitive::kPrimInt, |
| 3314 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3315 | loc.ToLow(), |
| 3316 | Primitive::kPrimInt); |
| 3317 | } else if (shift > 32) { |
| 3318 | // Low part becomes 0. High part is low part << (shift-32). |
| 3319 | __ movl(high, low); |
| 3320 | __ shll(high, Immediate(shift - 32)); |
| 3321 | __ xorl(low, low); |
| 3322 | } else { |
| 3323 | // Between 1 and 31. |
| 3324 | __ shld(high, low, Immediate(shift)); |
| 3325 | __ shll(low, Immediate(shift)); |
| 3326 | } |
| 3327 | } |
| 3328 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3329 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3330 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3331 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3332 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3333 | __ testl(shifter, Immediate(32)); |
| 3334 | __ j(kEqual, &done); |
| 3335 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3336 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3337 | __ Bind(&done); |
| 3338 | } |
| 3339 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3340 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3341 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3342 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3343 | if (shift == 32) { |
| 3344 | // Need to copy the sign. |
| 3345 | DCHECK_NE(low, high); |
| 3346 | __ movl(low, high); |
| 3347 | __ sarl(high, Immediate(31)); |
| 3348 | } else if (shift > 32) { |
| 3349 | DCHECK_NE(low, high); |
| 3350 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3351 | __ movl(low, high); |
| 3352 | __ sarl(high, Immediate(31)); |
| 3353 | __ sarl(low, Immediate(shift - 32)); |
| 3354 | } else { |
| 3355 | // Between 1 and 31. |
| 3356 | __ shrd(low, high, Immediate(shift)); |
| 3357 | __ sarl(high, Immediate(shift)); |
| 3358 | } |
| 3359 | } |
| 3360 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3361 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3362 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3363 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3364 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3365 | __ testl(shifter, Immediate(32)); |
| 3366 | __ j(kEqual, &done); |
| 3367 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3368 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3369 | __ Bind(&done); |
| 3370 | } |
| 3371 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3372 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3373 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3374 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3375 | if (shift == 32) { |
| 3376 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3377 | codegen_->EmitParallelMoves( |
| 3378 | loc.ToHigh(), |
| 3379 | loc.ToLow(), |
| 3380 | Primitive::kPrimInt, |
| 3381 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3382 | loc.ToHigh(), |
| 3383 | Primitive::kPrimInt); |
| 3384 | } else if (shift > 32) { |
| 3385 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3386 | __ movl(low, high); |
| 3387 | __ shrl(low, Immediate(shift - 32)); |
| 3388 | __ xorl(high, high); |
| 3389 | } else { |
| 3390 | // Between 1 and 31. |
| 3391 | __ shrd(low, high, Immediate(shift)); |
| 3392 | __ shrl(high, Immediate(shift)); |
| 3393 | } |
| 3394 | } |
| 3395 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3396 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3397 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3398 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3399 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3400 | __ testl(shifter, Immediate(32)); |
| 3401 | __ j(kEqual, &done); |
| 3402 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3403 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3404 | __ Bind(&done); |
| 3405 | } |
| 3406 | |
| 3407 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3408 | HandleShift(shl); |
| 3409 | } |
| 3410 | |
| 3411 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3412 | HandleShift(shl); |
| 3413 | } |
| 3414 | |
| 3415 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3416 | HandleShift(shr); |
| 3417 | } |
| 3418 | |
| 3419 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3420 | HandleShift(shr); |
| 3421 | } |
| 3422 | |
| 3423 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3424 | HandleShift(ushr); |
| 3425 | } |
| 3426 | |
| 3427 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3428 | HandleShift(ushr); |
| 3429 | } |
| 3430 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3431 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3432 | LocationSummary* locations = |
| 3433 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3434 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3435 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3436 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3437 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3438 | } |
| 3439 | |
| 3440 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 3441 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3442 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3443 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3444 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3445 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3446 | instruction, |
| 3447 | instruction->GetDexPc(), |
| 3448 | nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3449 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3450 | } |
| 3451 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3452 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3453 | LocationSummary* locations = |
| 3454 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3455 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3456 | InvokeRuntimeCallingConvention calling_convention; |
| 3457 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3458 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3459 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3463 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3464 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 3465 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3466 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3467 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3468 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3469 | instruction, |
| 3470 | instruction->GetDexPc(), |
| 3471 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3472 | DCHECK(!codegen_->IsLeafMethod()); |
| 3473 | } |
| 3474 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3475 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3476 | LocationSummary* locations = |
| 3477 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3478 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3479 | if (location.IsStackSlot()) { |
| 3480 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3481 | } else if (location.IsDoubleStackSlot()) { |
| 3482 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3483 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3484 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3485 | } |
| 3486 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3487 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3488 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3489 | } |
| 3490 | |
| 3491 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3492 | LocationSummary* locations = |
| 3493 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3494 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3495 | } |
| 3496 | |
| 3497 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3498 | } |
| 3499 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3500 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3501 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3502 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3503 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3504 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3505 | } |
| 3506 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3507 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3508 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3509 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3510 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3511 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3512 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3513 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3514 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3515 | break; |
| 3516 | |
| 3517 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3518 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3519 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3520 | break; |
| 3521 | |
| 3522 | default: |
| 3523 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3524 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3525 | } |
| 3526 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3527 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3528 | LocationSummary* locations = |
| 3529 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3530 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3531 | locations->SetOut(Location::SameAsFirstInput()); |
| 3532 | } |
| 3533 | |
| 3534 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3535 | LocationSummary* locations = bool_not->GetLocations(); |
| 3536 | Location in = locations->InAt(0); |
| 3537 | Location out = locations->Out(); |
| 3538 | DCHECK(in.Equals(out)); |
| 3539 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3540 | } |
| 3541 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3542 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3543 | LocationSummary* locations = |
| 3544 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3545 | switch (compare->InputAt(0)->GetType()) { |
| 3546 | case Primitive::kPrimLong: { |
| 3547 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3548 | locations->SetInAt(1, Location::Any()); |
| 3549 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3550 | break; |
| 3551 | } |
| 3552 | case Primitive::kPrimFloat: |
| 3553 | case Primitive::kPrimDouble: { |
| 3554 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3555 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3556 | locations->SetOut(Location::RequiresRegister()); |
| 3557 | break; |
| 3558 | } |
| 3559 | default: |
| 3560 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3561 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3565 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3566 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3567 | Location left = locations->InAt(0); |
| 3568 | Location right = locations->InAt(1); |
| 3569 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3570 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3571 | switch (compare->InputAt(0)->GetType()) { |
| 3572 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3573 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 3574 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 3575 | int32_t val_low = 0; |
| 3576 | int32_t val_high = 0; |
| 3577 | bool right_is_const = false; |
| 3578 | |
| 3579 | if (right.IsConstant()) { |
| 3580 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 3581 | right_is_const = true; |
| 3582 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 3583 | val_low = Low32Bits(val); |
| 3584 | val_high = High32Bits(val); |
| 3585 | } |
| 3586 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3587 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3588 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3589 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3590 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3591 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3592 | DCHECK(right_is_const) << right; |
| 3593 | if (val_high == 0) { |
| 3594 | __ testl(left_high, left_high); |
| 3595 | } else { |
| 3596 | __ cmpl(left_high, Immediate(val_high)); |
| 3597 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3598 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3599 | __ j(kLess, &less); // Signed compare. |
| 3600 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3601 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3602 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3603 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3604 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3605 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3606 | DCHECK(right_is_const) << right; |
| 3607 | if (val_low == 0) { |
| 3608 | __ testl(left_low, left_low); |
| 3609 | } else { |
| 3610 | __ cmpl(left_low, Immediate(val_low)); |
| 3611 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3612 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3613 | break; |
| 3614 | } |
| 3615 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3616 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3617 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3618 | break; |
| 3619 | } |
| 3620 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3621 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3622 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3623 | break; |
| 3624 | } |
| 3625 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3626 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3627 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3628 | __ movl(out, Immediate(0)); |
| 3629 | __ j(kEqual, &done); |
| 3630 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3631 | |
| 3632 | __ Bind(&greater); |
| 3633 | __ movl(out, Immediate(1)); |
| 3634 | __ jmp(&done); |
| 3635 | |
| 3636 | __ Bind(&less); |
| 3637 | __ movl(out, Immediate(-1)); |
| 3638 | |
| 3639 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3640 | } |
| 3641 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3642 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3643 | LocationSummary* locations = |
| 3644 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3645 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3646 | locations->SetInAt(i, Location::Any()); |
| 3647 | } |
| 3648 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3649 | } |
| 3650 | |
| 3651 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3652 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3653 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3654 | } |
| 3655 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3656 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3657 | /* |
| 3658 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3659 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3660 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3661 | */ |
| 3662 | switch (kind) { |
| 3663 | case MemBarrierKind::kAnyAny: { |
| 3664 | __ mfence(); |
| 3665 | break; |
| 3666 | } |
| 3667 | case MemBarrierKind::kAnyStore: |
| 3668 | case MemBarrierKind::kLoadAny: |
| 3669 | case MemBarrierKind::kStoreStore: { |
| 3670 | // nop |
| 3671 | break; |
| 3672 | } |
| 3673 | default: |
| 3674 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3675 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3676 | } |
| 3677 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3678 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3679 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 3680 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3681 | switch (invoke->GetMethodLoadKind()) { |
| 3682 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3683 | // temp = thread->string_init_entrypoint |
| 3684 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 3685 | break; |
| 3686 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 3687 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3688 | break; |
| 3689 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3690 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 3691 | break; |
| 3692 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3693 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 3694 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3695 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 3696 | break; |
| 3697 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 3698 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 3699 | FALLTHROUGH_INTENDED; |
| 3700 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 3701 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3702 | Register method_reg; |
| 3703 | Register reg = temp.AsRegister<Register>(); |
| 3704 | if (current_method.IsRegister()) { |
| 3705 | method_reg = current_method.AsRegister<Register>(); |
| 3706 | } else { |
| 3707 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 3708 | DCHECK(!current_method.IsValid()); |
| 3709 | method_reg = reg; |
| 3710 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 3711 | } |
| 3712 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3713 | __ movl(reg, Address(method_reg, |
| 3714 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3715 | // temp = temp[index_in_cache] |
| 3716 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3717 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 3718 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3719 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | switch (invoke->GetCodePtrLocation()) { |
| 3723 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3724 | __ call(GetFrameEntryLabel()); |
| 3725 | break; |
| 3726 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3727 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3728 | Label* label = &relative_call_patches_.back().label; |
| 3729 | __ call(label); // Bind to the patch label, override at link time. |
| 3730 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 3731 | break; |
| 3732 | } |
| 3733 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3734 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3735 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 3736 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 3737 | FALLTHROUGH_INTENDED; |
| 3738 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3739 | // (callee_method + offset_of_quick_compiled_code)() |
| 3740 | __ call(Address(callee_method.AsRegister<Register>(), |
| 3741 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3742 | kX86WordSize).Int32Value())); |
| 3743 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3747 | } |
| 3748 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3749 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 3750 | Register temp = temp_in.AsRegister<Register>(); |
| 3751 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3752 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| 3753 | LocationSummary* locations = invoke->GetLocations(); |
| 3754 | Location receiver = locations->InAt(0); |
| 3755 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3756 | // temp = object->GetClass(); |
| 3757 | DCHECK(receiver.IsRegister()); |
| 3758 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| 3759 | MaybeRecordImplicitNullCheck(invoke); |
| 3760 | __ MaybeUnpoisonHeapReference(temp); |
| 3761 | // temp = temp->GetMethodAt(method_offset); |
| 3762 | __ movl(temp, Address(temp, method_offset)); |
| 3763 | // call temp->GetEntryPoint(); |
| 3764 | __ call(Address( |
| 3765 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 3766 | } |
| 3767 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3768 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3769 | DCHECK(linker_patches->empty()); |
| 3770 | linker_patches->reserve(method_patches_.size() + relative_call_patches_.size()); |
| 3771 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 3772 | // The label points to the end of the "movl" insn but the literal offset for method |
| 3773 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3774 | uint32_t literal_offset = info.label.Position() - 4; |
| 3775 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 3776 | info.target_method.dex_file, |
| 3777 | info.target_method.dex_method_index)); |
| 3778 | } |
| 3779 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 3780 | // The label points to the end of the "call" insn but the literal offset for method |
| 3781 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3782 | uint32_t literal_offset = info.label.Position() - 4; |
| 3783 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 3784 | info.target_method.dex_file, |
| 3785 | info.target_method.dex_method_index)); |
| 3786 | } |
| 3787 | } |
| 3788 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3789 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 3790 | Register card, |
| 3791 | Register object, |
| 3792 | Register value, |
| 3793 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3794 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3795 | if (value_can_be_null) { |
| 3796 | __ testl(value, value); |
| 3797 | __ j(kEqual, &is_null); |
| 3798 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3799 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3800 | __ movl(temp, object); |
| 3801 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3802 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3803 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3804 | if (value_can_be_null) { |
| 3805 | __ Bind(&is_null); |
| 3806 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3807 | } |
| 3808 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3809 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3810 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3811 | LocationSummary* locations = |
| 3812 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3813 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3814 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3815 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3816 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3817 | } else { |
| 3818 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3819 | // the object's location. |
| 3820 | locations->SetOut(Location::RequiresRegister(), |
| 3821 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3822 | : Location::kNoOutputOverlap); |
| 3823 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3824 | |
| 3825 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3826 | // Long values can be loaded atomically into an XMM using movsd. |
| 3827 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3828 | // and then copy the XMM into the output 32bits at a time). |
| 3829 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3830 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3831 | } |
| 3832 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3833 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3834 | const FieldInfo& field_info) { |
| 3835 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3836 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3837 | LocationSummary* locations = instruction->GetLocations(); |
| 3838 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3839 | Location out = locations->Out(); |
| 3840 | bool is_volatile = field_info.IsVolatile(); |
| 3841 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3842 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3843 | |
| 3844 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3845 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3846 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3847 | break; |
| 3848 | } |
| 3849 | |
| 3850 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3851 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3852 | break; |
| 3853 | } |
| 3854 | |
| 3855 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3856 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3857 | break; |
| 3858 | } |
| 3859 | |
| 3860 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3861 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3862 | break; |
| 3863 | } |
| 3864 | |
| 3865 | case Primitive::kPrimInt: |
| 3866 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3867 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3868 | break; |
| 3869 | } |
| 3870 | |
| 3871 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3872 | if (is_volatile) { |
| 3873 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3874 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3875 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3876 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3877 | __ psrlq(temp, Immediate(32)); |
| 3878 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3879 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3880 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3881 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3882 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3883 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3884 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3885 | break; |
| 3886 | } |
| 3887 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3888 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3889 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3890 | break; |
| 3891 | } |
| 3892 | |
| 3893 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3894 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3895 | break; |
| 3896 | } |
| 3897 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3898 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3899 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3900 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3901 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3902 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3903 | // Longs are handled in the switch. |
| 3904 | if (field_type != Primitive::kPrimLong) { |
| 3905 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3906 | } |
| 3907 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3908 | if (is_volatile) { |
| 3909 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3910 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3911 | |
| 3912 | if (field_type == Primitive::kPrimNot) { |
| 3913 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3914 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3918 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3919 | |
| 3920 | LocationSummary* locations = |
| 3921 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3922 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3923 | bool is_volatile = field_info.IsVolatile(); |
| 3924 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3925 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3926 | || (field_type == Primitive::kPrimByte); |
| 3927 | |
| 3928 | // The register allocator does not support multiple |
| 3929 | // inputs that die at entry with one in a specific register. |
| 3930 | if (is_byte_type) { |
| 3931 | // Ensure the value is in a byte register. |
| 3932 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3933 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3934 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3935 | } else { |
| 3936 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3937 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3938 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3939 | // Temporary registers for the write barrier. |
| 3940 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3941 | // Ensure the card is in a byte register. |
| 3942 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3943 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3944 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3945 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3946 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3947 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3948 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3949 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3950 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3951 | } |
| 3952 | } |
| 3953 | |
| 3954 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3955 | const FieldInfo& field_info, |
| 3956 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3957 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3958 | |
| 3959 | LocationSummary* locations = instruction->GetLocations(); |
| 3960 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3961 | Location value = locations->InAt(1); |
| 3962 | bool is_volatile = field_info.IsVolatile(); |
| 3963 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3964 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3965 | bool needs_write_barrier = |
| 3966 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3967 | |
| 3968 | if (is_volatile) { |
| 3969 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3970 | } |
| 3971 | |
| 3972 | switch (field_type) { |
| 3973 | case Primitive::kPrimBoolean: |
| 3974 | case Primitive::kPrimByte: { |
| 3975 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 3976 | break; |
| 3977 | } |
| 3978 | |
| 3979 | case Primitive::kPrimShort: |
| 3980 | case Primitive::kPrimChar: { |
| 3981 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 3982 | break; |
| 3983 | } |
| 3984 | |
| 3985 | case Primitive::kPrimInt: |
| 3986 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3987 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3988 | // Note that in the case where `value` is a null reference, |
| 3989 | // we do not enter this block, as the reference does not |
| 3990 | // need poisoning. |
| 3991 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3992 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3993 | __ movl(temp, value.AsRegister<Register>()); |
| 3994 | __ PoisonHeapReference(temp); |
| 3995 | __ movl(Address(base, offset), temp); |
| 3996 | } else { |
| 3997 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 3998 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3999 | break; |
| 4000 | } |
| 4001 | |
| 4002 | case Primitive::kPrimLong: { |
| 4003 | if (is_volatile) { |
| 4004 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4005 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4006 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4007 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4008 | __ punpckldq(temp1, temp2); |
| 4009 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4010 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4011 | } else { |
| 4012 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4013 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4014 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4015 | } |
| 4016 | break; |
| 4017 | } |
| 4018 | |
| 4019 | case Primitive::kPrimFloat: { |
| 4020 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4021 | break; |
| 4022 | } |
| 4023 | |
| 4024 | case Primitive::kPrimDouble: { |
| 4025 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4026 | break; |
| 4027 | } |
| 4028 | |
| 4029 | case Primitive::kPrimVoid: |
| 4030 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4031 | UNREACHABLE(); |
| 4032 | } |
| 4033 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4034 | // Longs are handled in the switch. |
| 4035 | if (field_type != Primitive::kPrimLong) { |
| 4036 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4037 | } |
| 4038 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4039 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4040 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4041 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4042 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4043 | } |
| 4044 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4045 | if (is_volatile) { |
| 4046 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4051 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4052 | } |
| 4053 | |
| 4054 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4055 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4056 | } |
| 4057 | |
| 4058 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4059 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4060 | } |
| 4061 | |
| 4062 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4063 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4067 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4068 | } |
| 4069 | |
| 4070 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4071 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4072 | } |
| 4073 | |
| 4074 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4075 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4076 | } |
| 4077 | |
| 4078 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4079 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4080 | } |
| 4081 | |
Calin Juravle | 23a8e35 | 2015-09-08 19:56:31 +0100 | [diff] [blame] | 4082 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4083 | HUnresolvedInstanceFieldGet* instruction) { |
| 4084 | FieldAccessCallingConvetionX86 calling_convention; |
| 4085 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4086 | instruction, instruction->GetFieldType(), calling_convention); |
| 4087 | } |
| 4088 | |
| 4089 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4090 | HUnresolvedInstanceFieldGet* instruction) { |
| 4091 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4092 | instruction->GetFieldType(), |
| 4093 | instruction->GetFieldIndex(), |
| 4094 | instruction->GetDexPc()); |
| 4095 | } |
| 4096 | |
| 4097 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4098 | HUnresolvedInstanceFieldSet* instruction) { |
| 4099 | FieldAccessCallingConvetionX86 calling_convention; |
| 4100 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4101 | instruction, instruction->GetFieldType(), calling_convention); |
| 4102 | } |
| 4103 | |
| 4104 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4105 | HUnresolvedInstanceFieldSet* instruction) { |
| 4106 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4107 | instruction->GetFieldType(), |
| 4108 | instruction->GetFieldIndex(), |
| 4109 | instruction->GetDexPc()); |
| 4110 | } |
| 4111 | |
| 4112 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4113 | HUnresolvedStaticFieldGet* instruction) { |
| 4114 | FieldAccessCallingConvetionX86 calling_convention; |
| 4115 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4116 | instruction, instruction->GetFieldType(), calling_convention); |
| 4117 | } |
| 4118 | |
| 4119 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4120 | HUnresolvedStaticFieldGet* instruction) { |
| 4121 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4122 | instruction->GetFieldType(), |
| 4123 | instruction->GetFieldIndex(), |
| 4124 | instruction->GetDexPc()); |
| 4125 | } |
| 4126 | |
| 4127 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4128 | HUnresolvedStaticFieldSet* instruction) { |
| 4129 | FieldAccessCallingConvetionX86 calling_convention; |
| 4130 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4131 | instruction, instruction->GetFieldType(), calling_convention); |
| 4132 | } |
| 4133 | |
| 4134 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4135 | HUnresolvedStaticFieldSet* instruction) { |
| 4136 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4137 | instruction->GetFieldType(), |
| 4138 | instruction->GetFieldIndex(), |
| 4139 | instruction->GetDexPc()); |
| 4140 | } |
| 4141 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4142 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4143 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4144 | ? LocationSummary::kCallOnSlowPath |
| 4145 | : LocationSummary::kNoCall; |
| 4146 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4147 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4148 | ? Location::RequiresRegister() |
| 4149 | : Location::Any(); |
| 4150 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4151 | if (instruction->HasUses()) { |
| 4152 | locations->SetOut(Location::SameAsFirstInput()); |
| 4153 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4154 | } |
| 4155 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4156 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4157 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4158 | return; |
| 4159 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4160 | LocationSummary* locations = instruction->GetLocations(); |
| 4161 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4162 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4163 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4164 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4165 | } |
| 4166 | |
| 4167 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 4168 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4169 | codegen_->AddSlowPath(slow_path); |
| 4170 | |
| 4171 | LocationSummary* locations = instruction->GetLocations(); |
| 4172 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4173 | |
| 4174 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4175 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4176 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4177 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4178 | } else { |
| 4179 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4180 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4181 | __ jmp(slow_path->GetEntryLabel()); |
| 4182 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4183 | } |
| 4184 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4185 | } |
| 4186 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4187 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4188 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4189 | GenerateImplicitNullCheck(instruction); |
| 4190 | } else { |
| 4191 | GenerateExplicitNullCheck(instruction); |
| 4192 | } |
| 4193 | } |
| 4194 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4195 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4196 | LocationSummary* locations = |
| 4197 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4198 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4199 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4200 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4201 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4202 | } else { |
| 4203 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 4204 | // the array's location. |
| 4205 | locations->SetOut(Location::RequiresRegister(), |
| 4206 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 4207 | : Location::kNoOutputOverlap); |
| 4208 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4212 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4213 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4214 | Location index = locations->InAt(1); |
| 4215 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4216 | Primitive::Type type = instruction->GetType(); |
| 4217 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4218 | case Primitive::kPrimBoolean: { |
| 4219 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4220 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4221 | if (index.IsConstant()) { |
| 4222 | __ movzxb(out, Address(obj, |
| 4223 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4224 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4225 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4226 | } |
| 4227 | break; |
| 4228 | } |
| 4229 | |
| 4230 | case Primitive::kPrimByte: { |
| 4231 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4232 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4233 | if (index.IsConstant()) { |
| 4234 | __ movsxb(out, Address(obj, |
| 4235 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4236 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4237 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4238 | } |
| 4239 | break; |
| 4240 | } |
| 4241 | |
| 4242 | case Primitive::kPrimShort: { |
| 4243 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4244 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4245 | if (index.IsConstant()) { |
| 4246 | __ movsxw(out, Address(obj, |
| 4247 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4248 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4249 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4250 | } |
| 4251 | break; |
| 4252 | } |
| 4253 | |
| 4254 | case Primitive::kPrimChar: { |
| 4255 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4256 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4257 | if (index.IsConstant()) { |
| 4258 | __ movzxw(out, Address(obj, |
| 4259 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4260 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4261 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4262 | } |
| 4263 | break; |
| 4264 | } |
| 4265 | |
| 4266 | case Primitive::kPrimInt: |
| 4267 | case Primitive::kPrimNot: { |
| 4268 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4269 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4270 | if (index.IsConstant()) { |
| 4271 | __ movl(out, Address(obj, |
| 4272 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4273 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4274 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4275 | } |
| 4276 | break; |
| 4277 | } |
| 4278 | |
| 4279 | case Primitive::kPrimLong: { |
| 4280 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4281 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4282 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4283 | if (index.IsConstant()) { |
| 4284 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4285 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4286 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4287 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4288 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4289 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4290 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4291 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4292 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4293 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4294 | } |
| 4295 | break; |
| 4296 | } |
| 4297 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4298 | case Primitive::kPrimFloat: { |
| 4299 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4300 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4301 | if (index.IsConstant()) { |
| 4302 | __ movss(out, Address(obj, |
| 4303 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4304 | } else { |
| 4305 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4306 | } |
| 4307 | break; |
| 4308 | } |
| 4309 | |
| 4310 | case Primitive::kPrimDouble: { |
| 4311 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4312 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4313 | if (index.IsConstant()) { |
| 4314 | __ movsd(out, Address(obj, |
| 4315 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4316 | } else { |
| 4317 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 4318 | } |
| 4319 | break; |
| 4320 | } |
| 4321 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4322 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4323 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4324 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4325 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4326 | |
| 4327 | if (type != Primitive::kPrimLong) { |
| 4328 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4329 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4330 | |
| 4331 | if (type == Primitive::kPrimNot) { |
| 4332 | Register out = locations->Out().AsRegister<Register>(); |
| 4333 | __ MaybeUnpoisonHeapReference(out); |
| 4334 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4338 | // This location builder might end up asking to up to four registers, which is |
| 4339 | // not currently possible for baseline. The situation in which we need four |
| 4340 | // registers cannot be met by baseline though, because it has not run any |
| 4341 | // optimization. |
| 4342 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4343 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4344 | bool needs_write_barrier = |
| 4345 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 4346 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4347 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4348 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4349 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4350 | instruction, |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4351 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4352 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4353 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4354 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4355 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4356 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4357 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4358 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4359 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4360 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4361 | // 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] | 4362 | // In case of a byte operation, the register allocator does not support multiple |
| 4363 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4364 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4365 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4366 | if (is_byte_type) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4367 | // Ensure the value is in a byte register. |
| 4368 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4369 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 4370 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4371 | } else { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4372 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4373 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4374 | if (needs_write_barrier) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4375 | // Temporary registers for the write barrier. |
| 4376 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4377 | // Ensure the card is in a byte register. |
| 4378 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4379 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4380 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4384 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4385 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4386 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4387 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4388 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4389 | bool needs_runtime_call = locations->WillCall(); |
| 4390 | bool needs_write_barrier = |
| 4391 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4392 | |
| 4393 | switch (value_type) { |
| 4394 | case Primitive::kPrimBoolean: |
| 4395 | case Primitive::kPrimByte: { |
| 4396 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4397 | if (index.IsConstant()) { |
| 4398 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4399 | if (value.IsRegister()) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4400 | __ movb(Address(obj, offset), value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4401 | } else { |
| 4402 | __ movb(Address(obj, offset), |
| 4403 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4404 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4405 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4406 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4407 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4408 | value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4409 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4410 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4411 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4412 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4413 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4414 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4415 | break; |
| 4416 | } |
| 4417 | |
| 4418 | case Primitive::kPrimShort: |
| 4419 | case Primitive::kPrimChar: { |
| 4420 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4421 | if (index.IsConstant()) { |
| 4422 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4423 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4424 | __ movw(Address(obj, offset), value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4425 | } else { |
| 4426 | __ movw(Address(obj, offset), |
| 4427 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4428 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4429 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4430 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4431 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
| 4432 | value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4433 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4434 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4435 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4436 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4437 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4438 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4439 | break; |
| 4440 | } |
| 4441 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4442 | case Primitive::kPrimInt: |
| 4443 | case Primitive::kPrimNot: { |
| 4444 | if (!needs_runtime_call) { |
| 4445 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4446 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4447 | size_t offset = |
| 4448 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4449 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4450 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4451 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4452 | __ movl(temp, value.AsRegister<Register>()); |
| 4453 | __ PoisonHeapReference(temp); |
| 4454 | __ movl(Address(obj, offset), temp); |
| 4455 | } else { |
| 4456 | __ movl(Address(obj, offset), value.AsRegister<Register>()); |
| 4457 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4458 | } else { |
| 4459 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4460 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4461 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4462 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4463 | // Note: if heap poisoning is enabled, no need to poison |
| 4464 | // (negate) `v` if it is a reference, as it would be null. |
| 4465 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4466 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4467 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4468 | DCHECK(index.IsRegister()) << index; |
| 4469 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4470 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4471 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4472 | __ movl(temp, value.AsRegister<Register>()); |
| 4473 | __ PoisonHeapReference(temp); |
| 4474 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), temp); |
| 4475 | } else { |
| 4476 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4477 | value.AsRegister<Register>()); |
| 4478 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4479 | } else { |
| 4480 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4481 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4482 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4483 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4484 | // Note: if heap poisoning is enabled, no need to poison |
| 4485 | // (negate) `v` if it is a reference, as it would be null. |
| 4486 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4487 | } |
| 4488 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4489 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4490 | |
| 4491 | if (needs_write_barrier) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4492 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4493 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4494 | codegen_->MarkGCCard( |
| 4495 | temp, card, obj, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4496 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4497 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4498 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4499 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4500 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4501 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4502 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4503 | instruction, |
| 4504 | instruction->GetDexPc(), |
| 4505 | nullptr); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4506 | } |
| 4507 | break; |
| 4508 | } |
| 4509 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4510 | case Primitive::kPrimLong: { |
| 4511 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4512 | if (index.IsConstant()) { |
| 4513 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4514 | if (value.IsRegisterPair()) { |
| 4515 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4516 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4517 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4518 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4519 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4520 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4521 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4522 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4523 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 4524 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4525 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4526 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4527 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4528 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4529 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4530 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4531 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4532 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4533 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4534 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4535 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4536 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4537 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4538 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4539 | Immediate(High32Bits(val))); |
| 4540 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4541 | } |
| 4542 | break; |
| 4543 | } |
| 4544 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4545 | case Primitive::kPrimFloat: { |
| 4546 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4547 | DCHECK(value.IsFpuRegister()); |
| 4548 | if (index.IsConstant()) { |
| 4549 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4550 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4551 | } else { |
| 4552 | __ movss(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4553 | value.AsFpuRegister<XmmRegister>()); |
| 4554 | } |
| 4555 | break; |
| 4556 | } |
| 4557 | |
| 4558 | case Primitive::kPrimDouble: { |
| 4559 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4560 | DCHECK(value.IsFpuRegister()); |
| 4561 | if (index.IsConstant()) { |
| 4562 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4563 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4564 | } else { |
| 4565 | __ movsd(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
| 4566 | value.AsFpuRegister<XmmRegister>()); |
| 4567 | } |
| 4568 | break; |
| 4569 | } |
| 4570 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4571 | case Primitive::kPrimVoid: |
| 4572 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4573 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 4578 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4579 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4580 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 4584 | LocationSummary* locations = instruction->GetLocations(); |
| 4585 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4586 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4587 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4588 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4589 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4593 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4594 | ? LocationSummary::kCallOnSlowPath |
| 4595 | : LocationSummary::kNoCall; |
| 4596 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4597 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4598 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4599 | if (instruction->HasUses()) { |
| 4600 | locations->SetOut(Location::SameAsFirstInput()); |
| 4601 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4605 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4606 | Location index_loc = locations->InAt(0); |
| 4607 | Location length_loc = locations->InAt(1); |
| 4608 | SlowPathCodeX86* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4609 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4610 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4611 | if (length_loc.IsConstant()) { |
| 4612 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4613 | if (index_loc.IsConstant()) { |
| 4614 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4615 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4616 | if (index < 0 || index >= length) { |
| 4617 | codegen_->AddSlowPath(slow_path); |
| 4618 | __ jmp(slow_path->GetEntryLabel()); |
| 4619 | } else { |
| 4620 | // Some optimization after BCE may have generated this, and we should not |
| 4621 | // generate a bounds check if it is a valid range. |
| 4622 | } |
| 4623 | return; |
| 4624 | } |
| 4625 | |
| 4626 | // We have to reverse the jump condition because the length is the constant. |
| 4627 | Register index_reg = index_loc.AsRegister<Register>(); |
| 4628 | __ cmpl(index_reg, Immediate(length)); |
| 4629 | codegen_->AddSlowPath(slow_path); |
| 4630 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4631 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4632 | Register length = length_loc.AsRegister<Register>(); |
| 4633 | if (index_loc.IsConstant()) { |
| 4634 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4635 | __ cmpl(length, Immediate(value)); |
| 4636 | } else { |
| 4637 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 4638 | } |
| 4639 | codegen_->AddSlowPath(slow_path); |
| 4640 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4641 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4644 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 4645 | temp->SetLocations(nullptr); |
| 4646 | } |
| 4647 | |
| 4648 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 4649 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4650 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4651 | } |
| 4652 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4653 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4654 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4655 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4659 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4660 | } |
| 4661 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4662 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4663 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4664 | } |
| 4665 | |
| 4666 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4667 | HBasicBlock* block = instruction->GetBlock(); |
| 4668 | if (block->GetLoopInformation() != nullptr) { |
| 4669 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4670 | // The back edge will generate the suspend check. |
| 4671 | return; |
| 4672 | } |
| 4673 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4674 | // The goto will generate the suspend check. |
| 4675 | return; |
| 4676 | } |
| 4677 | GenerateSuspendCheck(instruction, nullptr); |
| 4678 | } |
| 4679 | |
| 4680 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4681 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4682 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4683 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 4684 | if (slow_path == nullptr) { |
| 4685 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 4686 | instruction->SetSlowPath(slow_path); |
| 4687 | codegen_->AddSlowPath(slow_path); |
| 4688 | if (successor != nullptr) { |
| 4689 | DCHECK(successor->IsLoopHeader()); |
| 4690 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4691 | } |
| 4692 | } else { |
| 4693 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4694 | } |
| 4695 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4696 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4697 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4698 | if (successor == nullptr) { |
| 4699 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4700 | __ Bind(slow_path->GetReturnLabel()); |
| 4701 | } else { |
| 4702 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4703 | __ jmp(slow_path->GetEntryLabel()); |
| 4704 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4705 | } |
| 4706 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4707 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 4708 | return codegen_->GetAssembler(); |
| 4709 | } |
| 4710 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4711 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4712 | ScratchRegisterScope ensure_scratch( |
| 4713 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4714 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4715 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4716 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4717 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4721 | ScratchRegisterScope ensure_scratch( |
| 4722 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4723 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4724 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4725 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4726 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 4727 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 4728 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 4732 | MoveOperands* move = moves_.Get(index); |
| 4733 | Location source = move->GetSource(); |
| 4734 | Location destination = move->GetDestination(); |
| 4735 | |
| 4736 | if (source.IsRegister()) { |
| 4737 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4738 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4739 | } else { |
| 4740 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4741 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4742 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4743 | } else if (source.IsFpuRegister()) { |
| 4744 | if (destination.IsFpuRegister()) { |
| 4745 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4746 | } else if (destination.IsStackSlot()) { |
| 4747 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4748 | } else { |
| 4749 | DCHECK(destination.IsDoubleStackSlot()); |
| 4750 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4751 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4752 | } else if (source.IsStackSlot()) { |
| 4753 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4754 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4755 | } else if (destination.IsFpuRegister()) { |
| 4756 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4757 | } else { |
| 4758 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4759 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4760 | } |
| 4761 | } else if (source.IsDoubleStackSlot()) { |
| 4762 | if (destination.IsFpuRegister()) { |
| 4763 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 4764 | } else { |
| 4765 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4766 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4767 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4768 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4769 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4770 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4771 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4772 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4773 | if (value == 0) { |
| 4774 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4775 | } else { |
| 4776 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 4777 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4778 | } else { |
| 4779 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4780 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4781 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4782 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4783 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4784 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4785 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4786 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4787 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4788 | if (value == 0) { |
| 4789 | // Easy handling of 0.0. |
| 4790 | __ xorps(dest, dest); |
| 4791 | } else { |
| 4792 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4793 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4794 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4795 | __ movl(temp, Immediate(value)); |
| 4796 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4797 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4798 | } else { |
| 4799 | DCHECK(destination.IsStackSlot()) << destination; |
| 4800 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 4801 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4802 | } else if (constant->IsLongConstant()) { |
| 4803 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4804 | int32_t low_value = Low32Bits(value); |
| 4805 | int32_t high_value = High32Bits(value); |
| 4806 | Immediate low(low_value); |
| 4807 | Immediate high(high_value); |
| 4808 | if (destination.IsDoubleStackSlot()) { |
| 4809 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4810 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4811 | } else { |
| 4812 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 4813 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 4814 | } |
| 4815 | } else { |
| 4816 | DCHECK(constant->IsDoubleConstant()); |
| 4817 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4818 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4819 | int32_t low_value = Low32Bits(value); |
| 4820 | int32_t high_value = High32Bits(value); |
| 4821 | Immediate low(low_value); |
| 4822 | Immediate high(high_value); |
| 4823 | if (destination.IsFpuRegister()) { |
| 4824 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4825 | if (value == 0) { |
| 4826 | // Easy handling of 0.0. |
| 4827 | __ xorpd(dest, dest); |
| 4828 | } else { |
| 4829 | __ pushl(high); |
| 4830 | __ pushl(low); |
| 4831 | __ movsd(dest, Address(ESP, 0)); |
| 4832 | __ addl(ESP, Immediate(8)); |
| 4833 | } |
| 4834 | } else { |
| 4835 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4836 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4837 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4838 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4839 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4840 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4841 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4842 | } |
| 4843 | } |
| 4844 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4845 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4846 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4847 | ScratchRegisterScope ensure_scratch( |
| 4848 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4849 | |
| 4850 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4851 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4852 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4853 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4854 | } |
| 4855 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4856 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4857 | ScratchRegisterScope ensure_scratch( |
| 4858 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4859 | |
| 4860 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4861 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4862 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4863 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4864 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4865 | } |
| 4866 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4867 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4868 | ScratchRegisterScope ensure_scratch1( |
| 4869 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4870 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4871 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4872 | ScratchRegisterScope ensure_scratch2( |
| 4873 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4874 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4875 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4876 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4877 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4878 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4879 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4880 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4881 | } |
| 4882 | |
| 4883 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 4884 | MoveOperands* move = moves_.Get(index); |
| 4885 | Location source = move->GetSource(); |
| 4886 | Location destination = move->GetDestination(); |
| 4887 | |
| 4888 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 4889 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 4890 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4891 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4892 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4893 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4894 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4895 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4896 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4897 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4898 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4899 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4900 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4901 | // Use XOR Swap algorithm to avoid a temporary. |
| 4902 | DCHECK_NE(source.reg(), destination.reg()); |
| 4903 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4904 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4905 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4906 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4907 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4908 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4909 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4910 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4911 | // Take advantage of the 16 bytes in the XMM register. |
| 4912 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4913 | Address stack(ESP, destination.GetStackIndex()); |
| 4914 | // Load the double into the high doubleword. |
| 4915 | __ movhpd(reg, stack); |
| 4916 | |
| 4917 | // Store the low double into the destination. |
| 4918 | __ movsd(stack, reg); |
| 4919 | |
| 4920 | // Move the high double to the low double. |
| 4921 | __ psrldq(reg, Immediate(8)); |
| 4922 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4923 | // Take advantage of the 16 bytes in the XMM register. |
| 4924 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4925 | Address stack(ESP, source.GetStackIndex()); |
| 4926 | // Load the double into the high doubleword. |
| 4927 | __ movhpd(reg, stack); |
| 4928 | |
| 4929 | // Store the low double into the destination. |
| 4930 | __ movsd(stack, reg); |
| 4931 | |
| 4932 | // Move the high double to the low double. |
| 4933 | __ psrldq(reg, Immediate(8)); |
| 4934 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4935 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4936 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4937 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4938 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4939 | } |
| 4940 | } |
| 4941 | |
| 4942 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4943 | __ pushl(static_cast<Register>(reg)); |
| 4944 | } |
| 4945 | |
| 4946 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4947 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4948 | } |
| 4949 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4950 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4951 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4952 | ? LocationSummary::kCallOnSlowPath |
| 4953 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4954 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4955 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4956 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4957 | locations->SetOut(Location::RequiresRegister()); |
| 4958 | } |
| 4959 | |
| 4960 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4961 | LocationSummary* locations = cls->GetLocations(); |
| 4962 | Register out = locations->Out().AsRegister<Register>(); |
| 4963 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4964 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4965 | DCHECK(!cls->CanCallRuntime()); |
| 4966 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4967 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4968 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4969 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4970 | __ movl(out, Address( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4971 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4972 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4973 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4974 | |
| 4975 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4976 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4977 | codegen_->AddSlowPath(slow_path); |
| 4978 | __ testl(out, out); |
| 4979 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4980 | if (cls->MustGenerateClinitCheck()) { |
| 4981 | GenerateClassInitializationCheck(slow_path, out); |
| 4982 | } else { |
| 4983 | __ Bind(slow_path->GetExitLabel()); |
| 4984 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4985 | } |
| 4986 | } |
| 4987 | |
| 4988 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 4989 | LocationSummary* locations = |
| 4990 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4991 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4992 | if (check->HasUses()) { |
| 4993 | locations->SetOut(Location::SameAsFirstInput()); |
| 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4998 | // We assume the class to not be null. |
| 4999 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5000 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5001 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5002 | GenerateClassInitializationCheck(slow_path, |
| 5003 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5004 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5005 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5006 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 5007 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5008 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5009 | Immediate(mirror::Class::kStatusInitialized)); |
| 5010 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5011 | __ Bind(slow_path->GetExitLabel()); |
| 5012 | // No need for memory fence, thanks to the X86 memory model. |
| 5013 | } |
| 5014 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5015 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 5016 | LocationSummary* locations = |
| 5017 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5018 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5019 | locations->SetOut(Location::RequiresRegister()); |
| 5020 | } |
| 5021 | |
| 5022 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 5023 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5024 | codegen_->AddSlowPath(slow_path); |
| 5025 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5026 | LocationSummary* locations = load->GetLocations(); |
| 5027 | Register out = locations->Out().AsRegister<Register>(); |
| 5028 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 5029 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5030 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5031 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5032 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5033 | __ testl(out, out); |
| 5034 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5035 | __ Bind(slow_path->GetExitLabel()); |
| 5036 | } |
| 5037 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5038 | static Address GetExceptionTlsAddress() { |
| 5039 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5040 | } |
| 5041 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5042 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5043 | LocationSummary* locations = |
| 5044 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5045 | locations->SetOut(Location::RequiresRegister()); |
| 5046 | } |
| 5047 | |
| 5048 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5049 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5050 | } |
| 5051 | |
| 5052 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5053 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5054 | } |
| 5055 | |
| 5056 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5057 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5061 | LocationSummary* locations = |
| 5062 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5063 | InvokeRuntimeCallingConvention calling_convention; |
| 5064 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5065 | } |
| 5066 | |
| 5067 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5068 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5069 | instruction, |
| 5070 | instruction->GetDexPc(), |
| 5071 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5074 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5075 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 5076 | ? LocationSummary::kNoCall |
| 5077 | : LocationSummary::kCallOnSlowPath; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5078 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5080 | locations->SetInAt(1, Location::Any()); |
| 5081 | // Note that TypeCheckSlowPathX86 uses this register too. |
| 5082 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5083 | } |
| 5084 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5085 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5086 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5087 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5088 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5089 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5090 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 5091 | NearLabel done, zero; |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5092 | SlowPathCodeX86* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5093 | |
| 5094 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5095 | // Avoid null check if we know obj is not null. |
| 5096 | if (instruction->MustDoNullCheck()) { |
| 5097 | __ testl(obj, obj); |
| 5098 | __ j(kEqual, &zero); |
| 5099 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5100 | // Compare the class of `obj` with `cls`. |
| 5101 | __ movl(out, Address(obj, class_offset)); |
| 5102 | __ MaybeUnpoisonHeapReference(out); |
| 5103 | if (cls.IsRegister()) { |
| 5104 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5105 | } else { |
| 5106 | DCHECK(cls.IsStackSlot()) << cls; |
| 5107 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5108 | } |
| 5109 | |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5110 | if (instruction->IsClassFinal()) { |
| 5111 | // Classes must be equal for the instanceof to succeed. |
| 5112 | __ j(kNotEqual, &zero); |
| 5113 | __ movl(out, Immediate(1)); |
| 5114 | __ jmp(&done); |
| 5115 | } else { |
| 5116 | // If the classes are not equal, we go into a slow path. |
| 5117 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5118 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction); |
| 5119 | codegen_->AddSlowPath(slow_path); |
| 5120 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5121 | __ movl(out, Immediate(1)); |
| 5122 | __ jmp(&done); |
| 5123 | } |
| 5124 | |
| 5125 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5126 | __ Bind(&zero); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5127 | __ movl(out, Immediate(0)); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5128 | } |
| 5129 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5130 | if (slow_path != nullptr) { |
| 5131 | __ Bind(slow_path->GetExitLabel()); |
| 5132 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5133 | __ Bind(&done); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5134 | } |
| 5135 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5136 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| 5137 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5138 | instruction, LocationSummary::kCallOnSlowPath); |
| 5139 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5140 | locations->SetInAt(1, Location::Any()); |
| 5141 | // Note that TypeCheckSlowPathX86 uses this register too. |
| 5142 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 5146 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5147 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5148 | Location cls = locations->InAt(1); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5149 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 5150 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5151 | SlowPathCodeX86* slow_path = |
| 5152 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction); |
| 5153 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 5154 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5155 | // Avoid null check if we know obj is not null. |
| 5156 | if (instruction->MustDoNullCheck()) { |
| 5157 | __ testl(obj, obj); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5158 | __ j(kEqual, slow_path->GetExitLabel()); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5159 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5160 | // Compare the class of `obj` with `cls`. |
| 5161 | __ movl(temp, Address(obj, class_offset)); |
| 5162 | __ MaybeUnpoisonHeapReference(temp); |
| 5163 | if (cls.IsRegister()) { |
| 5164 | __ cmpl(temp, cls.AsRegister<Register>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5165 | } else { |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5166 | DCHECK(cls.IsStackSlot()) << cls; |
| 5167 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5168 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame^] | 5169 | // The checkcast succeeds if the classes are equal (fast path). |
| 5170 | // Otherwise, we need to go into the slow path to check the types. |
| 5171 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5172 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5175 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5176 | LocationSummary* locations = |
| 5177 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5178 | InvokeRuntimeCallingConvention calling_convention; |
| 5179 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5180 | } |
| 5181 | |
| 5182 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5183 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5184 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5185 | instruction, |
| 5186 | instruction->GetDexPc(), |
| 5187 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5188 | } |
| 5189 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5190 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5191 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5192 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5193 | |
| 5194 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5195 | LocationSummary* locations = |
| 5196 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5197 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5198 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5199 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5200 | locations->SetInAt(1, Location::Any()); |
| 5201 | locations->SetOut(Location::SameAsFirstInput()); |
| 5202 | } |
| 5203 | |
| 5204 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 5205 | HandleBitwiseOperation(instruction); |
| 5206 | } |
| 5207 | |
| 5208 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 5209 | HandleBitwiseOperation(instruction); |
| 5210 | } |
| 5211 | |
| 5212 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 5213 | HandleBitwiseOperation(instruction); |
| 5214 | } |
| 5215 | |
| 5216 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5217 | LocationSummary* locations = instruction->GetLocations(); |
| 5218 | Location first = locations->InAt(0); |
| 5219 | Location second = locations->InAt(1); |
| 5220 | DCHECK(first.Equals(locations->Out())); |
| 5221 | |
| 5222 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5223 | if (second.IsRegister()) { |
| 5224 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5225 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5226 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5227 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5228 | } else { |
| 5229 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5230 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5231 | } |
| 5232 | } else if (second.IsConstant()) { |
| 5233 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5234 | __ andl(first.AsRegister<Register>(), |
| 5235 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5236 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5237 | __ orl(first.AsRegister<Register>(), |
| 5238 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5239 | } else { |
| 5240 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5241 | __ xorl(first.AsRegister<Register>(), |
| 5242 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5243 | } |
| 5244 | } else { |
| 5245 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5246 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5247 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5248 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5249 | } else { |
| 5250 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5251 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5252 | } |
| 5253 | } |
| 5254 | } else { |
| 5255 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5256 | if (second.IsRegisterPair()) { |
| 5257 | if (instruction->IsAnd()) { |
| 5258 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5259 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5260 | } else if (instruction->IsOr()) { |
| 5261 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5262 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5263 | } else { |
| 5264 | DCHECK(instruction->IsXor()); |
| 5265 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5266 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5267 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5268 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5269 | if (instruction->IsAnd()) { |
| 5270 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5271 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 5272 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5273 | } else if (instruction->IsOr()) { |
| 5274 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5275 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 5276 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5277 | } else { |
| 5278 | DCHECK(instruction->IsXor()); |
| 5279 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5280 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 5281 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5282 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5283 | } else { |
| 5284 | DCHECK(second.IsConstant()) << second; |
| 5285 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5286 | int32_t low_value = Low32Bits(value); |
| 5287 | int32_t high_value = High32Bits(value); |
| 5288 | Immediate low(low_value); |
| 5289 | Immediate high(high_value); |
| 5290 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5291 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5292 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5293 | if (low_value == 0) { |
| 5294 | __ xorl(first_low, first_low); |
| 5295 | } else if (low_value != -1) { |
| 5296 | __ andl(first_low, low); |
| 5297 | } |
| 5298 | if (high_value == 0) { |
| 5299 | __ xorl(first_high, first_high); |
| 5300 | } else if (high_value != -1) { |
| 5301 | __ andl(first_high, high); |
| 5302 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5303 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5304 | if (low_value != 0) { |
| 5305 | __ orl(first_low, low); |
| 5306 | } |
| 5307 | if (high_value != 0) { |
| 5308 | __ orl(first_high, high); |
| 5309 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5310 | } else { |
| 5311 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5312 | if (low_value != 0) { |
| 5313 | __ xorl(first_low, low); |
| 5314 | } |
| 5315 | if (high_value != 0) { |
| 5316 | __ xorl(first_high, high); |
| 5317 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5318 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5319 | } |
| 5320 | } |
| 5321 | } |
| 5322 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5323 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 5324 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5325 | UNUSED(instruction); |
| 5326 | LOG(FATAL) << "Unreachable"; |
| 5327 | } |
| 5328 | |
| 5329 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 5330 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5331 | UNUSED(instruction); |
| 5332 | LOG(FATAL) << "Unreachable"; |
| 5333 | } |
| 5334 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5335 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 5336 | DCHECK(codegen_->IsBaseline()); |
| 5337 | LocationSummary* locations = |
| 5338 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5339 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5340 | } |
| 5341 | |
| 5342 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5343 | DCHECK(codegen_->IsBaseline()); |
| 5344 | // Will be generated at use site. |
| 5345 | } |
| 5346 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5347 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 5348 | HX86ComputeBaseMethodAddress* insn) { |
| 5349 | LocationSummary* locations = |
| 5350 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5351 | locations->SetOut(Location::RequiresRegister()); |
| 5352 | } |
| 5353 | |
| 5354 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 5355 | HX86ComputeBaseMethodAddress* insn) { |
| 5356 | LocationSummary* locations = insn->GetLocations(); |
| 5357 | Register reg = locations->Out().AsRegister<Register>(); |
| 5358 | |
| 5359 | // Generate call to next instruction. |
| 5360 | Label next_instruction; |
| 5361 | __ call(&next_instruction); |
| 5362 | __ Bind(&next_instruction); |
| 5363 | |
| 5364 | // Remember this offset for later use with constant area. |
| 5365 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 5366 | |
| 5367 | // Grab the return address off the stack. |
| 5368 | __ popl(reg); |
| 5369 | } |
| 5370 | |
| 5371 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 5372 | HX86LoadFromConstantTable* insn) { |
| 5373 | LocationSummary* locations = |
| 5374 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5375 | |
| 5376 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5377 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 5378 | |
| 5379 | // If we don't need to be materialized, we only need the inputs to be set. |
| 5380 | if (!insn->NeedsMaterialization()) { |
| 5381 | return; |
| 5382 | } |
| 5383 | |
| 5384 | switch (insn->GetType()) { |
| 5385 | case Primitive::kPrimFloat: |
| 5386 | case Primitive::kPrimDouble: |
| 5387 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5388 | break; |
| 5389 | |
| 5390 | case Primitive::kPrimInt: |
| 5391 | locations->SetOut(Location::RequiresRegister()); |
| 5392 | break; |
| 5393 | |
| 5394 | default: |
| 5395 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5396 | } |
| 5397 | } |
| 5398 | |
| 5399 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 5400 | if (!insn->NeedsMaterialization()) { |
| 5401 | return; |
| 5402 | } |
| 5403 | |
| 5404 | LocationSummary* locations = insn->GetLocations(); |
| 5405 | Location out = locations->Out(); |
| 5406 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 5407 | HConstant *value = insn->GetConstant(); |
| 5408 | |
| 5409 | switch (insn->GetType()) { |
| 5410 | case Primitive::kPrimFloat: |
| 5411 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 5412 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 5413 | break; |
| 5414 | |
| 5415 | case Primitive::kPrimDouble: |
| 5416 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 5417 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 5418 | break; |
| 5419 | |
| 5420 | case Primitive::kPrimInt: |
| 5421 | __ movl(out.AsRegister<Register>(), |
| 5422 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 5423 | break; |
| 5424 | |
| 5425 | default: |
| 5426 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5427 | } |
| 5428 | } |
| 5429 | |
| 5430 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 5431 | // Generate the constant area if needed. |
| 5432 | X86Assembler* assembler = GetAssembler(); |
| 5433 | if (!assembler->IsConstantAreaEmpty()) { |
| 5434 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 5435 | // byte values. |
| 5436 | assembler->Align(4, 0); |
| 5437 | constant_area_start_ = assembler->CodeSize(); |
| 5438 | assembler->AddConstantArea(); |
| 5439 | } |
| 5440 | |
| 5441 | // And finish up. |
| 5442 | CodeGenerator::Finalize(allocator); |
| 5443 | } |
| 5444 | |
| 5445 | /** |
| 5446 | * Class to handle late fixup of offsets into constant area. |
| 5447 | */ |
| 5448 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 5449 | public: |
| 5450 | RIPFixup(const CodeGeneratorX86& codegen, int offset) |
| 5451 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 5452 | |
| 5453 | private: |
| 5454 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5455 | // Patch the correct offset for the instruction. The place to patch is the |
| 5456 | // last 4 bytes of the instruction. |
| 5457 | // The value to patch is the distance from the offset in the constant area |
| 5458 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| 5459 | int32_t constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 5460 | int32_t relative_position = constant_offset - codegen_.GetMethodAddressOffset();; |
| 5461 | |
| 5462 | // Patch in the right value. |
| 5463 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5464 | } |
| 5465 | |
| 5466 | const CodeGeneratorX86& codegen_; |
| 5467 | |
| 5468 | // Location in constant area that the fixup refers to. |
| 5469 | int offset_into_constant_area_; |
| 5470 | }; |
| 5471 | |
| 5472 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 5473 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5474 | return Address(reg, kDummy32BitOffset, fixup); |
| 5475 | } |
| 5476 | |
| 5477 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 5478 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5479 | return Address(reg, kDummy32BitOffset, fixup); |
| 5480 | } |
| 5481 | |
| 5482 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 5483 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5484 | return Address(reg, kDummy32BitOffset, fixup); |
| 5485 | } |
| 5486 | |
| 5487 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 5488 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5489 | return Address(reg, kDummy32BitOffset, fixup); |
| 5490 | } |
| 5491 | |
| 5492 | /** |
| 5493 | * Finds instructions that need the constant area base as an input. |
| 5494 | */ |
| 5495 | class ConstantHandlerVisitor : public HGraphVisitor { |
| 5496 | public: |
| 5497 | explicit ConstantHandlerVisitor(HGraph* graph) : HGraphVisitor(graph), base_(nullptr) {} |
| 5498 | |
| 5499 | private: |
| 5500 | void VisitAdd(HAdd* add) OVERRIDE { |
| 5501 | BinaryFP(add); |
| 5502 | } |
| 5503 | |
| 5504 | void VisitSub(HSub* sub) OVERRIDE { |
| 5505 | BinaryFP(sub); |
| 5506 | } |
| 5507 | |
| 5508 | void VisitMul(HMul* mul) OVERRIDE { |
| 5509 | BinaryFP(mul); |
| 5510 | } |
| 5511 | |
| 5512 | void VisitDiv(HDiv* div) OVERRIDE { |
| 5513 | BinaryFP(div); |
| 5514 | } |
| 5515 | |
| 5516 | void VisitReturn(HReturn* ret) OVERRIDE { |
| 5517 | HConstant* value = ret->InputAt(0)->AsConstant(); |
| 5518 | if ((value != nullptr && Primitive::IsFloatingPointType(value->GetType()))) { |
| 5519 | ReplaceInput(ret, value, 0, true); |
| 5520 | } |
| 5521 | } |
| 5522 | |
| 5523 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE { |
| 5524 | HandleInvoke(invoke); |
| 5525 | } |
| 5526 | |
| 5527 | void VisitInvokeVirtual(HInvokeVirtual* invoke) OVERRIDE { |
| 5528 | HandleInvoke(invoke); |
| 5529 | } |
| 5530 | |
| 5531 | void VisitInvokeInterface(HInvokeInterface* invoke) OVERRIDE { |
| 5532 | HandleInvoke(invoke); |
| 5533 | } |
| 5534 | |
| 5535 | void BinaryFP(HBinaryOperation* bin) { |
| 5536 | HConstant* rhs = bin->InputAt(1)->AsConstant(); |
| 5537 | if (rhs != nullptr && Primitive::IsFloatingPointType(bin->GetResultType())) { |
| 5538 | ReplaceInput(bin, rhs, 1, false); |
| 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | void InitializeConstantAreaPointer(HInstruction* user) { |
| 5543 | // Ensure we only initialize the pointer once. |
| 5544 | if (base_ != nullptr) { |
| 5545 | return; |
| 5546 | } |
| 5547 | |
| 5548 | HGraph* graph = GetGraph(); |
| 5549 | HBasicBlock* entry = graph->GetEntryBlock(); |
| 5550 | base_ = new (graph->GetArena()) HX86ComputeBaseMethodAddress(); |
| 5551 | HInstruction* insert_pos = (user->GetBlock() == entry) ? user : entry->GetLastInstruction(); |
| 5552 | entry->InsertInstructionBefore(base_, insert_pos); |
| 5553 | DCHECK(base_ != nullptr); |
| 5554 | } |
| 5555 | |
| 5556 | void ReplaceInput(HInstruction* insn, HConstant* value, int input_index, bool materialize) { |
| 5557 | InitializeConstantAreaPointer(insn); |
| 5558 | HGraph* graph = GetGraph(); |
| 5559 | HBasicBlock* block = insn->GetBlock(); |
| 5560 | HX86LoadFromConstantTable* load_constant = |
| 5561 | new (graph->GetArena()) HX86LoadFromConstantTable(base_, value, materialize); |
| 5562 | block->InsertInstructionBefore(load_constant, insn); |
| 5563 | insn->ReplaceInput(load_constant, input_index); |
| 5564 | } |
| 5565 | |
| 5566 | void HandleInvoke(HInvoke* invoke) { |
| 5567 | // Ensure that we can load FP arguments from the constant area. |
| 5568 | for (size_t i = 0, e = invoke->InputCount(); i < e; i++) { |
| 5569 | HConstant* input = invoke->InputAt(i)->AsConstant(); |
| 5570 | if (input != nullptr && Primitive::IsFloatingPointType(input->GetType())) { |
| 5571 | ReplaceInput(invoke, input, i, true); |
| 5572 | } |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | // The generated HX86ComputeBaseMethodAddress in the entry block needed as an |
| 5577 | // input to the HX86LoadFromConstantTable instructions. |
| 5578 | HX86ComputeBaseMethodAddress* base_; |
| 5579 | }; |
| 5580 | |
| 5581 | void ConstantAreaFixups::Run() { |
| 5582 | ConstantHandlerVisitor visitor(graph_); |
| 5583 | visitor.VisitInsertionOrder(); |
| 5584 | } |
| 5585 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5586 | #undef __ |
| 5587 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5588 | } // namespace x86 |
| 5589 | } // namespace art |