Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace x86 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 44 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 45 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 46 | static constexpr int kC2ConditionMask = 0x400; |
| 47 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 48 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 49 | |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 50 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 51 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 52 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 54 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 56 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 58 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 59 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 61 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 62 | // Live registers will be restored in the catch block if caught. |
| 63 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 64 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 65 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 66 | instruction_, |
| 67 | instruction_->GetDexPc(), |
| 68 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 69 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 72 | bool IsFatal() const OVERRIDE { return true; } |
| 73 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 74 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 75 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 78 | }; |
| 79 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 80 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 81 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 82 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 83 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 84 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 85 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 87 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 88 | // Live registers will be restored in the catch block if caught. |
| 89 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 90 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 91 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 92 | instruction_, |
| 93 | instruction_->GetDexPc(), |
| 94 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 95 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 98 | bool IsFatal() const OVERRIDE { return true; } |
| 99 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 100 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 101 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 104 | }; |
| 105 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 106 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 108 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 109 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 111 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negl(reg_); |
| 115 | } else { |
| 116 | __ movl(reg_, Immediate(0)); |
| 117 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | __ jmp(GetExitLabel()); |
| 119 | } |
| 120 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 121 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 122 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | private: |
| 124 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | bool is_div_; |
| 126 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 129 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 130 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 131 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 132 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 133 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 134 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 135 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 136 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 137 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 138 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 139 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 140 | // Live registers will be restored in the catch block if caught. |
| 141 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 142 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 143 | |
| 144 | // Are we using an array length from memory? |
| 145 | HInstruction* array_length = instruction_->InputAt(1); |
| 146 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 147 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 148 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 149 | // Load the array length into our temporary. |
| 150 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 151 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 152 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 153 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 154 | // Check for conflicts with index. |
| 155 | if (length_loc.Equals(locations->InAt(0))) { |
| 156 | // We know we aren't using parameter 2. |
| 157 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 158 | } |
| 159 | __ movl(length_loc.AsRegister<Register>(), array_len); |
| 160 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 161 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 162 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 163 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 164 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 165 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 166 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 167 | Primitive::kPrimInt); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 168 | uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 169 | ? QUICK_ENTRY_POINT(pThrowStringBounds) |
| 170 | : QUICK_ENTRY_POINT(pThrowArrayBounds); |
| 171 | x86_codegen->InvokeRuntime(entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 172 | instruction_, |
| 173 | instruction_->GetDexPc(), |
| 174 | this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 175 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 176 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 179 | bool IsFatal() const OVERRIDE { return true; } |
| 180 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 181 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 182 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 185 | }; |
| 186 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 187 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 188 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 189 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 190 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 191 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 192 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 193 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 194 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 195 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 196 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 197 | instruction_, |
| 198 | instruction_->GetDexPc(), |
| 199 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 200 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 201 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 202 | if (successor_ == nullptr) { |
| 203 | __ jmp(GetReturnLabel()); |
| 204 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 205 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 206 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 209 | Label* GetReturnLabel() { |
| 210 | DCHECK(successor_ == nullptr); |
| 211 | return &return_label_; |
| 212 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 213 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 214 | HBasicBlock* GetSuccessor() const { |
| 215 | return successor_; |
| 216 | } |
| 217 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 218 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 219 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 220 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 221 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 222 | Label return_label_; |
| 223 | |
| 224 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 225 | }; |
| 226 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 227 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 228 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 229 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 230 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 231 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 232 | LocationSummary* locations = instruction_->GetLocations(); |
| 233 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 234 | |
| 235 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 236 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 237 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 238 | |
| 239 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 240 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 241 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 242 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 243 | instruction_, |
| 244 | instruction_->GetDexPc(), |
| 245 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 246 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 247 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 248 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 249 | |
| 250 | __ jmp(GetExitLabel()); |
| 251 | } |
| 252 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 253 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 254 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 255 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 256 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 257 | }; |
| 258 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 259 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 260 | public: |
| 261 | LoadClassSlowPathX86(HLoadClass* cls, |
| 262 | HInstruction* at, |
| 263 | uint32_t dex_pc, |
| 264 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 265 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 267 | } |
| 268 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 269 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | LocationSummary* locations = at_->GetLocations(); |
| 271 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 272 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 273 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | |
| 275 | InvokeRuntimeCallingConvention calling_convention; |
| 276 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 277 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 278 | : QUICK_ENTRY_POINT(pInitializeType), |
| 279 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 280 | if (do_clinit_) { |
| 281 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 282 | } else { |
| 283 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 284 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 285 | |
| 286 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 287 | Location out = locations->Out(); |
| 288 | if (out.IsValid()) { |
| 289 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 290 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 291 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 292 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 293 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 294 | __ jmp(GetExitLabel()); |
| 295 | } |
| 296 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 297 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 298 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 299 | private: |
| 300 | // The class this slow path will load. |
| 301 | HLoadClass* const cls_; |
| 302 | |
| 303 | // The instruction where this slow path is happening. |
| 304 | // (Might be the load class or an initialization check). |
| 305 | HInstruction* const at_; |
| 306 | |
| 307 | // The dex PC of `at_`. |
| 308 | const uint32_t dex_pc_; |
| 309 | |
| 310 | // Whether to initialize the class. |
| 311 | const bool do_clinit_; |
| 312 | |
| 313 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 314 | }; |
| 315 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 316 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 318 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 319 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 321 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 322 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 323 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 324 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 325 | DCHECK(instruction_->IsCheckCast() |
| 326 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | |
| 328 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 329 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 330 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 331 | if (!is_fatal_) { |
| 332 | SaveLiveRegisters(codegen, locations); |
| 333 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | |
| 335 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 336 | // move resolver. |
| 337 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 338 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 339 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 340 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 341 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 342 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 343 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 344 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 345 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 346 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 347 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 348 | instruction_, |
| 349 | instruction_->GetDexPc(), |
| 350 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 351 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame^] | 352 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 353 | } else { |
| 354 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 355 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 356 | instruction_, |
| 357 | instruction_->GetDexPc(), |
| 358 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 359 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 362 | if (!is_fatal_) { |
| 363 | if (instruction_->IsInstanceOf()) { |
| 364 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 365 | } |
| 366 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 367 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 368 | __ jmp(GetExitLabel()); |
| 369 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 372 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 373 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 374 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 375 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 376 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 377 | |
| 378 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 379 | }; |
| 380 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 381 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 382 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 383 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 384 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 385 | |
| 386 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 387 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 388 | __ Bind(GetEntryLabel()); |
| 389 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 390 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 391 | instruction_, |
| 392 | instruction_->GetDexPc(), |
| 393 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 394 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 397 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 398 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 400 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 401 | }; |
| 402 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 403 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 404 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 405 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 406 | |
| 407 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 408 | LocationSummary* locations = instruction_->GetLocations(); |
| 409 | __ Bind(GetEntryLabel()); |
| 410 | SaveLiveRegisters(codegen, locations); |
| 411 | |
| 412 | InvokeRuntimeCallingConvention calling_convention; |
| 413 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 414 | parallel_move.AddMove( |
| 415 | locations->InAt(0), |
| 416 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 417 | Primitive::kPrimNot, |
| 418 | nullptr); |
| 419 | parallel_move.AddMove( |
| 420 | locations->InAt(1), |
| 421 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 422 | Primitive::kPrimInt, |
| 423 | nullptr); |
| 424 | parallel_move.AddMove( |
| 425 | locations->InAt(2), |
| 426 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 427 | Primitive::kPrimNot, |
| 428 | nullptr); |
| 429 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 430 | |
| 431 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 432 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 433 | instruction_, |
| 434 | instruction_->GetDexPc(), |
| 435 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 436 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 437 | RestoreLiveRegisters(codegen, locations); |
| 438 | __ jmp(GetExitLabel()); |
| 439 | } |
| 440 | |
| 441 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 442 | |
| 443 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 444 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 445 | }; |
| 446 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 447 | // Slow path marking an object during a read barrier. |
| 448 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 449 | public: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 450 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location obj) |
| 451 | : SlowPathCode(instruction), obj_(obj) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 452 | DCHECK(kEmitCompilerReadBarrier); |
| 453 | } |
| 454 | |
| 455 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 456 | |
| 457 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 458 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 459 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 460 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 461 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 462 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 463 | instruction_->IsStaticFieldGet() || |
| 464 | instruction_->IsArrayGet() || |
| 465 | instruction_->IsLoadClass() || |
| 466 | instruction_->IsLoadString() || |
| 467 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 468 | instruction_->IsCheckCast() || |
| 469 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
| 470 | instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 471 | << "Unexpected instruction in read barrier marking slow path: " |
| 472 | << instruction_->DebugName(); |
| 473 | |
| 474 | __ Bind(GetEntryLabel()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 475 | // Save live registers before the runtime call, and in particular |
| 476 | // EAX (if it is live), as it is clobbered by functions |
| 477 | // art_quick_read_barrier_mark_regX. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 478 | SaveLiveRegisters(codegen, locations); |
| 479 | |
| 480 | InvokeRuntimeCallingConvention calling_convention; |
| 481 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 482 | DCHECK_NE(reg, ESP); |
| 483 | DCHECK(0 <= reg && reg < kNumberOfCpuRegisters) << reg; |
| 484 | // "Compact" slow path, saving two moves. |
| 485 | // |
| 486 | // Instead of using the standard runtime calling convention (input |
| 487 | // and output in EAX): |
| 488 | // |
| 489 | // EAX <- obj |
| 490 | // EAX <- ReadBarrierMark(EAX) |
| 491 | // obj <- EAX |
| 492 | // |
| 493 | // we just use rX (the register holding `obj`) as input and output |
| 494 | // of a dedicated entrypoint: |
| 495 | // |
| 496 | // rX <- ReadBarrierMarkRegX(rX) |
| 497 | // |
| 498 | int32_t entry_point_offset = |
| 499 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86WordSize>(reg); |
| 500 | // TODO: Do not emit a stack map for this runtime call. |
| 501 | x86_codegen->InvokeRuntime(entry_point_offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 502 | instruction_, |
| 503 | instruction_->GetDexPc(), |
| 504 | this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 505 | |
| 506 | RestoreLiveRegisters(codegen, locations); |
| 507 | __ jmp(GetExitLabel()); |
| 508 | } |
| 509 | |
| 510 | private: |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 511 | const Location obj_; |
| 512 | |
| 513 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 514 | }; |
| 515 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 516 | // Slow path generating a read barrier for a heap reference. |
| 517 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 518 | public: |
| 519 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 520 | Location out, |
| 521 | Location ref, |
| 522 | Location obj, |
| 523 | uint32_t offset, |
| 524 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 525 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 526 | out_(out), |
| 527 | ref_(ref), |
| 528 | obj_(obj), |
| 529 | offset_(offset), |
| 530 | index_(index) { |
| 531 | DCHECK(kEmitCompilerReadBarrier); |
| 532 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 533 | // has been overwritten by (or after) the heap object reference load |
| 534 | // to be instrumented, e.g.: |
| 535 | // |
| 536 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 537 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 538 | // |
| 539 | // In that case, we have lost the information about the original |
| 540 | // object, and the emitted read barrier cannot work properly. |
| 541 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 542 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 543 | } |
| 544 | |
| 545 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 546 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 547 | LocationSummary* locations = instruction_->GetLocations(); |
| 548 | Register reg_out = out_.AsRegister<Register>(); |
| 549 | DCHECK(locations->CanCall()); |
| 550 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 551 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 552 | instruction_->IsStaticFieldGet() || |
| 553 | instruction_->IsArrayGet() || |
| 554 | instruction_->IsInstanceOf() || |
| 555 | instruction_->IsCheckCast() || |
| 556 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 557 | instruction_->GetLocations()->Intrinsified())) |
| 558 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 559 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 560 | |
| 561 | __ Bind(GetEntryLabel()); |
| 562 | SaveLiveRegisters(codegen, locations); |
| 563 | |
| 564 | // We may have to change the index's value, but as `index_` is a |
| 565 | // constant member (like other "inputs" of this slow path), |
| 566 | // introduce a copy of it, `index`. |
| 567 | Location index = index_; |
| 568 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 569 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 570 | if (instruction_->IsArrayGet()) { |
| 571 | // Compute the actual memory offset and store it in `index`. |
| 572 | Register index_reg = index_.AsRegister<Register>(); |
| 573 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 574 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 575 | // We are about to change the value of `index_reg` (see the |
| 576 | // calls to art::x86::X86Assembler::shll and |
| 577 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 578 | // not been saved by the previous call to |
| 579 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 580 | // callee-save register -- |
| 581 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 582 | // callee-save registers, as it has been designed with the |
| 583 | // assumption that callee-save registers are supposed to be |
| 584 | // handled by the called function. So, as a callee-save |
| 585 | // register, `index_reg` _would_ eventually be saved onto |
| 586 | // the stack, but it would be too late: we would have |
| 587 | // changed its value earlier. Therefore, we manually save |
| 588 | // it here into another freely available register, |
| 589 | // `free_reg`, chosen of course among the caller-save |
| 590 | // registers (as a callee-save `free_reg` register would |
| 591 | // exhibit the same problem). |
| 592 | // |
| 593 | // Note we could have requested a temporary register from |
| 594 | // the register allocator instead; but we prefer not to, as |
| 595 | // this is a slow path, and we know we can find a |
| 596 | // caller-save register that is available. |
| 597 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 598 | __ movl(free_reg, index_reg); |
| 599 | index_reg = free_reg; |
| 600 | index = Location::RegisterLocation(index_reg); |
| 601 | } else { |
| 602 | // The initial register stored in `index_` has already been |
| 603 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 604 | // (as it is not a callee-save register), so we can freely |
| 605 | // use it. |
| 606 | } |
| 607 | // Shifting the index value contained in `index_reg` by the scale |
| 608 | // factor (2) cannot overflow in practice, as the runtime is |
| 609 | // unable to allocate object arrays with a size larger than |
| 610 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 611 | __ shll(index_reg, Immediate(TIMES_4)); |
| 612 | static_assert( |
| 613 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 614 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 615 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 616 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 617 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 618 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 619 | // (as in the case of ArrayGet), as it is actually an offset |
| 620 | // to an object field within an object. |
| 621 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 622 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 623 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 624 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 625 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 626 | DCHECK_EQ(offset_, 0U); |
| 627 | DCHECK(index_.IsRegisterPair()); |
| 628 | // UnsafeGet's offset location is a register pair, the low |
| 629 | // part contains the correct offset. |
| 630 | index = index_.ToLow(); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | // We're moving two or three locations to locations that could |
| 635 | // overlap, so we need a parallel move resolver. |
| 636 | InvokeRuntimeCallingConvention calling_convention; |
| 637 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 638 | parallel_move.AddMove(ref_, |
| 639 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 640 | Primitive::kPrimNot, |
| 641 | nullptr); |
| 642 | parallel_move.AddMove(obj_, |
| 643 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 644 | Primitive::kPrimNot, |
| 645 | nullptr); |
| 646 | if (index.IsValid()) { |
| 647 | parallel_move.AddMove(index, |
| 648 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 649 | Primitive::kPrimInt, |
| 650 | nullptr); |
| 651 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 652 | } else { |
| 653 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 654 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 655 | } |
| 656 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 657 | instruction_, |
| 658 | instruction_->GetDexPc(), |
| 659 | this); |
| 660 | CheckEntrypointTypes< |
| 661 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 662 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 663 | |
| 664 | RestoreLiveRegisters(codegen, locations); |
| 665 | __ jmp(GetExitLabel()); |
| 666 | } |
| 667 | |
| 668 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 669 | |
| 670 | private: |
| 671 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 672 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 673 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 674 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 675 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 676 | return static_cast<Register>(i); |
| 677 | } |
| 678 | } |
| 679 | // We shall never fail to find a free caller-save register, as |
| 680 | // there are more than two core caller-save registers on x86 |
| 681 | // (meaning it is possible to find one which is different from |
| 682 | // `ref` and `obj`). |
| 683 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 684 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 685 | UNREACHABLE(); |
| 686 | } |
| 687 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 688 | const Location out_; |
| 689 | const Location ref_; |
| 690 | const Location obj_; |
| 691 | const uint32_t offset_; |
| 692 | // An additional location containing an index to an array. |
| 693 | // Only used for HArrayGet and the UnsafeGetObject & |
| 694 | // UnsafeGetObjectVolatile intrinsics. |
| 695 | const Location index_; |
| 696 | |
| 697 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 698 | }; |
| 699 | |
| 700 | // Slow path generating a read barrier for a GC root. |
| 701 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 702 | public: |
| 703 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 704 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 705 | DCHECK(kEmitCompilerReadBarrier); |
| 706 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 707 | |
| 708 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 709 | LocationSummary* locations = instruction_->GetLocations(); |
| 710 | Register reg_out = out_.AsRegister<Register>(); |
| 711 | DCHECK(locations->CanCall()); |
| 712 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 713 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 714 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 715 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 716 | |
| 717 | __ Bind(GetEntryLabel()); |
| 718 | SaveLiveRegisters(codegen, locations); |
| 719 | |
| 720 | InvokeRuntimeCallingConvention calling_convention; |
| 721 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 722 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 723 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 724 | instruction_, |
| 725 | instruction_->GetDexPc(), |
| 726 | this); |
| 727 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 728 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 729 | |
| 730 | RestoreLiveRegisters(codegen, locations); |
| 731 | __ jmp(GetExitLabel()); |
| 732 | } |
| 733 | |
| 734 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 735 | |
| 736 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 737 | const Location out_; |
| 738 | const Location root_; |
| 739 | |
| 740 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 741 | }; |
| 742 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 743 | #undef __ |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 744 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 745 | #define __ down_cast<X86Assembler*>(GetAssembler())-> /* NOLINT */ |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 746 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 747 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 748 | switch (cond) { |
| 749 | case kCondEQ: return kEqual; |
| 750 | case kCondNE: return kNotEqual; |
| 751 | case kCondLT: return kLess; |
| 752 | case kCondLE: return kLessEqual; |
| 753 | case kCondGT: return kGreater; |
| 754 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 755 | case kCondB: return kBelow; |
| 756 | case kCondBE: return kBelowEqual; |
| 757 | case kCondA: return kAbove; |
| 758 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 759 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 760 | LOG(FATAL) << "Unreachable"; |
| 761 | UNREACHABLE(); |
| 762 | } |
| 763 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 764 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 765 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 766 | switch (cond) { |
| 767 | case kCondEQ: return kEqual; |
| 768 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 769 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 770 | case kCondLT: return kBelow; |
| 771 | case kCondLE: return kBelowEqual; |
| 772 | case kCondGT: return kAbove; |
| 773 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 774 | // Unsigned remain unchanged. |
| 775 | case kCondB: return kBelow; |
| 776 | case kCondBE: return kBelowEqual; |
| 777 | case kCondA: return kAbove; |
| 778 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 779 | } |
| 780 | LOG(FATAL) << "Unreachable"; |
| 781 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 784 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 785 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 789 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 790 | } |
| 791 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 792 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 793 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 794 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 797 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 798 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 799 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 800 | } |
| 801 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 802 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 803 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 804 | return GetFloatingPointSpillSlotSize(); |
| 805 | } |
| 806 | |
| 807 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 808 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 809 | return GetFloatingPointSpillSlotSize(); |
| 810 | } |
| 811 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 812 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 813 | HInstruction* instruction, |
| 814 | uint32_t dex_pc, |
| 815 | SlowPathCode* slow_path) { |
| 816 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 817 | instruction, |
| 818 | dex_pc, |
| 819 | slow_path); |
| 820 | } |
| 821 | |
| 822 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 823 | HInstruction* instruction, |
| 824 | uint32_t dex_pc, |
| 825 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 826 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 827 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 828 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 829 | } |
| 830 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 831 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 832 | const X86InstructionSetFeatures& isa_features, |
| 833 | const CompilerOptions& compiler_options, |
| 834 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 835 | : CodeGenerator(graph, |
| 836 | kNumberOfCpuRegisters, |
| 837 | kNumberOfXmmRegisters, |
| 838 | kNumberOfRegisterPairs, |
| 839 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 840 | arraysize(kCoreCalleeSaves)) |
| 841 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 842 | 0, |
| 843 | compiler_options, |
| 844 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 845 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 846 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 847 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 848 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 849 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 850 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 851 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 852 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 853 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 854 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 855 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 856 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 857 | constant_area_start_(-1), |
| 858 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 859 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 860 | // Use a fake return address register to mimic Quick. |
| 861 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 862 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 863 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 864 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 865 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 866 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 867 | |
| 868 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 869 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 870 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 871 | UpdateBlockedPairRegisters(); |
| 872 | } |
| 873 | |
| 874 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 875 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 876 | X86ManagedRegister current = |
| 877 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 878 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 879 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 880 | blocked_register_pairs_[i] = true; |
| 881 | } |
| 882 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 885 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 886 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 887 | assembler_(codegen->GetAssembler()), |
| 888 | codegen_(codegen) {} |
| 889 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 890 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 891 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 892 | } |
| 893 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 894 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 895 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 896 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 897 | bool skip_overflow_check = |
| 898 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 899 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 900 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 901 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 902 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 903 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 904 | } |
| 905 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 906 | if (HasEmptyFrame()) { |
| 907 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 908 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 909 | |
| 910 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 911 | Register reg = kCoreCalleeSaves[i]; |
| 912 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 913 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 914 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 915 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 919 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 920 | __ subl(ESP, Immediate(adjust)); |
| 921 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 922 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 926 | __ cfi().RememberState(); |
| 927 | if (!HasEmptyFrame()) { |
| 928 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 929 | __ addl(ESP, Immediate(adjust)); |
| 930 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 931 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 932 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 933 | Register reg = kCoreCalleeSaves[i]; |
| 934 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 935 | __ popl(reg); |
| 936 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 937 | __ cfi().Restore(DWARFReg(reg)); |
| 938 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 939 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 940 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 941 | __ ret(); |
| 942 | __ cfi().RestoreState(); |
| 943 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 946 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 947 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 950 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 951 | switch (type) { |
| 952 | case Primitive::kPrimBoolean: |
| 953 | case Primitive::kPrimByte: |
| 954 | case Primitive::kPrimChar: |
| 955 | case Primitive::kPrimShort: |
| 956 | case Primitive::kPrimInt: |
| 957 | case Primitive::kPrimNot: |
| 958 | return Location::RegisterLocation(EAX); |
| 959 | |
| 960 | case Primitive::kPrimLong: |
| 961 | return Location::RegisterPairLocation(EAX, EDX); |
| 962 | |
| 963 | case Primitive::kPrimVoid: |
| 964 | return Location::NoLocation(); |
| 965 | |
| 966 | case Primitive::kPrimDouble: |
| 967 | case Primitive::kPrimFloat: |
| 968 | return Location::FpuRegisterLocation(XMM0); |
| 969 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 970 | |
| 971 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 975 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 976 | } |
| 977 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 978 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 979 | switch (type) { |
| 980 | case Primitive::kPrimBoolean: |
| 981 | case Primitive::kPrimByte: |
| 982 | case Primitive::kPrimChar: |
| 983 | case Primitive::kPrimShort: |
| 984 | case Primitive::kPrimInt: |
| 985 | case Primitive::kPrimNot: { |
| 986 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 987 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 988 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 989 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 990 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 991 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 992 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 993 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 994 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 995 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 996 | uint32_t index = gp_index_; |
| 997 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 998 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 999 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1000 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1001 | calling_convention.GetRegisterPairAt(index)); |
| 1002 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1003 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1004 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1009 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1010 | stack_index_++; |
| 1011 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1012 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1013 | } else { |
| 1014 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1019 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1020 | stack_index_ += 2; |
| 1021 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1022 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1023 | } else { |
| 1024 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1028 | case Primitive::kPrimVoid: |
| 1029 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1030 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1031 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1032 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1033 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1034 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1035 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1036 | if (source.Equals(destination)) { |
| 1037 | return; |
| 1038 | } |
| 1039 | if (destination.IsRegister()) { |
| 1040 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1041 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1042 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1043 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1044 | } else { |
| 1045 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1046 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1047 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1048 | } else if (destination.IsFpuRegister()) { |
| 1049 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1050 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1051 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1052 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1053 | } else { |
| 1054 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1055 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1056 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1057 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1058 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1059 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1060 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1061 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1062 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1063 | } else if (source.IsConstant()) { |
| 1064 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1065 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1066 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1067 | } else { |
| 1068 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1069 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1070 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1076 | if (source.Equals(destination)) { |
| 1077 | return; |
| 1078 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1079 | if (destination.IsRegisterPair()) { |
| 1080 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1081 | EmitParallelMoves( |
| 1082 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1083 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1084 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1085 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1086 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1087 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1088 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1089 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1090 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1091 | __ psrlq(src_reg, Immediate(32)); |
| 1092 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1093 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1094 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1095 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1096 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1097 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1098 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1099 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1100 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1101 | if (source.IsFpuRegister()) { |
| 1102 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1103 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1104 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1105 | } else if (source.IsRegisterPair()) { |
| 1106 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1107 | // Create stack space for 2 elements. |
| 1108 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1109 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1110 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1111 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1112 | // And remove the temporary stack space we allocated. |
| 1113 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1114 | } else { |
| 1115 | LOG(FATAL) << "Unimplemented"; |
| 1116 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1117 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1118 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1119 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1120 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1121 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1122 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1123 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1124 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1125 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1126 | } else if (source.IsConstant()) { |
| 1127 | HConstant* constant = source.GetConstant(); |
| 1128 | int64_t value; |
| 1129 | if (constant->IsLongConstant()) { |
| 1130 | value = constant->AsLongConstant()->GetValue(); |
| 1131 | } else { |
| 1132 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1133 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1134 | } |
| 1135 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1136 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1137 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1138 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1139 | EmitParallelMoves( |
| 1140 | Location::StackSlot(source.GetStackIndex()), |
| 1141 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1142 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1143 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1144 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1145 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1150 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1151 | DCHECK(location.IsRegister()); |
| 1152 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1153 | } |
| 1154 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1155 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1156 | HParallelMove move(GetGraph()->GetArena()); |
| 1157 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1158 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1159 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1160 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1161 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1162 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1163 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1167 | if (location.IsRegister()) { |
| 1168 | locations->AddTemp(location); |
| 1169 | } else if (location.IsRegisterPair()) { |
| 1170 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1171 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1172 | } else { |
| 1173 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1174 | } |
| 1175 | } |
| 1176 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1177 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1178 | DCHECK(!successor->IsExitBlock()); |
| 1179 | |
| 1180 | HBasicBlock* block = got->GetBlock(); |
| 1181 | HInstruction* previous = got->GetPrevious(); |
| 1182 | |
| 1183 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1184 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1185 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1186 | return; |
| 1187 | } |
| 1188 | |
| 1189 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1190 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1191 | } |
| 1192 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1193 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1197 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1198 | got->SetLocations(nullptr); |
| 1199 | } |
| 1200 | |
| 1201 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1202 | HandleGoto(got, got->GetSuccessor()); |
| 1203 | } |
| 1204 | |
| 1205 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1206 | try_boundary->SetLocations(nullptr); |
| 1207 | } |
| 1208 | |
| 1209 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1210 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1211 | if (!successor->IsExitBlock()) { |
| 1212 | HandleGoto(try_boundary, successor); |
| 1213 | } |
| 1214 | } |
| 1215 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1216 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1217 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1220 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1223 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1224 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1225 | LabelType* true_label, |
| 1226 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1227 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1228 | __ j(kUnordered, true_label); |
| 1229 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1230 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1231 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1232 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1233 | } |
| 1234 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1235 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1236 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1237 | LabelType* true_label, |
| 1238 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1239 | LocationSummary* locations = cond->GetLocations(); |
| 1240 | Location left = locations->InAt(0); |
| 1241 | Location right = locations->InAt(1); |
| 1242 | IfCondition if_cond = cond->GetCondition(); |
| 1243 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1244 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1245 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1246 | IfCondition true_high_cond = if_cond; |
| 1247 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1248 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1249 | |
| 1250 | // Set the conditions for the test, remembering that == needs to be |
| 1251 | // decided using the low words. |
| 1252 | switch (if_cond) { |
| 1253 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1254 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1255 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1256 | break; |
| 1257 | case kCondLT: |
| 1258 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1259 | break; |
| 1260 | case kCondLE: |
| 1261 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1262 | break; |
| 1263 | case kCondGT: |
| 1264 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1265 | break; |
| 1266 | case kCondGE: |
| 1267 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1268 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1269 | case kCondB: |
| 1270 | false_high_cond = kCondA; |
| 1271 | break; |
| 1272 | case kCondBE: |
| 1273 | true_high_cond = kCondB; |
| 1274 | break; |
| 1275 | case kCondA: |
| 1276 | false_high_cond = kCondB; |
| 1277 | break; |
| 1278 | case kCondAE: |
| 1279 | true_high_cond = kCondA; |
| 1280 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | if (right.IsConstant()) { |
| 1284 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1285 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1286 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1287 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1288 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1289 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1290 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1291 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1292 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1293 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1294 | __ j(X86Condition(true_high_cond), true_label); |
| 1295 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1296 | } |
| 1297 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1298 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1299 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1300 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1301 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1302 | |
| 1303 | __ cmpl(left_high, right_high); |
| 1304 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1305 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1306 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1307 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1308 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1309 | __ j(X86Condition(true_high_cond), true_label); |
| 1310 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1311 | } |
| 1312 | // Must be equal high, so compare the lows. |
| 1313 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1314 | } else { |
| 1315 | DCHECK(right.IsDoubleStackSlot()); |
| 1316 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1317 | if (if_cond == kCondNE) { |
| 1318 | __ j(X86Condition(true_high_cond), true_label); |
| 1319 | } else if (if_cond == kCondEQ) { |
| 1320 | __ j(X86Condition(false_high_cond), false_label); |
| 1321 | } else { |
| 1322 | __ j(X86Condition(true_high_cond), true_label); |
| 1323 | __ j(X86Condition(false_high_cond), false_label); |
| 1324 | } |
| 1325 | // Must be equal high, so compare the lows. |
| 1326 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1327 | } |
| 1328 | // The last comparison might be unsigned. |
| 1329 | __ j(final_condition, true_label); |
| 1330 | } |
| 1331 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1332 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1333 | Location rhs, |
| 1334 | HInstruction* insn, |
| 1335 | bool is_double) { |
| 1336 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1337 | if (is_double) { |
| 1338 | if (rhs.IsFpuRegister()) { |
| 1339 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1340 | } else if (const_area != nullptr) { |
| 1341 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1342 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1343 | codegen_->LiteralDoubleAddress( |
| 1344 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1345 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1346 | } else { |
| 1347 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1348 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1349 | } |
| 1350 | } else { |
| 1351 | if (rhs.IsFpuRegister()) { |
| 1352 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1353 | } else if (const_area != nullptr) { |
| 1354 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1355 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1356 | codegen_->LiteralFloatAddress( |
| 1357 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1358 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1359 | } else { |
| 1360 | DCHECK(rhs.IsStackSlot()); |
| 1361 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1362 | } |
| 1363 | } |
| 1364 | } |
| 1365 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1366 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1367 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1368 | LabelType* true_target_in, |
| 1369 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1370 | // Generated branching requires both targets to be explicit. If either of the |
| 1371 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1372 | LabelType fallthrough_target; |
| 1373 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1374 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1375 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1376 | LocationSummary* locations = condition->GetLocations(); |
| 1377 | Location left = locations->InAt(0); |
| 1378 | Location right = locations->InAt(1); |
| 1379 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1380 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1381 | switch (type) { |
| 1382 | case Primitive::kPrimLong: |
| 1383 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1384 | break; |
| 1385 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1386 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1387 | GenerateFPJumps(condition, true_target, false_target); |
| 1388 | break; |
| 1389 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1390 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1391 | GenerateFPJumps(condition, true_target, false_target); |
| 1392 | break; |
| 1393 | default: |
| 1394 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1395 | } |
| 1396 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1397 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1398 | __ jmp(false_target); |
| 1399 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1400 | |
| 1401 | if (fallthrough_target.IsLinked()) { |
| 1402 | __ Bind(&fallthrough_target); |
| 1403 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1404 | } |
| 1405 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1406 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1407 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1408 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1409 | // conditions if they are materialized due to the complex branching. |
| 1410 | return cond->IsCondition() && |
| 1411 | cond->GetNext() == branch && |
| 1412 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1413 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1414 | } |
| 1415 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1416 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1417 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1418 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1419 | LabelType* true_target, |
| 1420 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1421 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1422 | |
| 1423 | if (true_target == nullptr && false_target == nullptr) { |
| 1424 | // Nothing to do. The code always falls through. |
| 1425 | return; |
| 1426 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1427 | // Constant condition, statically compared against "true" (integer value 1). |
| 1428 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1429 | if (true_target != nullptr) { |
| 1430 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1431 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1432 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1433 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1434 | if (false_target != nullptr) { |
| 1435 | __ jmp(false_target); |
| 1436 | } |
| 1437 | } |
| 1438 | return; |
| 1439 | } |
| 1440 | |
| 1441 | // The following code generates these patterns: |
| 1442 | // (1) true_target == nullptr && false_target != nullptr |
| 1443 | // - opposite condition true => branch to false_target |
| 1444 | // (2) true_target != nullptr && false_target == nullptr |
| 1445 | // - condition true => branch to true_target |
| 1446 | // (3) true_target != nullptr && false_target != nullptr |
| 1447 | // - condition true => branch to true_target |
| 1448 | // - branch to false_target |
| 1449 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1450 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1451 | if (true_target == nullptr) { |
| 1452 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1453 | } else { |
| 1454 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1455 | } |
| 1456 | } else { |
| 1457 | // Materialized condition, compare against 0. |
| 1458 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1459 | if (lhs.IsRegister()) { |
| 1460 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1461 | } else { |
| 1462 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1463 | } |
| 1464 | if (true_target == nullptr) { |
| 1465 | __ j(kEqual, false_target); |
| 1466 | } else { |
| 1467 | __ j(kNotEqual, true_target); |
| 1468 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1469 | } |
| 1470 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1471 | // Condition has not been materialized, use its inputs as the comparison and |
| 1472 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1473 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1474 | |
| 1475 | // If this is a long or FP comparison that has been folded into |
| 1476 | // the HCondition, generate the comparison directly. |
| 1477 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1478 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1479 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1480 | return; |
| 1481 | } |
| 1482 | |
| 1483 | Location lhs = condition->GetLocations()->InAt(0); |
| 1484 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1485 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1486 | if (rhs.IsRegister()) { |
| 1487 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1488 | } else if (rhs.IsConstant()) { |
| 1489 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1490 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1491 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1492 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1493 | } |
| 1494 | if (true_target == nullptr) { |
| 1495 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1496 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1497 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1498 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1499 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1500 | |
| 1501 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1502 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1503 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1504 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1508 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1509 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1510 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1511 | locations->SetInAt(0, Location::Any()); |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1516 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1517 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1518 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1519 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1520 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1521 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1522 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1526 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1527 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1528 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1529 | locations->SetInAt(0, Location::Any()); |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1534 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1535 | GenerateTestAndBranch<Label>(deoptimize, |
| 1536 | /* condition_input_index */ 0, |
| 1537 | slow_path->GetEntryLabel(), |
| 1538 | /* false_target */ nullptr); |
| 1539 | } |
| 1540 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1541 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1542 | // There are no conditional move instructions for XMMs. |
| 1543 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1544 | return false; |
| 1545 | } |
| 1546 | |
| 1547 | // A FP condition doesn't generate the single CC that we need. |
| 1548 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1549 | HInstruction* condition = select->GetCondition(); |
| 1550 | if (condition->IsCondition()) { |
| 1551 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1552 | if (compare_type == Primitive::kPrimLong || |
| 1553 | Primitive::IsFloatingPointType(compare_type)) { |
| 1554 | return false; |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | // We can generate a CMOV for this Select. |
| 1559 | return true; |
| 1560 | } |
| 1561 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1562 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1563 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1564 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1565 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1566 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1567 | } else { |
| 1568 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1569 | if (SelectCanUseCMOV(select)) { |
| 1570 | if (select->InputAt(1)->IsConstant()) { |
| 1571 | // Cmov can't handle a constant value. |
| 1572 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1573 | } else { |
| 1574 | locations->SetInAt(1, Location::Any()); |
| 1575 | } |
| 1576 | } else { |
| 1577 | locations->SetInAt(1, Location::Any()); |
| 1578 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1579 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1580 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1581 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1582 | } |
| 1583 | locations->SetOut(Location::SameAsFirstInput()); |
| 1584 | } |
| 1585 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1586 | void InstructionCodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 1587 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 1588 | if (rhs.IsConstant()) { |
| 1589 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1590 | codegen_->Compare32BitValue(lhs_reg, value); |
| 1591 | } else if (rhs.IsStackSlot()) { |
| 1592 | __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
| 1593 | } else { |
| 1594 | __ cmpl(lhs_reg, rhs.AsRegister<Register>()); |
| 1595 | } |
| 1596 | } |
| 1597 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1598 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1599 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1600 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1601 | if (SelectCanUseCMOV(select)) { |
| 1602 | // If both the condition and the source types are integer, we can generate |
| 1603 | // a CMOV to implement Select. |
| 1604 | |
| 1605 | HInstruction* select_condition = select->GetCondition(); |
| 1606 | Condition cond = kNotEqual; |
| 1607 | |
| 1608 | // Figure out how to test the 'condition'. |
| 1609 | if (select_condition->IsCondition()) { |
| 1610 | HCondition* condition = select_condition->AsCondition(); |
| 1611 | if (!condition->IsEmittedAtUseSite()) { |
| 1612 | // This was a previously materialized condition. |
| 1613 | // Can we use the existing condition code? |
| 1614 | if (AreEflagsSetFrom(condition, select)) { |
| 1615 | // Materialization was the previous instruction. Condition codes are right. |
| 1616 | cond = X86Condition(condition->GetCondition()); |
| 1617 | } else { |
| 1618 | // No, we have to recreate the condition code. |
| 1619 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1620 | __ testl(cond_reg, cond_reg); |
| 1621 | } |
| 1622 | } else { |
| 1623 | // We can't handle FP or long here. |
| 1624 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1625 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1626 | LocationSummary* cond_locations = condition->GetLocations(); |
| 1627 | GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| 1628 | cond = X86Condition(condition->GetCondition()); |
| 1629 | } |
| 1630 | } else { |
| 1631 | // Must be a boolean condition, which needs to be compared to 0. |
| 1632 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1633 | __ testl(cond_reg, cond_reg); |
| 1634 | } |
| 1635 | |
| 1636 | // If the condition is true, overwrite the output, which already contains false. |
| 1637 | Location false_loc = locations->InAt(0); |
| 1638 | Location true_loc = locations->InAt(1); |
| 1639 | if (select->GetType() == Primitive::kPrimLong) { |
| 1640 | // 64 bit conditional move. |
| 1641 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1642 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1643 | if (true_loc.IsRegisterPair()) { |
| 1644 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1645 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1646 | } else { |
| 1647 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1648 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1649 | } |
| 1650 | } else { |
| 1651 | // 32 bit conditional move. |
| 1652 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1653 | if (true_loc.IsRegister()) { |
| 1654 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1655 | } else { |
| 1656 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1657 | } |
| 1658 | } |
| 1659 | } else { |
| 1660 | NearLabel false_target; |
| 1661 | GenerateTestAndBranch<NearLabel>( |
| 1662 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1663 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1664 | __ Bind(&false_target); |
| 1665 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1668 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1669 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1670 | } |
| 1671 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1672 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1673 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | void CodeGeneratorX86::GenerateNop() { |
| 1677 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1680 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1681 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1682 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1683 | // Handle the long/FP comparisons made in instruction simplification. |
| 1684 | switch (cond->InputAt(0)->GetType()) { |
| 1685 | case Primitive::kPrimLong: { |
| 1686 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1687 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1688 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1689 | locations->SetOut(Location::RequiresRegister()); |
| 1690 | } |
| 1691 | break; |
| 1692 | } |
| 1693 | case Primitive::kPrimFloat: |
| 1694 | case Primitive::kPrimDouble: { |
| 1695 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1696 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1697 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1698 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1699 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1700 | } else { |
| 1701 | locations->SetInAt(1, Location::Any()); |
| 1702 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1703 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1704 | locations->SetOut(Location::RequiresRegister()); |
| 1705 | } |
| 1706 | break; |
| 1707 | } |
| 1708 | default: |
| 1709 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1710 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1711 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1712 | // We need a byte register. |
| 1713 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1714 | } |
| 1715 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1716 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1719 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1720 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1721 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1722 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1723 | |
| 1724 | LocationSummary* locations = cond->GetLocations(); |
| 1725 | Location lhs = locations->InAt(0); |
| 1726 | Location rhs = locations->InAt(1); |
| 1727 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1728 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1729 | |
| 1730 | switch (cond->InputAt(0)->GetType()) { |
| 1731 | default: { |
| 1732 | // Integer case. |
| 1733 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1734 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1735 | __ xorl(reg, reg); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1736 | GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1737 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1738 | return; |
| 1739 | } |
| 1740 | case Primitive::kPrimLong: |
| 1741 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1742 | break; |
| 1743 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1744 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1745 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1746 | break; |
| 1747 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1748 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1749 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1750 | break; |
| 1751 | } |
| 1752 | |
| 1753 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1754 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1755 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1756 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1757 | __ Bind(&false_label); |
| 1758 | __ xorl(reg, reg); |
| 1759 | __ jmp(&done_label); |
| 1760 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1761 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1762 | __ Bind(&true_label); |
| 1763 | __ movl(reg, Immediate(1)); |
| 1764 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1768 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1772 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1776 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1780 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1784 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1788 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1796 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1800 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1804 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1808 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1812 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1815 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1816 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1820 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1824 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1828 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1832 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1836 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1840 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1844 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1847 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1848 | LocationSummary* locations = |
| 1849 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1850 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1853 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1854 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1857 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1858 | LocationSummary* locations = |
| 1859 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1860 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1861 | } |
| 1862 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1863 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1864 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1867 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1868 | LocationSummary* locations = |
| 1869 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1870 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1871 | } |
| 1872 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1873 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1874 | // Will be generated at use site. |
| 1875 | } |
| 1876 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1877 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1878 | LocationSummary* locations = |
| 1879 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1880 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1881 | } |
| 1882 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1883 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1884 | // Will be generated at use site. |
| 1885 | } |
| 1886 | |
| 1887 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1888 | LocationSummary* locations = |
| 1889 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1890 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1891 | } |
| 1892 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1893 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1894 | // Will be generated at use site. |
| 1895 | } |
| 1896 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1897 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1898 | memory_barrier->SetLocations(nullptr); |
| 1899 | } |
| 1900 | |
| 1901 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1902 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1903 | } |
| 1904 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1905 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1906 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1909 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1910 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1913 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1914 | LocationSummary* locations = |
| 1915 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1916 | switch (ret->InputAt(0)->GetType()) { |
| 1917 | case Primitive::kPrimBoolean: |
| 1918 | case Primitive::kPrimByte: |
| 1919 | case Primitive::kPrimChar: |
| 1920 | case Primitive::kPrimShort: |
| 1921 | case Primitive::kPrimInt: |
| 1922 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1923 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1924 | break; |
| 1925 | |
| 1926 | case Primitive::kPrimLong: |
| 1927 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1928 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1929 | break; |
| 1930 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1931 | case Primitive::kPrimFloat: |
| 1932 | case Primitive::kPrimDouble: |
| 1933 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1934 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1935 | break; |
| 1936 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1937 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1938 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1939 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1942 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1943 | if (kIsDebugBuild) { |
| 1944 | switch (ret->InputAt(0)->GetType()) { |
| 1945 | case Primitive::kPrimBoolean: |
| 1946 | case Primitive::kPrimByte: |
| 1947 | case Primitive::kPrimChar: |
| 1948 | case Primitive::kPrimShort: |
| 1949 | case Primitive::kPrimInt: |
| 1950 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1951 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1952 | break; |
| 1953 | |
| 1954 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1955 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1956 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1957 | break; |
| 1958 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1959 | case Primitive::kPrimFloat: |
| 1960 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1961 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1962 | break; |
| 1963 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1964 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1965 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1966 | } |
| 1967 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1968 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1971 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1972 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1973 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1974 | // the method_idx. |
| 1975 | HandleInvoke(invoke); |
| 1976 | } |
| 1977 | |
| 1978 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1979 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1980 | } |
| 1981 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1982 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1983 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1984 | // art::PrepareForRegisterAllocation. |
| 1985 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1986 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1987 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1988 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1989 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1990 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1991 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1992 | return; |
| 1993 | } |
| 1994 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1995 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1996 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1997 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1998 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1999 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2000 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2001 | } |
| 2002 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2003 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2004 | if (invoke->GetLocations()->Intrinsified()) { |
| 2005 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2006 | intrinsic.Dispatch(invoke); |
| 2007 | return true; |
| 2008 | } |
| 2009 | return false; |
| 2010 | } |
| 2011 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2012 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2013 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2014 | // art::PrepareForRegisterAllocation. |
| 2015 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2016 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2017 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2018 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2019 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2020 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2021 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2022 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2023 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2024 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2028 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2029 | if (intrinsic.TryDispatch(invoke)) { |
| 2030 | return; |
| 2031 | } |
| 2032 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2033 | HandleInvoke(invoke); |
| 2034 | } |
| 2035 | |
| 2036 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2037 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2038 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2041 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2042 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2043 | return; |
| 2044 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2045 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2046 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2047 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2048 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2051 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2052 | // This call to HandleInvoke allocates a temporary (core) register |
| 2053 | // which is also used to transfer the hidden argument from FP to |
| 2054 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2055 | HandleInvoke(invoke); |
| 2056 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2057 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2061 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2062 | LocationSummary* locations = invoke->GetLocations(); |
| 2063 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2064 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2065 | Location receiver = locations->InAt(0); |
| 2066 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2067 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2068 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2069 | // won't be modified thereafter, before the `call` instruction. |
| 2070 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2071 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2072 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2073 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2074 | if (receiver.IsStackSlot()) { |
| 2075 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2076 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2077 | __ movl(temp, Address(temp, class_offset)); |
| 2078 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2079 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2080 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2081 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2082 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2083 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2084 | // emit a read barrier for the previous class reference load. |
| 2085 | // However this is not required in practice, as this is an |
| 2086 | // intermediate/temporary reference and because the current |
| 2087 | // concurrent copying collector keeps the from-space memory |
| 2088 | // intact/accessible until the end of the marking phase (the |
| 2089 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2090 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2091 | // temp = temp->GetAddressOfIMT() |
| 2092 | __ movl(temp, |
| 2093 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2094 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2095 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 2096 | invoke->GetImtIndex() % ImTable::kSize, kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2097 | __ movl(temp, Address(temp, method_offset)); |
| 2098 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2099 | __ call(Address(temp, |
| 2100 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2101 | |
| 2102 | DCHECK(!codegen_->IsLeafMethod()); |
| 2103 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2104 | } |
| 2105 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2106 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2107 | LocationSummary* locations = |
| 2108 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2109 | switch (neg->GetResultType()) { |
| 2110 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2111 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2112 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2113 | locations->SetOut(Location::SameAsFirstInput()); |
| 2114 | break; |
| 2115 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2116 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2117 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2118 | locations->SetOut(Location::SameAsFirstInput()); |
| 2119 | locations->AddTemp(Location::RequiresRegister()); |
| 2120 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2121 | break; |
| 2122 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2123 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2124 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2125 | locations->SetOut(Location::SameAsFirstInput()); |
| 2126 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2127 | break; |
| 2128 | |
| 2129 | default: |
| 2130 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2131 | } |
| 2132 | } |
| 2133 | |
| 2134 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2135 | LocationSummary* locations = neg->GetLocations(); |
| 2136 | Location out = locations->Out(); |
| 2137 | Location in = locations->InAt(0); |
| 2138 | switch (neg->GetResultType()) { |
| 2139 | case Primitive::kPrimInt: |
| 2140 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2141 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2142 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2143 | break; |
| 2144 | |
| 2145 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2146 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2147 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2148 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2149 | // Negation is similar to subtraction from zero. The least |
| 2150 | // significant byte triggers a borrow when it is different from |
| 2151 | // zero; to take it into account, add 1 to the most significant |
| 2152 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2153 | // operation. |
| 2154 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2155 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2156 | break; |
| 2157 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2158 | case Primitive::kPrimFloat: { |
| 2159 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2160 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2161 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2162 | // Implement float negation with an exclusive or with value |
| 2163 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2164 | // single-precision floating-point number). |
| 2165 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2166 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2167 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2168 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2169 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2170 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2171 | case Primitive::kPrimDouble: { |
| 2172 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2173 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2174 | // Implement double negation with an exclusive or with value |
| 2175 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2176 | // a double-precision floating-point number). |
| 2177 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2178 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2179 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2180 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2181 | |
| 2182 | default: |
| 2183 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2184 | } |
| 2185 | } |
| 2186 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2187 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2188 | LocationSummary* locations = |
| 2189 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2190 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2191 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2192 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2193 | locations->SetOut(Location::SameAsFirstInput()); |
| 2194 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2195 | } |
| 2196 | |
| 2197 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2198 | LocationSummary* locations = neg->GetLocations(); |
| 2199 | Location out = locations->Out(); |
| 2200 | DCHECK(locations->InAt(0).Equals(out)); |
| 2201 | |
| 2202 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2203 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2204 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2205 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2206 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2207 | } else { |
| 2208 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2209 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2210 | } |
| 2211 | } |
| 2212 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2213 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2214 | Primitive::Type result_type = conversion->GetResultType(); |
| 2215 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2216 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2217 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2218 | // The float-to-long and double-to-long type conversions rely on a |
| 2219 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2220 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2221 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2222 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2223 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2224 | : LocationSummary::kNoCall; |
| 2225 | LocationSummary* locations = |
| 2226 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2227 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2228 | // The Java language does not allow treating boolean as an integral type but |
| 2229 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2230 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2231 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2232 | case Primitive::kPrimByte: |
| 2233 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2234 | case Primitive::kPrimLong: { |
| 2235 | // Type conversion from long to byte is a result of code transformations. |
| 2236 | HInstruction* input = conversion->InputAt(0); |
| 2237 | Location input_location = input->IsConstant() |
| 2238 | ? Location::ConstantLocation(input->AsConstant()) |
| 2239 | : Location::RegisterPairLocation(EAX, EDX); |
| 2240 | locations->SetInAt(0, input_location); |
| 2241 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2242 | // the validation of the linear scan implementation |
| 2243 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2244 | break; |
| 2245 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2246 | case Primitive::kPrimBoolean: |
| 2247 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2248 | case Primitive::kPrimShort: |
| 2249 | case Primitive::kPrimInt: |
| 2250 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2251 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2252 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2253 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2254 | // the validation of the linear scan implementation |
| 2255 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2256 | break; |
| 2257 | |
| 2258 | default: |
| 2259 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2260 | << " to " << result_type; |
| 2261 | } |
| 2262 | break; |
| 2263 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2264 | case Primitive::kPrimShort: |
| 2265 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2266 | case Primitive::kPrimLong: |
| 2267 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2268 | case Primitive::kPrimBoolean: |
| 2269 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2270 | case Primitive::kPrimByte: |
| 2271 | case Primitive::kPrimInt: |
| 2272 | case Primitive::kPrimChar: |
| 2273 | // Processing a Dex `int-to-short' instruction. |
| 2274 | locations->SetInAt(0, Location::Any()); |
| 2275 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2276 | break; |
| 2277 | |
| 2278 | default: |
| 2279 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2280 | << " to " << result_type; |
| 2281 | } |
| 2282 | break; |
| 2283 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2284 | case Primitive::kPrimInt: |
| 2285 | switch (input_type) { |
| 2286 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2287 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2288 | locations->SetInAt(0, Location::Any()); |
| 2289 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2290 | break; |
| 2291 | |
| 2292 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2293 | // Processing a Dex `float-to-int' instruction. |
| 2294 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2295 | locations->SetOut(Location::RequiresRegister()); |
| 2296 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2297 | break; |
| 2298 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2299 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2300 | // Processing a Dex `double-to-int' instruction. |
| 2301 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2302 | locations->SetOut(Location::RequiresRegister()); |
| 2303 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2304 | break; |
| 2305 | |
| 2306 | default: |
| 2307 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2308 | << " to " << result_type; |
| 2309 | } |
| 2310 | break; |
| 2311 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimLong: |
| 2313 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimBoolean: |
| 2315 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimByte: |
| 2317 | case Primitive::kPrimShort: |
| 2318 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2319 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2320 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2321 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2322 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2323 | break; |
| 2324 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2325 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2326 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2327 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2328 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2329 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2330 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2331 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2332 | // The runtime helper puts the result in EAX, EDX. |
| 2333 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2334 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2335 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2336 | |
| 2337 | default: |
| 2338 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2339 | << " to " << result_type; |
| 2340 | } |
| 2341 | break; |
| 2342 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2343 | case Primitive::kPrimChar: |
| 2344 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2345 | case Primitive::kPrimLong: |
| 2346 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimBoolean: |
| 2348 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2349 | case Primitive::kPrimByte: |
| 2350 | case Primitive::kPrimShort: |
| 2351 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2352 | // Processing a Dex `int-to-char' instruction. |
| 2353 | locations->SetInAt(0, Location::Any()); |
| 2354 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2355 | break; |
| 2356 | |
| 2357 | default: |
| 2358 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2359 | << " to " << result_type; |
| 2360 | } |
| 2361 | break; |
| 2362 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2364 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimBoolean: |
| 2366 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2367 | case Primitive::kPrimByte: |
| 2368 | case Primitive::kPrimShort: |
| 2369 | case Primitive::kPrimInt: |
| 2370 | case Primitive::kPrimChar: |
| 2371 | // Processing a Dex `int-to-float' instruction. |
| 2372 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2373 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2374 | break; |
| 2375 | |
| 2376 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2377 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2378 | locations->SetInAt(0, Location::Any()); |
| 2379 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2380 | break; |
| 2381 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2382 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2383 | // Processing a Dex `double-to-float' instruction. |
| 2384 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2385 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | |
| 2388 | default: |
| 2389 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2390 | << " to " << result_type; |
| 2391 | }; |
| 2392 | break; |
| 2393 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2394 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2395 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2396 | case Primitive::kPrimBoolean: |
| 2397 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2398 | case Primitive::kPrimByte: |
| 2399 | case Primitive::kPrimShort: |
| 2400 | case Primitive::kPrimInt: |
| 2401 | case Primitive::kPrimChar: |
| 2402 | // Processing a Dex `int-to-double' instruction. |
| 2403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2404 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2405 | break; |
| 2406 | |
| 2407 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2408 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2409 | locations->SetInAt(0, Location::Any()); |
| 2410 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2411 | break; |
| 2412 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2414 | // Processing a Dex `float-to-double' instruction. |
| 2415 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2416 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2417 | break; |
| 2418 | |
| 2419 | default: |
| 2420 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2421 | << " to " << result_type; |
| 2422 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2423 | break; |
| 2424 | |
| 2425 | default: |
| 2426 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2427 | << " to " << result_type; |
| 2428 | } |
| 2429 | } |
| 2430 | |
| 2431 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2432 | LocationSummary* locations = conversion->GetLocations(); |
| 2433 | Location out = locations->Out(); |
| 2434 | Location in = locations->InAt(0); |
| 2435 | Primitive::Type result_type = conversion->GetResultType(); |
| 2436 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2437 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2438 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2439 | case Primitive::kPrimByte: |
| 2440 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2441 | case Primitive::kPrimLong: |
| 2442 | // Type conversion from long to byte is a result of code transformations. |
| 2443 | if (in.IsRegisterPair()) { |
| 2444 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2445 | } else { |
| 2446 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2447 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2448 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2449 | } |
| 2450 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2451 | case Primitive::kPrimBoolean: |
| 2452 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2453 | case Primitive::kPrimShort: |
| 2454 | case Primitive::kPrimInt: |
| 2455 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2456 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2457 | if (in.IsRegister()) { |
| 2458 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2459 | } else { |
| 2460 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2461 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2462 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2463 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2464 | break; |
| 2465 | |
| 2466 | default: |
| 2467 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2468 | << " to " << result_type; |
| 2469 | } |
| 2470 | break; |
| 2471 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2472 | case Primitive::kPrimShort: |
| 2473 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2474 | case Primitive::kPrimLong: |
| 2475 | // Type conversion from long to short is a result of code transformations. |
| 2476 | if (in.IsRegisterPair()) { |
| 2477 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2478 | } else if (in.IsDoubleStackSlot()) { |
| 2479 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2480 | } else { |
| 2481 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2482 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2483 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2484 | } |
| 2485 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2486 | case Primitive::kPrimBoolean: |
| 2487 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2488 | case Primitive::kPrimByte: |
| 2489 | case Primitive::kPrimInt: |
| 2490 | case Primitive::kPrimChar: |
| 2491 | // Processing a Dex `int-to-short' instruction. |
| 2492 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2493 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2494 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2495 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2496 | } else { |
| 2497 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2498 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2499 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2500 | } |
| 2501 | break; |
| 2502 | |
| 2503 | default: |
| 2504 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2505 | << " to " << result_type; |
| 2506 | } |
| 2507 | break; |
| 2508 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2509 | case Primitive::kPrimInt: |
| 2510 | switch (input_type) { |
| 2511 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2512 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2513 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2514 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2515 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2516 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2517 | } else { |
| 2518 | DCHECK(in.IsConstant()); |
| 2519 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2520 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2521 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2522 | } |
| 2523 | break; |
| 2524 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2525 | case Primitive::kPrimFloat: { |
| 2526 | // Processing a Dex `float-to-int' instruction. |
| 2527 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2528 | Register output = out.AsRegister<Register>(); |
| 2529 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2530 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2531 | |
| 2532 | __ movl(output, Immediate(kPrimIntMax)); |
| 2533 | // temp = int-to-float(output) |
| 2534 | __ cvtsi2ss(temp, output); |
| 2535 | // if input >= temp goto done |
| 2536 | __ comiss(input, temp); |
| 2537 | __ j(kAboveEqual, &done); |
| 2538 | // if input == NaN goto nan |
| 2539 | __ j(kUnordered, &nan); |
| 2540 | // output = float-to-int-truncate(input) |
| 2541 | __ cvttss2si(output, input); |
| 2542 | __ jmp(&done); |
| 2543 | __ Bind(&nan); |
| 2544 | // output = 0 |
| 2545 | __ xorl(output, output); |
| 2546 | __ Bind(&done); |
| 2547 | break; |
| 2548 | } |
| 2549 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2550 | case Primitive::kPrimDouble: { |
| 2551 | // Processing a Dex `double-to-int' instruction. |
| 2552 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2553 | Register output = out.AsRegister<Register>(); |
| 2554 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2555 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2556 | |
| 2557 | __ movl(output, Immediate(kPrimIntMax)); |
| 2558 | // temp = int-to-double(output) |
| 2559 | __ cvtsi2sd(temp, output); |
| 2560 | // if input >= temp goto done |
| 2561 | __ comisd(input, temp); |
| 2562 | __ j(kAboveEqual, &done); |
| 2563 | // if input == NaN goto nan |
| 2564 | __ j(kUnordered, &nan); |
| 2565 | // output = double-to-int-truncate(input) |
| 2566 | __ cvttsd2si(output, input); |
| 2567 | __ jmp(&done); |
| 2568 | __ Bind(&nan); |
| 2569 | // output = 0 |
| 2570 | __ xorl(output, output); |
| 2571 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2572 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2573 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2574 | |
| 2575 | default: |
| 2576 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2577 | << " to " << result_type; |
| 2578 | } |
| 2579 | break; |
| 2580 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2581 | case Primitive::kPrimLong: |
| 2582 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2583 | case Primitive::kPrimBoolean: |
| 2584 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2585 | case Primitive::kPrimByte: |
| 2586 | case Primitive::kPrimShort: |
| 2587 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2589 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2590 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2591 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2592 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2593 | __ cdq(); |
| 2594 | break; |
| 2595 | |
| 2596 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2597 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2598 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2599 | conversion, |
| 2600 | conversion->GetDexPc(), |
| 2601 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2602 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2603 | break; |
| 2604 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2606 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2607 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2608 | conversion, |
| 2609 | conversion->GetDexPc(), |
| 2610 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2611 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2612 | break; |
| 2613 | |
| 2614 | default: |
| 2615 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2616 | << " to " << result_type; |
| 2617 | } |
| 2618 | break; |
| 2619 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2620 | case Primitive::kPrimChar: |
| 2621 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimLong: |
| 2623 | // Type conversion from long to short is a result of code transformations. |
| 2624 | if (in.IsRegisterPair()) { |
| 2625 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2626 | } else if (in.IsDoubleStackSlot()) { |
| 2627 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2628 | } else { |
| 2629 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2630 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2631 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2632 | } |
| 2633 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2634 | case Primitive::kPrimBoolean: |
| 2635 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2636 | case Primitive::kPrimByte: |
| 2637 | case Primitive::kPrimShort: |
| 2638 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2639 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2640 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2641 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2642 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2643 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2644 | } else { |
| 2645 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2646 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2647 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2648 | } |
| 2649 | break; |
| 2650 | |
| 2651 | default: |
| 2652 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2653 | << " to " << result_type; |
| 2654 | } |
| 2655 | break; |
| 2656 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2657 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2658 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2659 | case Primitive::kPrimBoolean: |
| 2660 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2661 | case Primitive::kPrimByte: |
| 2662 | case Primitive::kPrimShort: |
| 2663 | case Primitive::kPrimInt: |
| 2664 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2665 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2666 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 | break; |
| 2668 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2669 | case Primitive::kPrimLong: { |
| 2670 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2671 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2672 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2673 | // Create stack space for the call to |
| 2674 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2675 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2676 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2677 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2678 | __ subl(ESP, Immediate(adjustment)); |
| 2679 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2680 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2681 | // Load the value to the FP stack, using temporaries if needed. |
| 2682 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2683 | |
| 2684 | if (out.IsStackSlot()) { |
| 2685 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2686 | } else { |
| 2687 | __ fstps(Address(ESP, 0)); |
| 2688 | Location stack_temp = Location::StackSlot(0); |
| 2689 | codegen_->Move32(out, stack_temp); |
| 2690 | } |
| 2691 | |
| 2692 | // Remove the temporary stack space we allocated. |
| 2693 | if (adjustment != 0) { |
| 2694 | __ addl(ESP, Immediate(adjustment)); |
| 2695 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2696 | break; |
| 2697 | } |
| 2698 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2699 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2700 | // Processing a Dex `double-to-float' instruction. |
| 2701 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2702 | break; |
| 2703 | |
| 2704 | default: |
| 2705 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2706 | << " to " << result_type; |
| 2707 | }; |
| 2708 | break; |
| 2709 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2710 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2711 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2712 | case Primitive::kPrimBoolean: |
| 2713 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2714 | case Primitive::kPrimByte: |
| 2715 | case Primitive::kPrimShort: |
| 2716 | case Primitive::kPrimInt: |
| 2717 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2718 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2719 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2720 | break; |
| 2721 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2722 | case Primitive::kPrimLong: { |
| 2723 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2724 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2725 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2726 | // Create stack space for the call to |
| 2727 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2728 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2729 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2730 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2731 | __ subl(ESP, Immediate(adjustment)); |
| 2732 | } |
| 2733 | |
| 2734 | // Load the value to the FP stack, using temporaries if needed. |
| 2735 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2736 | |
| 2737 | if (out.IsDoubleStackSlot()) { |
| 2738 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2739 | } else { |
| 2740 | __ fstpl(Address(ESP, 0)); |
| 2741 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2742 | codegen_->Move64(out, stack_temp); |
| 2743 | } |
| 2744 | |
| 2745 | // Remove the temporary stack space we allocated. |
| 2746 | if (adjustment != 0) { |
| 2747 | __ addl(ESP, Immediate(adjustment)); |
| 2748 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2749 | break; |
| 2750 | } |
| 2751 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2752 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2753 | // Processing a Dex `float-to-double' instruction. |
| 2754 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2755 | break; |
| 2756 | |
| 2757 | default: |
| 2758 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2759 | << " to " << result_type; |
| 2760 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2761 | break; |
| 2762 | |
| 2763 | default: |
| 2764 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2765 | << " to " << result_type; |
| 2766 | } |
| 2767 | } |
| 2768 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2769 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2770 | LocationSummary* locations = |
| 2771 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2772 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2773 | case Primitive::kPrimInt: { |
| 2774 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2775 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2776 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2777 | break; |
| 2778 | } |
| 2779 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2780 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2781 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2782 | locations->SetInAt(1, Location::Any()); |
| 2783 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2784 | break; |
| 2785 | } |
| 2786 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2787 | case Primitive::kPrimFloat: |
| 2788 | case Primitive::kPrimDouble: { |
| 2789 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2790 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2791 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2792 | } else if (add->InputAt(1)->IsConstant()) { |
| 2793 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2794 | } else { |
| 2795 | locations->SetInAt(1, Location::Any()); |
| 2796 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2797 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2798 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2799 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2800 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2801 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2802 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2803 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2804 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2808 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2809 | Location first = locations->InAt(0); |
| 2810 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2811 | Location out = locations->Out(); |
| 2812 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2813 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2814 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2815 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2816 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2817 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2818 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2819 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2820 | } else { |
| 2821 | __ leal(out.AsRegister<Register>(), Address( |
| 2822 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2823 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2824 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2825 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2826 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2827 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2828 | } else { |
| 2829 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2830 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2831 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2832 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2833 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2834 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2835 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2839 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2840 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2841 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2842 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2843 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2844 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2845 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2846 | } else { |
| 2847 | DCHECK(second.IsConstant()) << second; |
| 2848 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2849 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2850 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2851 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2852 | break; |
| 2853 | } |
| 2854 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2855 | case Primitive::kPrimFloat: { |
| 2856 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2857 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2858 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2859 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2860 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2861 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2862 | codegen_->LiteralFloatAddress( |
| 2863 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2864 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2865 | } else { |
| 2866 | DCHECK(second.IsStackSlot()); |
| 2867 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2868 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2869 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | case Primitive::kPrimDouble: { |
| 2873 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2874 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2875 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2876 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2877 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2878 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2879 | codegen_->LiteralDoubleAddress( |
| 2880 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2881 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2882 | } else { |
| 2883 | DCHECK(second.IsDoubleStackSlot()); |
| 2884 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2885 | } |
| 2886 | break; |
| 2887 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2888 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2889 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2890 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2891 | } |
| 2892 | } |
| 2893 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2894 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2895 | LocationSummary* locations = |
| 2896 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2897 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2898 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2899 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2900 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2901 | locations->SetInAt(1, Location::Any()); |
| 2902 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2903 | break; |
| 2904 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2905 | case Primitive::kPrimFloat: |
| 2906 | case Primitive::kPrimDouble: { |
| 2907 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2908 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2909 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2910 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2911 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2912 | } else { |
| 2913 | locations->SetInAt(1, Location::Any()); |
| 2914 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2915 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2916 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2917 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2918 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2919 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2920 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2921 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2925 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2926 | Location first = locations->InAt(0); |
| 2927 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2928 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2929 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2930 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2931 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2932 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2933 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2934 | __ subl(first.AsRegister<Register>(), |
| 2935 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2936 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2937 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2938 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2939 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2943 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2944 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2945 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2946 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2947 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2948 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2949 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2950 | } else { |
| 2951 | DCHECK(second.IsConstant()) << second; |
| 2952 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2953 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2954 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2955 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2956 | break; |
| 2957 | } |
| 2958 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2959 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2960 | if (second.IsFpuRegister()) { |
| 2961 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2962 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2963 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2964 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2965 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2966 | codegen_->LiteralFloatAddress( |
| 2967 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2968 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2969 | } else { |
| 2970 | DCHECK(second.IsStackSlot()); |
| 2971 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2972 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2973 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2977 | if (second.IsFpuRegister()) { |
| 2978 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2979 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2980 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2981 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2982 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2983 | codegen_->LiteralDoubleAddress( |
| 2984 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2985 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2986 | } else { |
| 2987 | DCHECK(second.IsDoubleStackSlot()); |
| 2988 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2989 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2990 | break; |
| 2991 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2992 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2993 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2994 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2995 | } |
| 2996 | } |
| 2997 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2998 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2999 | LocationSummary* locations = |
| 3000 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3001 | switch (mul->GetResultType()) { |
| 3002 | case Primitive::kPrimInt: |
| 3003 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3004 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3005 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3006 | // Can use 3 operand multiply. |
| 3007 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3008 | } else { |
| 3009 | locations->SetOut(Location::SameAsFirstInput()); |
| 3010 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3011 | break; |
| 3012 | case Primitive::kPrimLong: { |
| 3013 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3014 | locations->SetInAt(1, Location::Any()); |
| 3015 | locations->SetOut(Location::SameAsFirstInput()); |
| 3016 | // Needed for imul on 32bits with 64bits output. |
| 3017 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3018 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3019 | break; |
| 3020 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3021 | case Primitive::kPrimFloat: |
| 3022 | case Primitive::kPrimDouble: { |
| 3023 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3024 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3025 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3026 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3027 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3028 | } else { |
| 3029 | locations->SetInAt(1, Location::Any()); |
| 3030 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3031 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3032 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3033 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3034 | |
| 3035 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3036 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3037 | } |
| 3038 | } |
| 3039 | |
| 3040 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3041 | LocationSummary* locations = mul->GetLocations(); |
| 3042 | Location first = locations->InAt(0); |
| 3043 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3044 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3045 | |
| 3046 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3047 | case Primitive::kPrimInt: |
| 3048 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3049 | // problems where the output may not be the same as the first operand. |
| 3050 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3051 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3052 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3053 | } else if (second.IsRegister()) { |
| 3054 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3055 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3056 | } else { |
| 3057 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3058 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3059 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3060 | } |
| 3061 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3062 | |
| 3063 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3064 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3065 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3066 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3067 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3068 | |
| 3069 | DCHECK_EQ(EAX, eax); |
| 3070 | DCHECK_EQ(EDX, edx); |
| 3071 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3072 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3073 | // output: in1 |
| 3074 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3075 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3076 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3077 | if (second.IsConstant()) { |
| 3078 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3079 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3080 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3081 | int32_t low_value = Low32Bits(value); |
| 3082 | int32_t high_value = High32Bits(value); |
| 3083 | Immediate low(low_value); |
| 3084 | Immediate high(high_value); |
| 3085 | |
| 3086 | __ movl(eax, high); |
| 3087 | // eax <- in1.lo * in2.hi |
| 3088 | __ imull(eax, in1_lo); |
| 3089 | // in1.hi <- in1.hi * in2.lo |
| 3090 | __ imull(in1_hi, low); |
| 3091 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3092 | __ addl(in1_hi, eax); |
| 3093 | // move in2_lo to eax to prepare for double precision |
| 3094 | __ movl(eax, low); |
| 3095 | // edx:eax <- in1.lo * in2.lo |
| 3096 | __ mull(in1_lo); |
| 3097 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3098 | __ addl(in1_hi, edx); |
| 3099 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3100 | __ movl(in1_lo, eax); |
| 3101 | } else if (second.IsRegisterPair()) { |
| 3102 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3103 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3104 | |
| 3105 | __ movl(eax, in2_hi); |
| 3106 | // eax <- in1.lo * in2.hi |
| 3107 | __ imull(eax, in1_lo); |
| 3108 | // in1.hi <- in1.hi * in2.lo |
| 3109 | __ imull(in1_hi, in2_lo); |
| 3110 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3111 | __ addl(in1_hi, eax); |
| 3112 | // move in1_lo to eax to prepare for double precision |
| 3113 | __ movl(eax, in1_lo); |
| 3114 | // edx:eax <- in1.lo * in2.lo |
| 3115 | __ mull(in2_lo); |
| 3116 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3117 | __ addl(in1_hi, edx); |
| 3118 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3119 | __ movl(in1_lo, eax); |
| 3120 | } else { |
| 3121 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3122 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3123 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3124 | |
| 3125 | __ movl(eax, in2_hi); |
| 3126 | // eax <- in1.lo * in2.hi |
| 3127 | __ imull(eax, in1_lo); |
| 3128 | // in1.hi <- in1.hi * in2.lo |
| 3129 | __ imull(in1_hi, in2_lo); |
| 3130 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3131 | __ addl(in1_hi, eax); |
| 3132 | // move in1_lo to eax to prepare for double precision |
| 3133 | __ movl(eax, in1_lo); |
| 3134 | // edx:eax <- in1.lo * in2.lo |
| 3135 | __ mull(in2_lo); |
| 3136 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3137 | __ addl(in1_hi, edx); |
| 3138 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3139 | __ movl(in1_lo, eax); |
| 3140 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3141 | |
| 3142 | break; |
| 3143 | } |
| 3144 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3145 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3146 | DCHECK(first.Equals(locations->Out())); |
| 3147 | if (second.IsFpuRegister()) { |
| 3148 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3149 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3150 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3151 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3152 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3153 | codegen_->LiteralFloatAddress( |
| 3154 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3155 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3156 | } else { |
| 3157 | DCHECK(second.IsStackSlot()); |
| 3158 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3159 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3160 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3164 | DCHECK(first.Equals(locations->Out())); |
| 3165 | if (second.IsFpuRegister()) { |
| 3166 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3167 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3168 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3169 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3170 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3171 | codegen_->LiteralDoubleAddress( |
| 3172 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3173 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3174 | } else { |
| 3175 | DCHECK(second.IsDoubleStackSlot()); |
| 3176 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3177 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3178 | break; |
| 3179 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3180 | |
| 3181 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3182 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3183 | } |
| 3184 | } |
| 3185 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3186 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3187 | uint32_t temp_offset, |
| 3188 | uint32_t stack_adjustment, |
| 3189 | bool is_fp, |
| 3190 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3191 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3192 | DCHECK(!is_wide); |
| 3193 | if (is_fp) { |
| 3194 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3195 | } else { |
| 3196 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3197 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3198 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3199 | DCHECK(is_wide); |
| 3200 | if (is_fp) { |
| 3201 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3202 | } else { |
| 3203 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3204 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3205 | } else { |
| 3206 | // 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] | 3207 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3208 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3209 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3210 | if (is_fp) { |
| 3211 | __ flds(Address(ESP, temp_offset)); |
| 3212 | } else { |
| 3213 | __ filds(Address(ESP, temp_offset)); |
| 3214 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3215 | } else { |
| 3216 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3217 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3218 | if (is_fp) { |
| 3219 | __ fldl(Address(ESP, temp_offset)); |
| 3220 | } else { |
| 3221 | __ fildl(Address(ESP, temp_offset)); |
| 3222 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3223 | } |
| 3224 | } |
| 3225 | } |
| 3226 | |
| 3227 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3228 | Primitive::Type type = rem->GetResultType(); |
| 3229 | bool is_float = type == Primitive::kPrimFloat; |
| 3230 | size_t elem_size = Primitive::ComponentSize(type); |
| 3231 | LocationSummary* locations = rem->GetLocations(); |
| 3232 | Location first = locations->InAt(0); |
| 3233 | Location second = locations->InAt(1); |
| 3234 | Location out = locations->Out(); |
| 3235 | |
| 3236 | // Create stack space for 2 elements. |
| 3237 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3238 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3239 | |
| 3240 | // 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] | 3241 | const bool is_wide = !is_float; |
| 3242 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3243 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3244 | |
| 3245 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3246 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3247 | __ Bind(&retry); |
| 3248 | __ fprem(); |
| 3249 | |
| 3250 | // Move FP status to AX. |
| 3251 | __ fstsw(); |
| 3252 | |
| 3253 | // And see if the argument reduction is complete. This is signaled by the |
| 3254 | // C2 FPU flag bit set to 0. |
| 3255 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3256 | __ j(kNotEqual, &retry); |
| 3257 | |
| 3258 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3259 | // Store FP top of stack to real stack. |
| 3260 | if (is_float) { |
| 3261 | __ fsts(Address(ESP, 0)); |
| 3262 | } else { |
| 3263 | __ fstl(Address(ESP, 0)); |
| 3264 | } |
| 3265 | |
| 3266 | // Pop the 2 items from the FP stack. |
| 3267 | __ fucompp(); |
| 3268 | |
| 3269 | // Load the value from the stack into an XMM register. |
| 3270 | DCHECK(out.IsFpuRegister()) << out; |
| 3271 | if (is_float) { |
| 3272 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3273 | } else { |
| 3274 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3275 | } |
| 3276 | |
| 3277 | // And remove the temporary stack space we allocated. |
| 3278 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3279 | } |
| 3280 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3281 | |
| 3282 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3283 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3284 | |
| 3285 | LocationSummary* locations = instruction->GetLocations(); |
| 3286 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3287 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3288 | |
| 3289 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3290 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3291 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3292 | |
| 3293 | DCHECK(imm == 1 || imm == -1); |
| 3294 | |
| 3295 | if (instruction->IsRem()) { |
| 3296 | __ xorl(out_register, out_register); |
| 3297 | } else { |
| 3298 | __ movl(out_register, input_register); |
| 3299 | if (imm == -1) { |
| 3300 | __ negl(out_register); |
| 3301 | } |
| 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3306 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3307 | LocationSummary* locations = instruction->GetLocations(); |
| 3308 | |
| 3309 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3310 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3311 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3312 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3313 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3314 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3315 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3316 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3317 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3318 | __ testl(input_register, input_register); |
| 3319 | __ cmovl(kGreaterEqual, num, input_register); |
| 3320 | int shift = CTZ(imm); |
| 3321 | __ sarl(num, Immediate(shift)); |
| 3322 | |
| 3323 | if (imm < 0) { |
| 3324 | __ negl(num); |
| 3325 | } |
| 3326 | |
| 3327 | __ movl(out_register, num); |
| 3328 | } |
| 3329 | |
| 3330 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3331 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3332 | |
| 3333 | LocationSummary* locations = instruction->GetLocations(); |
| 3334 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3335 | |
| 3336 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3337 | Register out = locations->Out().AsRegister<Register>(); |
| 3338 | Register num; |
| 3339 | Register edx; |
| 3340 | |
| 3341 | if (instruction->IsDiv()) { |
| 3342 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3343 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3344 | } else { |
| 3345 | edx = locations->Out().AsRegister<Register>(); |
| 3346 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3347 | } |
| 3348 | |
| 3349 | DCHECK_EQ(EAX, eax); |
| 3350 | DCHECK_EQ(EDX, edx); |
| 3351 | if (instruction->IsDiv()) { |
| 3352 | DCHECK_EQ(EAX, out); |
| 3353 | } else { |
| 3354 | DCHECK_EQ(EDX, out); |
| 3355 | } |
| 3356 | |
| 3357 | int64_t magic; |
| 3358 | int shift; |
| 3359 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3360 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3361 | // Save the numerator. |
| 3362 | __ movl(num, eax); |
| 3363 | |
| 3364 | // EAX = magic |
| 3365 | __ movl(eax, Immediate(magic)); |
| 3366 | |
| 3367 | // EDX:EAX = magic * numerator |
| 3368 | __ imull(num); |
| 3369 | |
| 3370 | if (imm > 0 && magic < 0) { |
| 3371 | // EDX += num |
| 3372 | __ addl(edx, num); |
| 3373 | } else if (imm < 0 && magic > 0) { |
| 3374 | __ subl(edx, num); |
| 3375 | } |
| 3376 | |
| 3377 | // Shift if needed. |
| 3378 | if (shift != 0) { |
| 3379 | __ sarl(edx, Immediate(shift)); |
| 3380 | } |
| 3381 | |
| 3382 | // EDX += 1 if EDX < 0 |
| 3383 | __ movl(eax, edx); |
| 3384 | __ shrl(edx, Immediate(31)); |
| 3385 | __ addl(edx, eax); |
| 3386 | |
| 3387 | if (instruction->IsRem()) { |
| 3388 | __ movl(eax, num); |
| 3389 | __ imull(edx, Immediate(imm)); |
| 3390 | __ subl(eax, edx); |
| 3391 | __ movl(edx, eax); |
| 3392 | } else { |
| 3393 | __ movl(eax, edx); |
| 3394 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3395 | } |
| 3396 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3397 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3398 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3399 | |
| 3400 | LocationSummary* locations = instruction->GetLocations(); |
| 3401 | Location out = locations->Out(); |
| 3402 | Location first = locations->InAt(0); |
| 3403 | Location second = locations->InAt(1); |
| 3404 | bool is_div = instruction->IsDiv(); |
| 3405 | |
| 3406 | switch (instruction->GetResultType()) { |
| 3407 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3408 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3409 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3410 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3411 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3412 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3413 | |
| 3414 | if (imm == 0) { |
| 3415 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3416 | } else if (imm == 1 || imm == -1) { |
| 3417 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3418 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3419 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3420 | } else { |
| 3421 | DCHECK(imm <= -2 || imm >= 2); |
| 3422 | GenerateDivRemWithAnyConstant(instruction); |
| 3423 | } |
| 3424 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3425 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3426 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3427 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3428 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3429 | Register second_reg = second.AsRegister<Register>(); |
| 3430 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3431 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3432 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3433 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3434 | __ cmpl(second_reg, Immediate(-1)); |
| 3435 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3436 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3437 | // edx:eax <- sign-extended of eax |
| 3438 | __ cdq(); |
| 3439 | // eax = quotient, edx = remainder |
| 3440 | __ idivl(second_reg); |
| 3441 | __ Bind(slow_path->GetExitLabel()); |
| 3442 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3443 | break; |
| 3444 | } |
| 3445 | |
| 3446 | case Primitive::kPrimLong: { |
| 3447 | InvokeRuntimeCallingConvention calling_convention; |
| 3448 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3449 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3450 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3451 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3452 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3453 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3454 | |
| 3455 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3456 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3457 | instruction, |
| 3458 | instruction->GetDexPc(), |
| 3459 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3460 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3461 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3462 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3463 | instruction, |
| 3464 | instruction->GetDexPc(), |
| 3465 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3466 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3467 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3468 | break; |
| 3469 | } |
| 3470 | |
| 3471 | default: |
| 3472 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3473 | } |
| 3474 | } |
| 3475 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3476 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3477 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3478 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3479 | : LocationSummary::kNoCall; |
| 3480 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3481 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3482 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3483 | case Primitive::kPrimInt: { |
| 3484 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3485 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3486 | locations->SetOut(Location::SameAsFirstInput()); |
| 3487 | // Intel uses edx:eax as the dividend. |
| 3488 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3489 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3490 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3491 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3492 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3493 | locations->AddTemp(Location::RequiresRegister()); |
| 3494 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3495 | break; |
| 3496 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3497 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3498 | InvokeRuntimeCallingConvention calling_convention; |
| 3499 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3500 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3501 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3502 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3503 | // Runtime helper puts the result in EAX, EDX. |
| 3504 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3505 | break; |
| 3506 | } |
| 3507 | case Primitive::kPrimFloat: |
| 3508 | case Primitive::kPrimDouble: { |
| 3509 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3510 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3511 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3512 | } else if (div->InputAt(1)->IsConstant()) { |
| 3513 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3514 | } else { |
| 3515 | locations->SetInAt(1, Location::Any()); |
| 3516 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3517 | locations->SetOut(Location::SameAsFirstInput()); |
| 3518 | break; |
| 3519 | } |
| 3520 | |
| 3521 | default: |
| 3522 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3523 | } |
| 3524 | } |
| 3525 | |
| 3526 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3527 | LocationSummary* locations = div->GetLocations(); |
| 3528 | Location first = locations->InAt(0); |
| 3529 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3530 | |
| 3531 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3532 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3533 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3534 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3535 | break; |
| 3536 | } |
| 3537 | |
| 3538 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3539 | if (second.IsFpuRegister()) { |
| 3540 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3541 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3542 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3543 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3544 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3545 | codegen_->LiteralFloatAddress( |
| 3546 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3547 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3548 | } else { |
| 3549 | DCHECK(second.IsStackSlot()); |
| 3550 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3551 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3552 | break; |
| 3553 | } |
| 3554 | |
| 3555 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3556 | if (second.IsFpuRegister()) { |
| 3557 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3558 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3559 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3560 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3561 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3562 | codegen_->LiteralDoubleAddress( |
| 3563 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3564 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3565 | } else { |
| 3566 | DCHECK(second.IsDoubleStackSlot()); |
| 3567 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3568 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3569 | break; |
| 3570 | } |
| 3571 | |
| 3572 | default: |
| 3573 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3574 | } |
| 3575 | } |
| 3576 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3577 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3578 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3579 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3580 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3581 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3582 | : LocationSummary::kNoCall; |
| 3583 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3584 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3585 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3586 | case Primitive::kPrimInt: { |
| 3587 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3588 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3589 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3590 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3591 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3592 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3593 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3594 | locations->AddTemp(Location::RequiresRegister()); |
| 3595 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3596 | break; |
| 3597 | } |
| 3598 | case Primitive::kPrimLong: { |
| 3599 | InvokeRuntimeCallingConvention calling_convention; |
| 3600 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3601 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3602 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3603 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3604 | // Runtime helper puts the result in EAX, EDX. |
| 3605 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3606 | break; |
| 3607 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3608 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3609 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3610 | locations->SetInAt(0, Location::Any()); |
| 3611 | locations->SetInAt(1, Location::Any()); |
| 3612 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3613 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | } |
| 3616 | |
| 3617 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3618 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3619 | } |
| 3620 | } |
| 3621 | |
| 3622 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3623 | Primitive::Type type = rem->GetResultType(); |
| 3624 | switch (type) { |
| 3625 | case Primitive::kPrimInt: |
| 3626 | case Primitive::kPrimLong: { |
| 3627 | GenerateDivRemIntegral(rem); |
| 3628 | break; |
| 3629 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3630 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3631 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3632 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3633 | break; |
| 3634 | } |
| 3635 | default: |
| 3636 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3637 | } |
| 3638 | } |
| 3639 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3640 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3641 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3642 | ? LocationSummary::kCallOnSlowPath |
| 3643 | : LocationSummary::kNoCall; |
| 3644 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3645 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3646 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3647 | case Primitive::kPrimByte: |
| 3648 | case Primitive::kPrimChar: |
| 3649 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3650 | case Primitive::kPrimInt: { |
| 3651 | locations->SetInAt(0, Location::Any()); |
| 3652 | break; |
| 3653 | } |
| 3654 | case Primitive::kPrimLong: { |
| 3655 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3656 | if (!instruction->IsConstant()) { |
| 3657 | locations->AddTemp(Location::RequiresRegister()); |
| 3658 | } |
| 3659 | break; |
| 3660 | } |
| 3661 | default: |
| 3662 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3663 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3664 | if (instruction->HasUses()) { |
| 3665 | locations->SetOut(Location::SameAsFirstInput()); |
| 3666 | } |
| 3667 | } |
| 3668 | |
| 3669 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3670 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3671 | codegen_->AddSlowPath(slow_path); |
| 3672 | |
| 3673 | LocationSummary* locations = instruction->GetLocations(); |
| 3674 | Location value = locations->InAt(0); |
| 3675 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3676 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3677 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3678 | case Primitive::kPrimByte: |
| 3679 | case Primitive::kPrimChar: |
| 3680 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3681 | case Primitive::kPrimInt: { |
| 3682 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3683 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3684 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3685 | } else if (value.IsStackSlot()) { |
| 3686 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3687 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3688 | } else { |
| 3689 | DCHECK(value.IsConstant()) << value; |
| 3690 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3691 | __ jmp(slow_path->GetEntryLabel()); |
| 3692 | } |
| 3693 | } |
| 3694 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3695 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3696 | case Primitive::kPrimLong: { |
| 3697 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3698 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3699 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3700 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3701 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3702 | } else { |
| 3703 | DCHECK(value.IsConstant()) << value; |
| 3704 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3705 | __ jmp(slow_path->GetEntryLabel()); |
| 3706 | } |
| 3707 | } |
| 3708 | break; |
| 3709 | } |
| 3710 | default: |
| 3711 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3712 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3713 | } |
| 3714 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3715 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3716 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3717 | |
| 3718 | LocationSummary* locations = |
| 3719 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3720 | |
| 3721 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3722 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3723 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3724 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3725 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3726 | // The shift count needs to be in CL or a constant. |
| 3727 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3728 | locations->SetOut(Location::SameAsFirstInput()); |
| 3729 | break; |
| 3730 | } |
| 3731 | default: |
| 3732 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3733 | } |
| 3734 | } |
| 3735 | |
| 3736 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3737 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3738 | |
| 3739 | LocationSummary* locations = op->GetLocations(); |
| 3740 | Location first = locations->InAt(0); |
| 3741 | Location second = locations->InAt(1); |
| 3742 | DCHECK(first.Equals(locations->Out())); |
| 3743 | |
| 3744 | switch (op->GetResultType()) { |
| 3745 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3746 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3747 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3748 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3749 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3750 | DCHECK_EQ(ECX, second_reg); |
| 3751 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3752 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3753 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3754 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3755 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3756 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3757 | } |
| 3758 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3759 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3760 | if (shift == 0) { |
| 3761 | return; |
| 3762 | } |
| 3763 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3764 | if (op->IsShl()) { |
| 3765 | __ shll(first_reg, imm); |
| 3766 | } else if (op->IsShr()) { |
| 3767 | __ sarl(first_reg, imm); |
| 3768 | } else { |
| 3769 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3770 | } |
| 3771 | } |
| 3772 | break; |
| 3773 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3774 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3775 | if (second.IsRegister()) { |
| 3776 | Register second_reg = second.AsRegister<Register>(); |
| 3777 | DCHECK_EQ(ECX, second_reg); |
| 3778 | if (op->IsShl()) { |
| 3779 | GenerateShlLong(first, second_reg); |
| 3780 | } else if (op->IsShr()) { |
| 3781 | GenerateShrLong(first, second_reg); |
| 3782 | } else { |
| 3783 | GenerateUShrLong(first, second_reg); |
| 3784 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3785 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3786 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3787 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3788 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3789 | if (shift != 0) { |
| 3790 | if (op->IsShl()) { |
| 3791 | GenerateShlLong(first, shift); |
| 3792 | } else if (op->IsShr()) { |
| 3793 | GenerateShrLong(first, shift); |
| 3794 | } else { |
| 3795 | GenerateUShrLong(first, shift); |
| 3796 | } |
| 3797 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3798 | } |
| 3799 | break; |
| 3800 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3801 | default: |
| 3802 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3803 | } |
| 3804 | } |
| 3805 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3806 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3807 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3808 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3809 | if (shift == 1) { |
| 3810 | // This is just an addition. |
| 3811 | __ addl(low, low); |
| 3812 | __ adcl(high, high); |
| 3813 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3814 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3815 | codegen_->EmitParallelMoves( |
| 3816 | loc.ToLow(), |
| 3817 | loc.ToHigh(), |
| 3818 | Primitive::kPrimInt, |
| 3819 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3820 | loc.ToLow(), |
| 3821 | Primitive::kPrimInt); |
| 3822 | } else if (shift > 32) { |
| 3823 | // Low part becomes 0. High part is low part << (shift-32). |
| 3824 | __ movl(high, low); |
| 3825 | __ shll(high, Immediate(shift - 32)); |
| 3826 | __ xorl(low, low); |
| 3827 | } else { |
| 3828 | // Between 1 and 31. |
| 3829 | __ shld(high, low, Immediate(shift)); |
| 3830 | __ shll(low, Immediate(shift)); |
| 3831 | } |
| 3832 | } |
| 3833 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3834 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3835 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3836 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3837 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3838 | __ testl(shifter, Immediate(32)); |
| 3839 | __ j(kEqual, &done); |
| 3840 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3841 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3842 | __ Bind(&done); |
| 3843 | } |
| 3844 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3845 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3846 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3847 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3848 | if (shift == 32) { |
| 3849 | // Need to copy the sign. |
| 3850 | DCHECK_NE(low, high); |
| 3851 | __ movl(low, high); |
| 3852 | __ sarl(high, Immediate(31)); |
| 3853 | } else if (shift > 32) { |
| 3854 | DCHECK_NE(low, high); |
| 3855 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3856 | __ movl(low, high); |
| 3857 | __ sarl(high, Immediate(31)); |
| 3858 | __ sarl(low, Immediate(shift - 32)); |
| 3859 | } else { |
| 3860 | // Between 1 and 31. |
| 3861 | __ shrd(low, high, Immediate(shift)); |
| 3862 | __ sarl(high, Immediate(shift)); |
| 3863 | } |
| 3864 | } |
| 3865 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3866 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3867 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3868 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3869 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3870 | __ testl(shifter, Immediate(32)); |
| 3871 | __ j(kEqual, &done); |
| 3872 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3873 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3874 | __ Bind(&done); |
| 3875 | } |
| 3876 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3877 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3878 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3879 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3880 | if (shift == 32) { |
| 3881 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3882 | codegen_->EmitParallelMoves( |
| 3883 | loc.ToHigh(), |
| 3884 | loc.ToLow(), |
| 3885 | Primitive::kPrimInt, |
| 3886 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3887 | loc.ToHigh(), |
| 3888 | Primitive::kPrimInt); |
| 3889 | } else if (shift > 32) { |
| 3890 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3891 | __ movl(low, high); |
| 3892 | __ shrl(low, Immediate(shift - 32)); |
| 3893 | __ xorl(high, high); |
| 3894 | } else { |
| 3895 | // Between 1 and 31. |
| 3896 | __ shrd(low, high, Immediate(shift)); |
| 3897 | __ shrl(high, Immediate(shift)); |
| 3898 | } |
| 3899 | } |
| 3900 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3901 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3902 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3903 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3904 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3905 | __ testl(shifter, Immediate(32)); |
| 3906 | __ j(kEqual, &done); |
| 3907 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3908 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3909 | __ Bind(&done); |
| 3910 | } |
| 3911 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3912 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3913 | LocationSummary* locations = |
| 3914 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3915 | |
| 3916 | switch (ror->GetResultType()) { |
| 3917 | case Primitive::kPrimLong: |
| 3918 | // Add the temporary needed. |
| 3919 | locations->AddTemp(Location::RequiresRegister()); |
| 3920 | FALLTHROUGH_INTENDED; |
| 3921 | case Primitive::kPrimInt: |
| 3922 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3923 | // The shift count needs to be in CL (unless it is a constant). |
| 3924 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3925 | locations->SetOut(Location::SameAsFirstInput()); |
| 3926 | break; |
| 3927 | default: |
| 3928 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3929 | UNREACHABLE(); |
| 3930 | } |
| 3931 | } |
| 3932 | |
| 3933 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3934 | LocationSummary* locations = ror->GetLocations(); |
| 3935 | Location first = locations->InAt(0); |
| 3936 | Location second = locations->InAt(1); |
| 3937 | |
| 3938 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3939 | Register first_reg = first.AsRegister<Register>(); |
| 3940 | if (second.IsRegister()) { |
| 3941 | Register second_reg = second.AsRegister<Register>(); |
| 3942 | __ rorl(first_reg, second_reg); |
| 3943 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3944 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3945 | __ rorl(first_reg, imm); |
| 3946 | } |
| 3947 | return; |
| 3948 | } |
| 3949 | |
| 3950 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3951 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3952 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3953 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3954 | if (second.IsRegister()) { |
| 3955 | Register second_reg = second.AsRegister<Register>(); |
| 3956 | DCHECK_EQ(second_reg, ECX); |
| 3957 | __ movl(temp_reg, first_reg_hi); |
| 3958 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3959 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3960 | __ movl(temp_reg, first_reg_hi); |
| 3961 | __ testl(second_reg, Immediate(32)); |
| 3962 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3963 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3964 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3965 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3966 | if (shift_amt == 0) { |
| 3967 | // Already fine. |
| 3968 | return; |
| 3969 | } |
| 3970 | if (shift_amt == 32) { |
| 3971 | // Just swap. |
| 3972 | __ movl(temp_reg, first_reg_lo); |
| 3973 | __ movl(first_reg_lo, first_reg_hi); |
| 3974 | __ movl(first_reg_hi, temp_reg); |
| 3975 | return; |
| 3976 | } |
| 3977 | |
| 3978 | Immediate imm(shift_amt); |
| 3979 | // Save the constents of the low value. |
| 3980 | __ movl(temp_reg, first_reg_lo); |
| 3981 | |
| 3982 | // Shift right into low, feeding bits from high. |
| 3983 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3984 | |
| 3985 | // Shift right into high, feeding bits from the original low. |
| 3986 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3987 | |
| 3988 | // Swap if needed. |
| 3989 | if (shift_amt > 32) { |
| 3990 | __ movl(temp_reg, first_reg_lo); |
| 3991 | __ movl(first_reg_lo, first_reg_hi); |
| 3992 | __ movl(first_reg_hi, temp_reg); |
| 3993 | } |
| 3994 | } |
| 3995 | } |
| 3996 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3997 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3998 | HandleShift(shl); |
| 3999 | } |
| 4000 | |
| 4001 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4002 | HandleShift(shl); |
| 4003 | } |
| 4004 | |
| 4005 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4006 | HandleShift(shr); |
| 4007 | } |
| 4008 | |
| 4009 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4010 | HandleShift(shr); |
| 4011 | } |
| 4012 | |
| 4013 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4014 | HandleShift(ushr); |
| 4015 | } |
| 4016 | |
| 4017 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4018 | HandleShift(ushr); |
| 4019 | } |
| 4020 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4021 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4022 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4023 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4024 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4025 | if (instruction->IsStringAlloc()) { |
| 4026 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4027 | } else { |
| 4028 | InvokeRuntimeCallingConvention calling_convention; |
| 4029 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4030 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4031 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4035 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4036 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4037 | if (instruction->IsStringAlloc()) { |
| 4038 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4039 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 4040 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 4041 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4042 | __ call(Address(temp, code_offset.Int32Value())); |
| 4043 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4044 | } else { |
| 4045 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4046 | instruction, |
| 4047 | instruction->GetDexPc(), |
| 4048 | nullptr); |
| 4049 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4050 | DCHECK(!codegen_->IsLeafMethod()); |
| 4051 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4052 | } |
| 4053 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4054 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4055 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4056 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4057 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4058 | InvokeRuntimeCallingConvention calling_convention; |
| 4059 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4060 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4061 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4065 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4066 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4067 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4068 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4069 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4070 | instruction, |
| 4071 | instruction->GetDexPc(), |
| 4072 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4073 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4074 | DCHECK(!codegen_->IsLeafMethod()); |
| 4075 | } |
| 4076 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4077 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4078 | LocationSummary* locations = |
| 4079 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4080 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4081 | if (location.IsStackSlot()) { |
| 4082 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4083 | } else if (location.IsDoubleStackSlot()) { |
| 4084 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4085 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4086 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4087 | } |
| 4088 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4089 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4090 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4091 | } |
| 4092 | |
| 4093 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4094 | LocationSummary* locations = |
| 4095 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4096 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4097 | } |
| 4098 | |
| 4099 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4100 | } |
| 4101 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4102 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4103 | LocationSummary* locations = |
| 4104 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4105 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4106 | locations->SetOut(Location::RequiresRegister()); |
| 4107 | } |
| 4108 | |
| 4109 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4110 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4111 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4112 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4113 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4114 | __ movl(locations->Out().AsRegister<Register>(), |
| 4115 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4116 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4117 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4118 | instruction->GetIndex() % ImTable::kSize, kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4119 | __ movl(locations->Out().AsRegister<Register>(), |
| 4120 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4121 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4122 | // temp = temp->GetImtEntryAt(method_offset); |
| 4123 | __ movl(locations->Out().AsRegister<Register>(), |
| 4124 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4125 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4126 | } |
| 4127 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4128 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4129 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4130 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4131 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4132 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4133 | } |
| 4134 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4135 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4136 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4137 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4138 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4139 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4140 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4141 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4142 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4143 | break; |
| 4144 | |
| 4145 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4146 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4147 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4148 | break; |
| 4149 | |
| 4150 | default: |
| 4151 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4152 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4153 | } |
| 4154 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4155 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4156 | LocationSummary* locations = |
| 4157 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4158 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4159 | locations->SetOut(Location::SameAsFirstInput()); |
| 4160 | } |
| 4161 | |
| 4162 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4163 | LocationSummary* locations = bool_not->GetLocations(); |
| 4164 | Location in = locations->InAt(0); |
| 4165 | Location out = locations->Out(); |
| 4166 | DCHECK(in.Equals(out)); |
| 4167 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4168 | } |
| 4169 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4170 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4171 | LocationSummary* locations = |
| 4172 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4173 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4174 | case Primitive::kPrimBoolean: |
| 4175 | case Primitive::kPrimByte: |
| 4176 | case Primitive::kPrimShort: |
| 4177 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4178 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4179 | case Primitive::kPrimLong: { |
| 4180 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4181 | locations->SetInAt(1, Location::Any()); |
| 4182 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4183 | break; |
| 4184 | } |
| 4185 | case Primitive::kPrimFloat: |
| 4186 | case Primitive::kPrimDouble: { |
| 4187 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4188 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4189 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4190 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4191 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4192 | } else { |
| 4193 | locations->SetInAt(1, Location::Any()); |
| 4194 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4195 | locations->SetOut(Location::RequiresRegister()); |
| 4196 | break; |
| 4197 | } |
| 4198 | default: |
| 4199 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4200 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4204 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4205 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4206 | Location left = locations->InAt(0); |
| 4207 | Location right = locations->InAt(1); |
| 4208 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4209 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4210 | Condition less_cond = kLess; |
| 4211 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4212 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4213 | case Primitive::kPrimBoolean: |
| 4214 | case Primitive::kPrimByte: |
| 4215 | case Primitive::kPrimShort: |
| 4216 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4217 | case Primitive::kPrimInt: { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 4218 | GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4219 | break; |
| 4220 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4221 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4222 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4223 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4224 | int32_t val_low = 0; |
| 4225 | int32_t val_high = 0; |
| 4226 | bool right_is_const = false; |
| 4227 | |
| 4228 | if (right.IsConstant()) { |
| 4229 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4230 | right_is_const = true; |
| 4231 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4232 | val_low = Low32Bits(val); |
| 4233 | val_high = High32Bits(val); |
| 4234 | } |
| 4235 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4236 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4237 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4238 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4239 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4240 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4241 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4242 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4243 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4244 | __ j(kLess, &less); // Signed compare. |
| 4245 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4246 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4247 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4248 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4249 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4250 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4251 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4252 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4253 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4254 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4255 | break; |
| 4256 | } |
| 4257 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4258 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4259 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4260 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4261 | break; |
| 4262 | } |
| 4263 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4264 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4265 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4266 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4267 | break; |
| 4268 | } |
| 4269 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4270 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4271 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4272 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4273 | __ movl(out, Immediate(0)); |
| 4274 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4275 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4276 | |
| 4277 | __ Bind(&greater); |
| 4278 | __ movl(out, Immediate(1)); |
| 4279 | __ jmp(&done); |
| 4280 | |
| 4281 | __ Bind(&less); |
| 4282 | __ movl(out, Immediate(-1)); |
| 4283 | |
| 4284 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4285 | } |
| 4286 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4287 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4288 | LocationSummary* locations = |
| 4289 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4290 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4291 | locations->SetInAt(i, Location::Any()); |
| 4292 | } |
| 4293 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4294 | } |
| 4295 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4296 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4297 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4298 | } |
| 4299 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4300 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4301 | /* |
| 4302 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4303 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4304 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4305 | */ |
| 4306 | switch (kind) { |
| 4307 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4308 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4309 | break; |
| 4310 | } |
| 4311 | case MemBarrierKind::kAnyStore: |
| 4312 | case MemBarrierKind::kLoadAny: |
| 4313 | case MemBarrierKind::kStoreStore: { |
| 4314 | // nop |
| 4315 | break; |
| 4316 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4317 | case MemBarrierKind::kNTStoreStore: |
| 4318 | // Non-Temporal Store/Store needs an explicit fence. |
| 4319 | MemoryFence(/* non-temporal */ true); |
| 4320 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4321 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4322 | } |
| 4323 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4324 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4325 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4326 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4327 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4328 | |
| 4329 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4330 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4331 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4332 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4333 | if (GetGraph()->HasIrreducibleLoops() && |
| 4334 | (dispatch_info.method_load_kind == |
| 4335 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4336 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4337 | } |
| 4338 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4339 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4340 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4341 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4342 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4343 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4344 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4345 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4346 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4347 | 0u |
| 4348 | }; |
| 4349 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4350 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4351 | } |
| 4352 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4353 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4354 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4355 | Register temp) { |
| 4356 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4357 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4358 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4359 | return location.AsRegister<Register>(); |
| 4360 | } |
| 4361 | // For intrinsics we allow any location, so it may be on the stack. |
| 4362 | if (!location.IsRegister()) { |
| 4363 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4364 | return temp; |
| 4365 | } |
| 4366 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4367 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4368 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4369 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4370 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4371 | if (slow_path != nullptr) { |
| 4372 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4373 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4374 | __ movl(temp, Address(ESP, stack_offset)); |
| 4375 | return temp; |
| 4376 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4377 | } |
| 4378 | return location.AsRegister<Register>(); |
| 4379 | } |
| 4380 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4381 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4382 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4383 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4384 | switch (invoke->GetMethodLoadKind()) { |
| 4385 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4386 | // temp = thread->string_init_entrypoint |
| 4387 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4388 | break; |
| 4389 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4390 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4391 | break; |
| 4392 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4393 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4394 | break; |
| 4395 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4396 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4397 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4398 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4399 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4400 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4401 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4402 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4403 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4404 | // Bind a new fixup label at the end of the "movl" insn. |
| 4405 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4406 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4407 | break; |
| 4408 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4409 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4410 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4411 | Register method_reg; |
| 4412 | Register reg = temp.AsRegister<Register>(); |
| 4413 | if (current_method.IsRegister()) { |
| 4414 | method_reg = current_method.AsRegister<Register>(); |
| 4415 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4416 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4417 | DCHECK(!current_method.IsValid()); |
| 4418 | method_reg = reg; |
| 4419 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4420 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4421 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4422 | __ movl(reg, Address(method_reg, |
| 4423 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4424 | // temp = temp[index_in_cache]; |
| 4425 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4426 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4427 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4428 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4429 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4430 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4431 | return callee_method; |
| 4432 | } |
| 4433 | |
| 4434 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4435 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4436 | |
| 4437 | switch (invoke->GetCodePtrLocation()) { |
| 4438 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4439 | __ call(GetFrameEntryLabel()); |
| 4440 | break; |
| 4441 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4442 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4443 | Label* label = &relative_call_patches_.back().label; |
| 4444 | __ call(label); // Bind to the patch label, override at link time. |
| 4445 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4446 | break; |
| 4447 | } |
| 4448 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4449 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4450 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4451 | LOG(FATAL) << "Unsupported"; |
| 4452 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4453 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4454 | // (callee_method + offset_of_quick_compiled_code)() |
| 4455 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4456 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4457 | kX86WordSize).Int32Value())); |
| 4458 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4459 | } |
| 4460 | |
| 4461 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4462 | } |
| 4463 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4464 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4465 | Register temp = temp_in.AsRegister<Register>(); |
| 4466 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4467 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4468 | |
| 4469 | // Use the calling convention instead of the location of the receiver, as |
| 4470 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4471 | // slow path, the arguments have been moved to the right place, so here we are |
| 4472 | // guaranteed that the receiver is the first register of the calling convention. |
| 4473 | InvokeDexCallingConvention calling_convention; |
| 4474 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4475 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4476 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4477 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4478 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4479 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4480 | // emit a read barrier for the previous class reference load. |
| 4481 | // However this is not required in practice, as this is an |
| 4482 | // intermediate/temporary reference and because the current |
| 4483 | // concurrent copying collector keeps the from-space memory |
| 4484 | // intact/accessible until the end of the marking phase (the |
| 4485 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4486 | __ MaybeUnpoisonHeapReference(temp); |
| 4487 | // temp = temp->GetMethodAt(method_offset); |
| 4488 | __ movl(temp, Address(temp, method_offset)); |
| 4489 | // call temp->GetEntryPoint(); |
| 4490 | __ call(Address( |
| 4491 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4492 | } |
| 4493 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4494 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4495 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4496 | simple_patches_.emplace_back(); |
| 4497 | __ Bind(&simple_patches_.back()); |
| 4498 | } |
| 4499 | } |
| 4500 | |
| 4501 | void CodeGeneratorX86::RecordStringPatch(HLoadString* load_string) { |
| 4502 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4503 | __ Bind(&string_patches_.back().label); |
| 4504 | } |
| 4505 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4506 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
| 4507 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 4508 | __ Bind(&type_patches_.back().label); |
| 4509 | } |
| 4510 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4511 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4512 | uint32_t element_offset) { |
| 4513 | // Add the patch entry and bind its label at the end of the instruction. |
| 4514 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4515 | return &pc_relative_dex_cache_patches_.back().label; |
| 4516 | } |
| 4517 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4518 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4519 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4520 | size_t size = |
| 4521 | method_patches_.size() + |
| 4522 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4523 | pc_relative_dex_cache_patches_.size() + |
| 4524 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4525 | string_patches_.size() + |
| 4526 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4527 | linker_patches->reserve(size); |
| 4528 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4529 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4530 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4531 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4532 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4533 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4534 | info.target_method.dex_file, |
| 4535 | info.target_method.dex_method_index)); |
| 4536 | } |
| 4537 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4538 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4540 | info.target_method.dex_file, |
| 4541 | info.target_method.dex_method_index)); |
| 4542 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4543 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4544 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4545 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4546 | &info.target_dex_file, |
| 4547 | GetMethodAddressOffset(), |
| 4548 | info.element_offset)); |
| 4549 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4550 | for (const Label& label : simple_patches_) { |
| 4551 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4552 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4553 | } |
| 4554 | if (GetCompilerOptions().GetCompilePic()) { |
| 4555 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4556 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4557 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 4558 | &info.dex_file, |
| 4559 | GetMethodAddressOffset(), |
| 4560 | info.string_index)); |
| 4561 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4562 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4563 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4564 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(literal_offset, |
| 4565 | &info.dex_file, |
| 4566 | GetMethodAddressOffset(), |
| 4567 | info.type_index)); |
| 4568 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4569 | } else { |
| 4570 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4571 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4572 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 4573 | &info.dex_file, |
| 4574 | info.string_index)); |
| 4575 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4576 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4577 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4578 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 4579 | &info.dex_file, |
| 4580 | info.type_index)); |
| 4581 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4582 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4583 | } |
| 4584 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4585 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4586 | Register card, |
| 4587 | Register object, |
| 4588 | Register value, |
| 4589 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4590 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4591 | if (value_can_be_null) { |
| 4592 | __ testl(value, value); |
| 4593 | __ j(kEqual, &is_null); |
| 4594 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4595 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4596 | __ movl(temp, object); |
| 4597 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4598 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4599 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4600 | if (value_can_be_null) { |
| 4601 | __ Bind(&is_null); |
| 4602 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4603 | } |
| 4604 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4605 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4606 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4607 | |
| 4608 | bool object_field_get_with_read_barrier = |
| 4609 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4610 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4611 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4612 | kEmitCompilerReadBarrier ? |
| 4613 | LocationSummary::kCallOnSlowPath : |
| 4614 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4615 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4616 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4617 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4618 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4619 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4620 | // The output overlaps in case of long: we don't want the low move |
| 4621 | // to overwrite the object's location. Likewise, in the case of |
| 4622 | // an object field get with read barriers enabled, we do not want |
| 4623 | // the move to overwrite the object's location, as we need it to emit |
| 4624 | // the read barrier. |
| 4625 | locations->SetOut( |
| 4626 | Location::RequiresRegister(), |
| 4627 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4628 | Location::kOutputOverlap : |
| 4629 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4630 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4631 | |
| 4632 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4633 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4634 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4635 | // load the temp into the XMM and then copy the XMM into the |
| 4636 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4637 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4638 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4639 | // We need a temporary register for the read barrier marking slow |
| 4640 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4641 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4642 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4643 | } |
| 4644 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4645 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4646 | const FieldInfo& field_info) { |
| 4647 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4648 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4649 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4650 | Location base_loc = locations->InAt(0); |
| 4651 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4652 | Location out = locations->Out(); |
| 4653 | bool is_volatile = field_info.IsVolatile(); |
| 4654 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4655 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4656 | |
| 4657 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4658 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4659 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4660 | break; |
| 4661 | } |
| 4662 | |
| 4663 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4664 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4665 | break; |
| 4666 | } |
| 4667 | |
| 4668 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4669 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4670 | break; |
| 4671 | } |
| 4672 | |
| 4673 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4674 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4675 | break; |
| 4676 | } |
| 4677 | |
| 4678 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4679 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4680 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4681 | |
| 4682 | case Primitive::kPrimNot: { |
| 4683 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4684 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4685 | Location temp_loc = locations->GetTemp(0); |
| 4686 | // Note that a potential implicit null check is handled in this |
| 4687 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4688 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4689 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4690 | if (is_volatile) { |
| 4691 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4692 | } |
| 4693 | } else { |
| 4694 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4695 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4696 | if (is_volatile) { |
| 4697 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4698 | } |
| 4699 | // If read barriers are enabled, emit read barriers other than |
| 4700 | // Baker's using a slow path (and also unpoison the loaded |
| 4701 | // reference, if heap poisoning is enabled). |
| 4702 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4703 | } |
| 4704 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4705 | } |
| 4706 | |
| 4707 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4708 | if (is_volatile) { |
| 4709 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4710 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4711 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4712 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4713 | __ psrlq(temp, Immediate(32)); |
| 4714 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4715 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4716 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4717 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4718 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4719 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4720 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4721 | break; |
| 4722 | } |
| 4723 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4724 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4725 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4726 | break; |
| 4727 | } |
| 4728 | |
| 4729 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4730 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4731 | break; |
| 4732 | } |
| 4733 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4734 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4735 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4736 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4737 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4738 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4739 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4740 | // Potential implicit null checks, in the case of reference or |
| 4741 | // long fields, are handled in the previous switch statement. |
| 4742 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4743 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4744 | } |
| 4745 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4746 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4747 | if (field_type == Primitive::kPrimNot) { |
| 4748 | // Memory barriers, in the case of references, are also handled |
| 4749 | // in the previous switch statement. |
| 4750 | } else { |
| 4751 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4752 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4753 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4754 | } |
| 4755 | |
| 4756 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4757 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4758 | |
| 4759 | LocationSummary* locations = |
| 4760 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4761 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4762 | bool is_volatile = field_info.IsVolatile(); |
| 4763 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4764 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4765 | || (field_type == Primitive::kPrimByte); |
| 4766 | |
| 4767 | // The register allocator does not support multiple |
| 4768 | // inputs that die at entry with one in a specific register. |
| 4769 | if (is_byte_type) { |
| 4770 | // Ensure the value is in a byte register. |
| 4771 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4772 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4773 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4774 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4775 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4776 | } else { |
| 4777 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4778 | } |
| 4779 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4780 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4781 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4782 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4783 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4784 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4785 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4786 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4787 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4788 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4789 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4790 | } else { |
| 4791 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4792 | |
| 4793 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4794 | // Temporary registers for the write barrier. |
| 4795 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4796 | // Ensure the card is in a byte register. |
| 4797 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4798 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4799 | } |
| 4800 | } |
| 4801 | |
| 4802 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4803 | const FieldInfo& field_info, |
| 4804 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4805 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4806 | |
| 4807 | LocationSummary* locations = instruction->GetLocations(); |
| 4808 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4809 | Location value = locations->InAt(1); |
| 4810 | bool is_volatile = field_info.IsVolatile(); |
| 4811 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4812 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4813 | bool needs_write_barrier = |
| 4814 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4815 | |
| 4816 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4817 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4818 | } |
| 4819 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4820 | bool maybe_record_implicit_null_check_done = false; |
| 4821 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4822 | switch (field_type) { |
| 4823 | case Primitive::kPrimBoolean: |
| 4824 | case Primitive::kPrimByte: { |
| 4825 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4826 | break; |
| 4827 | } |
| 4828 | |
| 4829 | case Primitive::kPrimShort: |
| 4830 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4831 | if (value.IsConstant()) { |
| 4832 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4833 | __ movw(Address(base, offset), Immediate(v)); |
| 4834 | } else { |
| 4835 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4836 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4837 | break; |
| 4838 | } |
| 4839 | |
| 4840 | case Primitive::kPrimInt: |
| 4841 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4842 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4843 | // Note that in the case where `value` is a null reference, |
| 4844 | // we do not enter this block, as the reference does not |
| 4845 | // need poisoning. |
| 4846 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4847 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4848 | __ movl(temp, value.AsRegister<Register>()); |
| 4849 | __ PoisonHeapReference(temp); |
| 4850 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4851 | } else if (value.IsConstant()) { |
| 4852 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4853 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4854 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4855 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4856 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4857 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4858 | break; |
| 4859 | } |
| 4860 | |
| 4861 | case Primitive::kPrimLong: { |
| 4862 | if (is_volatile) { |
| 4863 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4864 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4865 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4866 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4867 | __ punpckldq(temp1, temp2); |
| 4868 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4869 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4870 | } else if (value.IsConstant()) { |
| 4871 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4872 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4873 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4874 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4875 | } else { |
| 4876 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4877 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4878 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4879 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4880 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4881 | break; |
| 4882 | } |
| 4883 | |
| 4884 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4885 | if (value.IsConstant()) { |
| 4886 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4887 | __ movl(Address(base, offset), Immediate(v)); |
| 4888 | } else { |
| 4889 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4890 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4891 | break; |
| 4892 | } |
| 4893 | |
| 4894 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4895 | if (value.IsConstant()) { |
| 4896 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4897 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4898 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4899 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4900 | maybe_record_implicit_null_check_done = true; |
| 4901 | } else { |
| 4902 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4903 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4904 | break; |
| 4905 | } |
| 4906 | |
| 4907 | case Primitive::kPrimVoid: |
| 4908 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4909 | UNREACHABLE(); |
| 4910 | } |
| 4911 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4912 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4913 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4914 | } |
| 4915 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4916 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4917 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4918 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4919 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4920 | } |
| 4921 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4922 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4923 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4924 | } |
| 4925 | } |
| 4926 | |
| 4927 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4928 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4929 | } |
| 4930 | |
| 4931 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4932 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4933 | } |
| 4934 | |
| 4935 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4936 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4937 | } |
| 4938 | |
| 4939 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4940 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4941 | } |
| 4942 | |
| 4943 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4944 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4945 | } |
| 4946 | |
| 4947 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4948 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4952 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4953 | } |
| 4954 | |
| 4955 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4956 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4957 | } |
| 4958 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4959 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4960 | HUnresolvedInstanceFieldGet* instruction) { |
| 4961 | FieldAccessCallingConventionX86 calling_convention; |
| 4962 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4963 | instruction, instruction->GetFieldType(), calling_convention); |
| 4964 | } |
| 4965 | |
| 4966 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4967 | HUnresolvedInstanceFieldGet* instruction) { |
| 4968 | FieldAccessCallingConventionX86 calling_convention; |
| 4969 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4970 | instruction->GetFieldType(), |
| 4971 | instruction->GetFieldIndex(), |
| 4972 | instruction->GetDexPc(), |
| 4973 | calling_convention); |
| 4974 | } |
| 4975 | |
| 4976 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4977 | HUnresolvedInstanceFieldSet* instruction) { |
| 4978 | FieldAccessCallingConventionX86 calling_convention; |
| 4979 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4980 | instruction, instruction->GetFieldType(), calling_convention); |
| 4981 | } |
| 4982 | |
| 4983 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4984 | HUnresolvedInstanceFieldSet* instruction) { |
| 4985 | FieldAccessCallingConventionX86 calling_convention; |
| 4986 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4987 | instruction->GetFieldType(), |
| 4988 | instruction->GetFieldIndex(), |
| 4989 | instruction->GetDexPc(), |
| 4990 | calling_convention); |
| 4991 | } |
| 4992 | |
| 4993 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4994 | HUnresolvedStaticFieldGet* instruction) { |
| 4995 | FieldAccessCallingConventionX86 calling_convention; |
| 4996 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4997 | instruction, instruction->GetFieldType(), calling_convention); |
| 4998 | } |
| 4999 | |
| 5000 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5001 | HUnresolvedStaticFieldGet* instruction) { |
| 5002 | FieldAccessCallingConventionX86 calling_convention; |
| 5003 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5004 | instruction->GetFieldType(), |
| 5005 | instruction->GetFieldIndex(), |
| 5006 | instruction->GetDexPc(), |
| 5007 | calling_convention); |
| 5008 | } |
| 5009 | |
| 5010 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5011 | HUnresolvedStaticFieldSet* instruction) { |
| 5012 | FieldAccessCallingConventionX86 calling_convention; |
| 5013 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5014 | instruction, instruction->GetFieldType(), calling_convention); |
| 5015 | } |
| 5016 | |
| 5017 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5018 | HUnresolvedStaticFieldSet* instruction) { |
| 5019 | FieldAccessCallingConventionX86 calling_convention; |
| 5020 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5021 | instruction->GetFieldType(), |
| 5022 | instruction->GetFieldIndex(), |
| 5023 | instruction->GetDexPc(), |
| 5024 | calling_convention); |
| 5025 | } |
| 5026 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5027 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5028 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5029 | ? LocationSummary::kCallOnSlowPath |
| 5030 | : LocationSummary::kNoCall; |
| 5031 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5032 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5033 | ? Location::RequiresRegister() |
| 5034 | : Location::Any(); |
| 5035 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5036 | if (instruction->HasUses()) { |
| 5037 | locations->SetOut(Location::SameAsFirstInput()); |
| 5038 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5039 | } |
| 5040 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5041 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5042 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5043 | return; |
| 5044 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5045 | LocationSummary* locations = instruction->GetLocations(); |
| 5046 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5047 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5048 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5049 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5050 | } |
| 5051 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5052 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5053 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5054 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5055 | |
| 5056 | LocationSummary* locations = instruction->GetLocations(); |
| 5057 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5058 | |
| 5059 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5060 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5061 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5062 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5063 | } else { |
| 5064 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5065 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5066 | __ jmp(slow_path->GetEntryLabel()); |
| 5067 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5068 | } |
| 5069 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5070 | } |
| 5071 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5072 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5073 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5074 | } |
| 5075 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5076 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5077 | bool object_array_get_with_read_barrier = |
| 5078 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5079 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5080 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5081 | object_array_get_with_read_barrier ? |
| 5082 | LocationSummary::kCallOnSlowPath : |
| 5083 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5084 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5085 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5086 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5087 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5088 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5089 | // The output overlaps in case of long: we don't want the low move |
| 5090 | // to overwrite the array's location. Likewise, in the case of an |
| 5091 | // object array get with read barriers enabled, we do not want the |
| 5092 | // move to overwrite the array's location, as we need it to emit |
| 5093 | // the read barrier. |
| 5094 | locations->SetOut( |
| 5095 | Location::RequiresRegister(), |
| 5096 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5097 | Location::kOutputOverlap : |
| 5098 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5099 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5100 | // We need a temporary register for the read barrier marking slow |
| 5101 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 5102 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5103 | locations->AddTemp(Location::RequiresRegister()); |
| 5104 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5108 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5109 | Location obj_loc = locations->InAt(0); |
| 5110 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5112 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5113 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5114 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5115 | Primitive::Type type = instruction->GetType(); |
| 5116 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5117 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5118 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5119 | if (index.IsConstant()) { |
| 5120 | __ movzxb(out, Address(obj, |
| 5121 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5122 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5123 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5124 | } |
| 5125 | break; |
| 5126 | } |
| 5127 | |
| 5128 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5129 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5130 | if (index.IsConstant()) { |
| 5131 | __ movsxb(out, Address(obj, |
| 5132 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5133 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5134 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5135 | } |
| 5136 | break; |
| 5137 | } |
| 5138 | |
| 5139 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5140 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5141 | if (index.IsConstant()) { |
| 5142 | __ movsxw(out, Address(obj, |
| 5143 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5144 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5145 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5146 | } |
| 5147 | break; |
| 5148 | } |
| 5149 | |
| 5150 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5151 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5152 | if (index.IsConstant()) { |
| 5153 | __ movzxw(out, Address(obj, |
| 5154 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5155 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5156 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5157 | } |
| 5158 | break; |
| 5159 | } |
| 5160 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5161 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5162 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5163 | if (index.IsConstant()) { |
| 5164 | __ movl(out, Address(obj, |
| 5165 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5166 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5167 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5168 | } |
| 5169 | break; |
| 5170 | } |
| 5171 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5172 | case Primitive::kPrimNot: { |
| 5173 | static_assert( |
| 5174 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5175 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5176 | // /* HeapReference<Object> */ out = |
| 5177 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5178 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5179 | Location temp = locations->GetTemp(0); |
| 5180 | // Note that a potential implicit null check is handled in this |
| 5181 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5182 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5183 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5184 | } else { |
| 5185 | Register out = out_loc.AsRegister<Register>(); |
| 5186 | if (index.IsConstant()) { |
| 5187 | uint32_t offset = |
| 5188 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5189 | __ movl(out, Address(obj, offset)); |
| 5190 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5191 | // If read barriers are enabled, emit read barriers other than |
| 5192 | // Baker's using a slow path (and also unpoison the loaded |
| 5193 | // reference, if heap poisoning is enabled). |
| 5194 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5195 | } else { |
| 5196 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5197 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5198 | // If read barriers are enabled, emit read barriers other than |
| 5199 | // Baker's using a slow path (and also unpoison the loaded |
| 5200 | // reference, if heap poisoning is enabled). |
| 5201 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5202 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5203 | } |
| 5204 | } |
| 5205 | break; |
| 5206 | } |
| 5207 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5208 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5209 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5210 | if (index.IsConstant()) { |
| 5211 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5212 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5213 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5214 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5215 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5216 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5217 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5218 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5219 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5220 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5221 | } |
| 5222 | break; |
| 5223 | } |
| 5224 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5225 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5226 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5227 | if (index.IsConstant()) { |
| 5228 | __ movss(out, Address(obj, |
| 5229 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5230 | } else { |
| 5231 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5232 | } |
| 5233 | break; |
| 5234 | } |
| 5235 | |
| 5236 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5237 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5238 | if (index.IsConstant()) { |
| 5239 | __ movsd(out, Address(obj, |
| 5240 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5241 | } else { |
| 5242 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5243 | } |
| 5244 | break; |
| 5245 | } |
| 5246 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5247 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5248 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5249 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5250 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5251 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5252 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5253 | // Potential implicit null checks, in the case of reference or |
| 5254 | // long arrays, are handled in the previous switch statement. |
| 5255 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5256 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5257 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5261 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5262 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5263 | bool needs_write_barrier = |
| 5264 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5265 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5266 | bool object_array_set_with_read_barrier = |
| 5267 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5268 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5269 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5270 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5271 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5272 | LocationSummary::kCallOnSlowPath : |
| 5273 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5274 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5275 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5276 | || (value_type == Primitive::kPrimByte); |
| 5277 | // We need the inputs to be different than the output in case of long operation. |
| 5278 | // In case of a byte operation, the register allocator does not support multiple |
| 5279 | // inputs that die at entry with one in a specific register. |
| 5280 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5281 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5282 | if (is_byte_type) { |
| 5283 | // Ensure the value is in a byte register. |
| 5284 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5285 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5286 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5287 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5288 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5289 | } |
| 5290 | if (needs_write_barrier) { |
| 5291 | // Temporary registers for the write barrier. |
| 5292 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5293 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5294 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5295 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5299 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5300 | Location array_loc = locations->InAt(0); |
| 5301 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5302 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5303 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5304 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5305 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5306 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5307 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5308 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5309 | bool needs_write_barrier = |
| 5310 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5311 | |
| 5312 | switch (value_type) { |
| 5313 | case Primitive::kPrimBoolean: |
| 5314 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5315 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5316 | Address address = index.IsConstant() |
| 5317 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5318 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5319 | if (value.IsRegister()) { |
| 5320 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5321 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5322 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5323 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5324 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5325 | break; |
| 5326 | } |
| 5327 | |
| 5328 | case Primitive::kPrimShort: |
| 5329 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5330 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5331 | Address address = index.IsConstant() |
| 5332 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5333 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5334 | if (value.IsRegister()) { |
| 5335 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5336 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5337 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5338 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5339 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5340 | break; |
| 5341 | } |
| 5342 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5343 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5344 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5345 | Address address = index.IsConstant() |
| 5346 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5347 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5348 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5349 | if (!value.IsRegister()) { |
| 5350 | // Just setting null. |
| 5351 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5352 | DCHECK(value.IsConstant()) << value; |
| 5353 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5354 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5355 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5356 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5357 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5358 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5359 | |
| 5360 | DCHECK(needs_write_barrier); |
| 5361 | Register register_value = value.AsRegister<Register>(); |
| 5362 | NearLabel done, not_null, do_put; |
| 5363 | SlowPathCode* slow_path = nullptr; |
| 5364 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5365 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5366 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5367 | codegen_->AddSlowPath(slow_path); |
| 5368 | if (instruction->GetValueCanBeNull()) { |
| 5369 | __ testl(register_value, register_value); |
| 5370 | __ j(kNotEqual, ¬_null); |
| 5371 | __ movl(address, Immediate(0)); |
| 5372 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5373 | __ jmp(&done); |
| 5374 | __ Bind(¬_null); |
| 5375 | } |
| 5376 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5377 | if (kEmitCompilerReadBarrier) { |
| 5378 | // When read barriers are enabled, the type checking |
| 5379 | // instrumentation requires two read barriers: |
| 5380 | // |
| 5381 | // __ movl(temp2, temp); |
| 5382 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5383 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5384 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5385 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5386 | // |
| 5387 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5388 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5389 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5390 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5391 | // |
| 5392 | // __ cmpl(temp, temp2); |
| 5393 | // |
| 5394 | // However, the second read barrier may trash `temp`, as it |
| 5395 | // is a temporary register, and as such would not be saved |
| 5396 | // along with live registers before calling the runtime (nor |
| 5397 | // restored afterwards). So in this case, we bail out and |
| 5398 | // delegate the work to the array set slow path. |
| 5399 | // |
| 5400 | // TODO: Extend the register allocator to support a new |
| 5401 | // "(locally) live temp" location so as to avoid always |
| 5402 | // going into the slow path when read barriers are enabled. |
| 5403 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5404 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5405 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5406 | __ movl(temp, Address(array, class_offset)); |
| 5407 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5408 | __ MaybeUnpoisonHeapReference(temp); |
| 5409 | |
| 5410 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5411 | __ movl(temp, Address(temp, component_offset)); |
| 5412 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5413 | // nor the object reference in `register_value->klass`, as |
| 5414 | // we are comparing two poisoned references. |
| 5415 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5416 | |
| 5417 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5418 | __ j(kEqual, &do_put); |
| 5419 | // If heap poisoning is enabled, the `temp` reference has |
| 5420 | // not been unpoisoned yet; unpoison it now. |
| 5421 | __ MaybeUnpoisonHeapReference(temp); |
| 5422 | |
| 5423 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5424 | __ movl(temp, Address(temp, super_offset)); |
| 5425 | // If heap poisoning is enabled, no need to unpoison |
| 5426 | // `temp`, as we are comparing against null below. |
| 5427 | __ testl(temp, temp); |
| 5428 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5429 | __ Bind(&do_put); |
| 5430 | } else { |
| 5431 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5432 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5433 | } |
| 5434 | } |
| 5435 | |
| 5436 | if (kPoisonHeapReferences) { |
| 5437 | __ movl(temp, register_value); |
| 5438 | __ PoisonHeapReference(temp); |
| 5439 | __ movl(address, temp); |
| 5440 | } else { |
| 5441 | __ movl(address, register_value); |
| 5442 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5443 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5444 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5445 | } |
| 5446 | |
| 5447 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5448 | codegen_->MarkGCCard( |
| 5449 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5450 | __ Bind(&done); |
| 5451 | |
| 5452 | if (slow_path != nullptr) { |
| 5453 | __ Bind(slow_path->GetExitLabel()); |
| 5454 | } |
| 5455 | |
| 5456 | break; |
| 5457 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5458 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5459 | case Primitive::kPrimInt: { |
| 5460 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5461 | Address address = index.IsConstant() |
| 5462 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5463 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5464 | if (value.IsRegister()) { |
| 5465 | __ movl(address, value.AsRegister<Register>()); |
| 5466 | } else { |
| 5467 | DCHECK(value.IsConstant()) << value; |
| 5468 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5469 | __ movl(address, Immediate(v)); |
| 5470 | } |
| 5471 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5472 | break; |
| 5473 | } |
| 5474 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5475 | case Primitive::kPrimLong: { |
| 5476 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5477 | if (index.IsConstant()) { |
| 5478 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5479 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5480 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5481 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5482 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5483 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5484 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5485 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5486 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5487 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5488 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5489 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5490 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5491 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5492 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5493 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5494 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5495 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5496 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5497 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5498 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5499 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5500 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5501 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5502 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5503 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5504 | Immediate(High32Bits(val))); |
| 5505 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5506 | } |
| 5507 | break; |
| 5508 | } |
| 5509 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5510 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5511 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5512 | Address address = index.IsConstant() |
| 5513 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5514 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5515 | if (value.IsFpuRegister()) { |
| 5516 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5517 | } else { |
| 5518 | DCHECK(value.IsConstant()); |
| 5519 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5520 | __ movl(address, Immediate(v)); |
| 5521 | } |
| 5522 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5523 | break; |
| 5524 | } |
| 5525 | |
| 5526 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5527 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5528 | Address address = index.IsConstant() |
| 5529 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5530 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5531 | if (value.IsFpuRegister()) { |
| 5532 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5533 | } else { |
| 5534 | DCHECK(value.IsConstant()); |
| 5535 | Address address_hi = index.IsConstant() ? |
| 5536 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5537 | offset + kX86WordSize) : |
| 5538 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5539 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5540 | __ movl(address, Immediate(Low32Bits(v))); |
| 5541 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5542 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5543 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5544 | break; |
| 5545 | } |
| 5546 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5547 | case Primitive::kPrimVoid: |
| 5548 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5549 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5550 | } |
| 5551 | } |
| 5552 | |
| 5553 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5554 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5555 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5556 | if (!instruction->IsEmittedAtUseSite()) { |
| 5557 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5558 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5559 | } |
| 5560 | |
| 5561 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5562 | if (instruction->IsEmittedAtUseSite()) { |
| 5563 | return; |
| 5564 | } |
| 5565 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5566 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5567 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5568 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5569 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5570 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5571 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5575 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5576 | ? LocationSummary::kCallOnSlowPath |
| 5577 | : LocationSummary::kNoCall; |
| 5578 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5579 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5580 | HInstruction* length = instruction->InputAt(1); |
| 5581 | if (!length->IsEmittedAtUseSite()) { |
| 5582 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5583 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5584 | if (instruction->HasUses()) { |
| 5585 | locations->SetOut(Location::SameAsFirstInput()); |
| 5586 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5590 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5591 | Location index_loc = locations->InAt(0); |
| 5592 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5593 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5594 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5595 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5596 | if (length_loc.IsConstant()) { |
| 5597 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5598 | if (index_loc.IsConstant()) { |
| 5599 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5600 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5601 | if (index < 0 || index >= length) { |
| 5602 | codegen_->AddSlowPath(slow_path); |
| 5603 | __ jmp(slow_path->GetEntryLabel()); |
| 5604 | } else { |
| 5605 | // Some optimization after BCE may have generated this, and we should not |
| 5606 | // generate a bounds check if it is a valid range. |
| 5607 | } |
| 5608 | return; |
| 5609 | } |
| 5610 | |
| 5611 | // We have to reverse the jump condition because the length is the constant. |
| 5612 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5613 | __ cmpl(index_reg, Immediate(length)); |
| 5614 | codegen_->AddSlowPath(slow_path); |
| 5615 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5616 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5617 | HInstruction* array_length = instruction->InputAt(1); |
| 5618 | if (array_length->IsEmittedAtUseSite()) { |
| 5619 | // Address the length field in the array. |
| 5620 | DCHECK(array_length->IsArrayLength()); |
| 5621 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5622 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5623 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 5624 | if (index_loc.IsConstant()) { |
| 5625 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5626 | __ cmpl(array_len, Immediate(value)); |
| 5627 | } else { |
| 5628 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5629 | } |
| 5630 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5631 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5632 | Register length = length_loc.AsRegister<Register>(); |
| 5633 | if (index_loc.IsConstant()) { |
| 5634 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5635 | __ cmpl(length, Immediate(value)); |
| 5636 | } else { |
| 5637 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5638 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5639 | } |
| 5640 | codegen_->AddSlowPath(slow_path); |
| 5641 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5642 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5643 | } |
| 5644 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5645 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5646 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5650 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5651 | } |
| 5652 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5653 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5654 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5655 | } |
| 5656 | |
| 5657 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5658 | HBasicBlock* block = instruction->GetBlock(); |
| 5659 | if (block->GetLoopInformation() != nullptr) { |
| 5660 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5661 | // The back edge will generate the suspend check. |
| 5662 | return; |
| 5663 | } |
| 5664 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5665 | // The goto will generate the suspend check. |
| 5666 | return; |
| 5667 | } |
| 5668 | GenerateSuspendCheck(instruction, nullptr); |
| 5669 | } |
| 5670 | |
| 5671 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5672 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5673 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5674 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5675 | if (slow_path == nullptr) { |
| 5676 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5677 | instruction->SetSlowPath(slow_path); |
| 5678 | codegen_->AddSlowPath(slow_path); |
| 5679 | if (successor != nullptr) { |
| 5680 | DCHECK(successor->IsLoopHeader()); |
| 5681 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5682 | } |
| 5683 | } else { |
| 5684 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5685 | } |
| 5686 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5687 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5688 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5689 | if (successor == nullptr) { |
| 5690 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5691 | __ Bind(slow_path->GetReturnLabel()); |
| 5692 | } else { |
| 5693 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5694 | __ jmp(slow_path->GetEntryLabel()); |
| 5695 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5698 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5699 | return codegen_->GetAssembler(); |
| 5700 | } |
| 5701 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5702 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5703 | ScratchRegisterScope ensure_scratch( |
| 5704 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5705 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5706 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5707 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5708 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5712 | ScratchRegisterScope ensure_scratch( |
| 5713 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5714 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5715 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5716 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5717 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5718 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5719 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5723 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5724 | Location source = move->GetSource(); |
| 5725 | Location destination = move->GetDestination(); |
| 5726 | |
| 5727 | if (source.IsRegister()) { |
| 5728 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5729 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5730 | } else if (destination.IsFpuRegister()) { |
| 5731 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5732 | } else { |
| 5733 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5734 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5735 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5736 | } else if (source.IsRegisterPair()) { |
| 5737 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5738 | // Create stack space for 2 elements. |
| 5739 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5740 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5741 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5742 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5743 | // And remove the temporary stack space we allocated. |
| 5744 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5745 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5746 | if (destination.IsRegister()) { |
| 5747 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5748 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5749 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5750 | } else if (destination.IsRegisterPair()) { |
| 5751 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5752 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5753 | __ psrlq(src_reg, Immediate(32)); |
| 5754 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5755 | } else if (destination.IsStackSlot()) { |
| 5756 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5757 | } else { |
| 5758 | DCHECK(destination.IsDoubleStackSlot()); |
| 5759 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5760 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5761 | } else if (source.IsStackSlot()) { |
| 5762 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5763 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5764 | } else if (destination.IsFpuRegister()) { |
| 5765 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5766 | } else { |
| 5767 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5768 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5769 | } |
| 5770 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5771 | if (destination.IsRegisterPair()) { |
| 5772 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5773 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5774 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5775 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5776 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5777 | } else { |
| 5778 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5779 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5780 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5781 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5782 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5783 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5784 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5785 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5786 | if (value == 0) { |
| 5787 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5788 | } else { |
| 5789 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5790 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5791 | } else { |
| 5792 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5793 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5794 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5795 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5796 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5797 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5798 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5799 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5800 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5801 | if (value == 0) { |
| 5802 | // Easy handling of 0.0. |
| 5803 | __ xorps(dest, dest); |
| 5804 | } else { |
| 5805 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5806 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5807 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5808 | __ movl(temp, Immediate(value)); |
| 5809 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5810 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5811 | } else { |
| 5812 | DCHECK(destination.IsStackSlot()) << destination; |
| 5813 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5814 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5815 | } else if (constant->IsLongConstant()) { |
| 5816 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5817 | int32_t low_value = Low32Bits(value); |
| 5818 | int32_t high_value = High32Bits(value); |
| 5819 | Immediate low(low_value); |
| 5820 | Immediate high(high_value); |
| 5821 | if (destination.IsDoubleStackSlot()) { |
| 5822 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5823 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5824 | } else { |
| 5825 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5826 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5827 | } |
| 5828 | } else { |
| 5829 | DCHECK(constant->IsDoubleConstant()); |
| 5830 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5831 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5832 | int32_t low_value = Low32Bits(value); |
| 5833 | int32_t high_value = High32Bits(value); |
| 5834 | Immediate low(low_value); |
| 5835 | Immediate high(high_value); |
| 5836 | if (destination.IsFpuRegister()) { |
| 5837 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5838 | if (value == 0) { |
| 5839 | // Easy handling of 0.0. |
| 5840 | __ xorpd(dest, dest); |
| 5841 | } else { |
| 5842 | __ pushl(high); |
| 5843 | __ pushl(low); |
| 5844 | __ movsd(dest, Address(ESP, 0)); |
| 5845 | __ addl(ESP, Immediate(8)); |
| 5846 | } |
| 5847 | } else { |
| 5848 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5849 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5850 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5851 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5852 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5853 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5854 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5855 | } |
| 5856 | } |
| 5857 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5858 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5859 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5860 | ScratchRegisterScope ensure_scratch( |
| 5861 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5862 | |
| 5863 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5864 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5865 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5866 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5867 | } |
| 5868 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5869 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5870 | ScratchRegisterScope ensure_scratch( |
| 5871 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5872 | |
| 5873 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5874 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5875 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5876 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5877 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5878 | } |
| 5879 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5880 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5881 | ScratchRegisterScope ensure_scratch1( |
| 5882 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5883 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5884 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5885 | ScratchRegisterScope ensure_scratch2( |
| 5886 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5887 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5888 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5889 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5890 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5891 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5892 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5893 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5897 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5898 | Location source = move->GetSource(); |
| 5899 | Location destination = move->GetDestination(); |
| 5900 | |
| 5901 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5902 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5903 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5904 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5905 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5906 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5907 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5908 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5909 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5910 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5911 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5912 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5913 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5914 | // Use XOR Swap algorithm to avoid a temporary. |
| 5915 | DCHECK_NE(source.reg(), destination.reg()); |
| 5916 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5917 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5918 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5919 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5920 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5921 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5922 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5923 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5924 | // Take advantage of the 16 bytes in the XMM register. |
| 5925 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5926 | Address stack(ESP, destination.GetStackIndex()); |
| 5927 | // Load the double into the high doubleword. |
| 5928 | __ movhpd(reg, stack); |
| 5929 | |
| 5930 | // Store the low double into the destination. |
| 5931 | __ movsd(stack, reg); |
| 5932 | |
| 5933 | // Move the high double to the low double. |
| 5934 | __ psrldq(reg, Immediate(8)); |
| 5935 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5936 | // Take advantage of the 16 bytes in the XMM register. |
| 5937 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5938 | Address stack(ESP, source.GetStackIndex()); |
| 5939 | // Load the double into the high doubleword. |
| 5940 | __ movhpd(reg, stack); |
| 5941 | |
| 5942 | // Store the low double into the destination. |
| 5943 | __ movsd(stack, reg); |
| 5944 | |
| 5945 | // Move the high double to the low double. |
| 5946 | __ psrldq(reg, Immediate(8)); |
| 5947 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5948 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5949 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5950 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5951 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5952 | } |
| 5953 | } |
| 5954 | |
| 5955 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5956 | __ pushl(static_cast<Register>(reg)); |
| 5957 | } |
| 5958 | |
| 5959 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5960 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5961 | } |
| 5962 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5963 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 5964 | HLoadClass::LoadKind desired_class_load_kind) { |
| 5965 | if (kEmitCompilerReadBarrier) { |
| 5966 | switch (desired_class_load_kind) { |
| 5967 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5968 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5969 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5970 | // TODO: Implement for read barrier. |
| 5971 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5972 | default: |
| 5973 | break; |
| 5974 | } |
| 5975 | } |
| 5976 | switch (desired_class_load_kind) { |
| 5977 | case HLoadClass::LoadKind::kReferrersClass: |
| 5978 | break; |
| 5979 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5980 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5981 | break; |
| 5982 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5983 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5984 | FALLTHROUGH_INTENDED; |
| 5985 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5986 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
| 5987 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5988 | // is incompatible with it. |
| 5989 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5990 | // with irreducible loops. |
| 5991 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5992 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5993 | } |
| 5994 | break; |
| 5995 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5996 | break; |
| 5997 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5998 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5999 | break; |
| 6000 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6001 | break; |
| 6002 | } |
| 6003 | return desired_class_load_kind; |
| 6004 | } |
| 6005 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6006 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6007 | if (cls->NeedsAccessCheck()) { |
| 6008 | InvokeRuntimeCallingConvention calling_convention; |
| 6009 | CodeGenerator::CreateLoadClassLocationSummary( |
| 6010 | cls, |
| 6011 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 6012 | Location::RegisterLocation(EAX), |
| 6013 | /* code_generator_supports_read_barrier */ true); |
| 6014 | return; |
| 6015 | } |
| 6016 | |
| 6017 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 6018 | ? LocationSummary::kCallOnSlowPath |
| 6019 | : LocationSummary::kNoCall; |
| 6020 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 6021 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6022 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 6023 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 6024 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 6025 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 6026 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6027 | } |
| 6028 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6029 | } |
| 6030 | |
| 6031 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6032 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6033 | if (cls->NeedsAccessCheck()) { |
| 6034 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 6035 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 6036 | cls, |
| 6037 | cls->GetDexPc(), |
| 6038 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6039 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6040 | return; |
| 6041 | } |
| 6042 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6043 | Location out_loc = locations->Out(); |
| 6044 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6045 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6046 | bool generate_null_check = false; |
| 6047 | switch (cls->GetLoadKind()) { |
| 6048 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6049 | DCHECK(!cls->CanCallRuntime()); |
| 6050 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6051 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6052 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6053 | GenerateGcRootFieldLoad( |
| 6054 | cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 6055 | break; |
| 6056 | } |
| 6057 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
| 6058 | DCHECK(!kEmitCompilerReadBarrier); |
| 6059 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6060 | codegen_->RecordTypePatch(cls); |
| 6061 | break; |
| 6062 | } |
| 6063 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 6064 | DCHECK(!kEmitCompilerReadBarrier); |
| 6065 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6066 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6067 | codegen_->RecordTypePatch(cls); |
| 6068 | break; |
| 6069 | } |
| 6070 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 6071 | DCHECK(!kEmitCompilerReadBarrier); |
| 6072 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6073 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6074 | __ movl(out, Immediate(address)); |
| 6075 | codegen_->RecordSimplePatch(); |
| 6076 | break; |
| 6077 | } |
| 6078 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 6079 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6080 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6081 | // /* GcRoot<mirror::Class> */ out = *address |
| 6082 | GenerateGcRootFieldLoad(cls, out_loc, Address::Absolute(address)); |
| 6083 | generate_null_check = !cls->IsInDexCache(); |
| 6084 | break; |
| 6085 | } |
| 6086 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 6087 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6088 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 6089 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 6090 | // /* GcRoot<mirror::Class> */ out = *(base + offset) /* PC-relative */ |
| 6091 | GenerateGcRootFieldLoad( |
| 6092 | cls, out_loc, Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), fixup_label); |
| 6093 | generate_null_check = !cls->IsInDexCache(); |
| 6094 | break; |
| 6095 | } |
| 6096 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 6097 | // /* GcRoot<mirror::Class>[] */ out = |
| 6098 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 6099 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6100 | __ movl(out, Address(current_method, |
| 6101 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 6102 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 6103 | GenerateGcRootFieldLoad( |
| 6104 | cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
| 6105 | generate_null_check = !cls->IsInDexCache(); |
| 6106 | break; |
| 6107 | } |
| 6108 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6109 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6110 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6111 | DCHECK(cls->CanCallRuntime()); |
| 6112 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6113 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6114 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6115 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6116 | if (generate_null_check) { |
| 6117 | __ testl(out, out); |
| 6118 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6119 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6120 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6121 | if (cls->MustGenerateClinitCheck()) { |
| 6122 | GenerateClassInitializationCheck(slow_path, out); |
| 6123 | } else { |
| 6124 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6125 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6126 | } |
| 6127 | } |
| 6128 | |
| 6129 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6130 | LocationSummary* locations = |
| 6131 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6132 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6133 | if (check->HasUses()) { |
| 6134 | locations->SetOut(Location::SameAsFirstInput()); |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6139 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6140 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6141 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6142 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6143 | GenerateClassInitializationCheck(slow_path, |
| 6144 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6145 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6146 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6147 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6148 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6149 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6150 | Immediate(mirror::Class::kStatusInitialized)); |
| 6151 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6152 | __ Bind(slow_path->GetExitLabel()); |
| 6153 | // No need for memory fence, thanks to the X86 memory model. |
| 6154 | } |
| 6155 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6156 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6157 | HLoadString::LoadKind desired_string_load_kind) { |
| 6158 | if (kEmitCompilerReadBarrier) { |
| 6159 | switch (desired_string_load_kind) { |
| 6160 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6161 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6162 | case HLoadString::LoadKind::kBootImageAddress: |
| 6163 | // TODO: Implement for read barrier. |
| 6164 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6165 | default: |
| 6166 | break; |
| 6167 | } |
| 6168 | } |
| 6169 | switch (desired_string_load_kind) { |
| 6170 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6171 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6172 | break; |
| 6173 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6174 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6175 | FALLTHROUGH_INTENDED; |
| 6176 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6177 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6178 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6179 | // is incompatible with it. |
| 6180 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6181 | // with irreducible loops. |
| 6182 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6183 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6184 | } |
| 6185 | break; |
| 6186 | case HLoadString::LoadKind::kBootImageAddress: |
| 6187 | break; |
| 6188 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6189 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6190 | break; |
| 6191 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6192 | break; |
| 6193 | } |
| 6194 | return desired_string_load_kind; |
| 6195 | } |
| 6196 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6197 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6198 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6199 | ? LocationSummary::kCallOnSlowPath |
| 6200 | : LocationSummary::kNoCall; |
| 6201 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6202 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6203 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 6204 | load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| 6205 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 6206 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6207 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6208 | locations->SetOut(Location::RequiresRegister()); |
| 6209 | } |
| 6210 | |
| 6211 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6212 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6213 | Location out_loc = locations->Out(); |
| 6214 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6215 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6216 | switch (load->GetLoadKind()) { |
| 6217 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 6218 | DCHECK(!kEmitCompilerReadBarrier); |
| 6219 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6220 | codegen_->RecordStringPatch(load); |
| 6221 | return; // No dex cache slow path. |
| 6222 | } |
| 6223 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6224 | DCHECK(!kEmitCompilerReadBarrier); |
| 6225 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6226 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6227 | codegen_->RecordStringPatch(load); |
| 6228 | return; // No dex cache slow path. |
| 6229 | } |
| 6230 | case HLoadString::LoadKind::kBootImageAddress: { |
| 6231 | DCHECK(!kEmitCompilerReadBarrier); |
| 6232 | DCHECK_NE(load->GetAddress(), 0u); |
| 6233 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6234 | __ movl(out, Immediate(address)); |
| 6235 | codegen_->RecordSimplePatch(); |
| 6236 | return; // No dex cache slow path. |
| 6237 | } |
| 6238 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 6239 | DCHECK_NE(load->GetAddress(), 0u); |
| 6240 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6241 | // /* GcRoot<mirror::String> */ out = *address |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6242 | GenerateGcRootFieldLoad(load, out_loc, Address::Absolute(address)); |
| 6243 | break; |
| 6244 | } |
| 6245 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 6246 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6247 | uint32_t offset = load->GetDexCacheElementOffset(); |
| 6248 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(load->GetDexFile(), offset); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6249 | // /* GcRoot<mirror::String> */ out = *(base + offset) /* PC-relative */ |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6250 | GenerateGcRootFieldLoad( |
| 6251 | load, out_loc, Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), fixup_label); |
| 6252 | break; |
| 6253 | } |
| 6254 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 6255 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6256 | |
| 6257 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6258 | GenerateGcRootFieldLoad( |
| 6259 | load, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 6260 | |
| 6261 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 6262 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
| 6263 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 6264 | GenerateGcRootFieldLoad( |
| 6265 | load, out_loc, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 6266 | break; |
| 6267 | } |
| 6268 | default: |
| 6269 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 6270 | UNREACHABLE(); |
| 6271 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6272 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6273 | if (!load->IsInDexCache()) { |
| 6274 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6275 | codegen_->AddSlowPath(slow_path); |
| 6276 | __ testl(out, out); |
| 6277 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6278 | __ Bind(slow_path->GetExitLabel()); |
| 6279 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6280 | } |
| 6281 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6282 | static Address GetExceptionTlsAddress() { |
| 6283 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 6284 | } |
| 6285 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6286 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6287 | LocationSummary* locations = |
| 6288 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6289 | locations->SetOut(Location::RequiresRegister()); |
| 6290 | } |
| 6291 | |
| 6292 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6293 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6294 | } |
| 6295 | |
| 6296 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6297 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6298 | } |
| 6299 | |
| 6300 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6301 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6302 | } |
| 6303 | |
| 6304 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6305 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6306 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6307 | InvokeRuntimeCallingConvention calling_convention; |
| 6308 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6309 | } |
| 6310 | |
| 6311 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6312 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 6313 | instruction, |
| 6314 | instruction->GetDexPc(), |
| 6315 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6316 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6317 | } |
| 6318 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6319 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6320 | return kEmitCompilerReadBarrier && |
| 6321 | (kUseBakerReadBarrier || |
| 6322 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6323 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6324 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6325 | } |
| 6326 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6327 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6328 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6329 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6330 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6331 | case TypeCheckKind::kExactCheck: |
| 6332 | case TypeCheckKind::kAbstractClassCheck: |
| 6333 | case TypeCheckKind::kClassHierarchyCheck: |
| 6334 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6335 | call_kind = |
| 6336 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6337 | break; |
| 6338 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6339 | case TypeCheckKind::kUnresolvedCheck: |
| 6340 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6341 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6342 | break; |
| 6343 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6344 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6345 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6346 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6347 | locations->SetInAt(1, Location::Any()); |
| 6348 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6349 | locations->SetOut(Location::RequiresRegister()); |
| 6350 | // When read barriers are enabled, we need a temporary register for |
| 6351 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6352 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6353 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6354 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6355 | } |
| 6356 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6357 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6358 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6359 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6360 | Location obj_loc = locations->InAt(0); |
| 6361 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6362 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6363 | Location out_loc = locations->Out(); |
| 6364 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6365 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6366 | locations->GetTemp(0) : |
| 6367 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6368 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6369 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6370 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6371 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6372 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6373 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6374 | |
| 6375 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6376 | // Avoid null check if we know obj is not null. |
| 6377 | if (instruction->MustDoNullCheck()) { |
| 6378 | __ testl(obj, obj); |
| 6379 | __ j(kEqual, &zero); |
| 6380 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6381 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6382 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6383 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6384 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6385 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6386 | case TypeCheckKind::kExactCheck: { |
| 6387 | if (cls.IsRegister()) { |
| 6388 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6389 | } else { |
| 6390 | DCHECK(cls.IsStackSlot()) << cls; |
| 6391 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6392 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6393 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6394 | // Classes must be equal for the instanceof to succeed. |
| 6395 | __ j(kNotEqual, &zero); |
| 6396 | __ movl(out, Immediate(1)); |
| 6397 | __ jmp(&done); |
| 6398 | break; |
| 6399 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6400 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6401 | case TypeCheckKind::kAbstractClassCheck: { |
| 6402 | // If the class is abstract, we eagerly fetch the super class of the |
| 6403 | // object to avoid doing a comparison we know will fail. |
| 6404 | NearLabel loop; |
| 6405 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6406 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6407 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6408 | __ testl(out, out); |
| 6409 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6410 | __ j(kEqual, &done); |
| 6411 | if (cls.IsRegister()) { |
| 6412 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6413 | } else { |
| 6414 | DCHECK(cls.IsStackSlot()) << cls; |
| 6415 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6416 | } |
| 6417 | __ j(kNotEqual, &loop); |
| 6418 | __ movl(out, Immediate(1)); |
| 6419 | if (zero.IsLinked()) { |
| 6420 | __ jmp(&done); |
| 6421 | } |
| 6422 | break; |
| 6423 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6424 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6425 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6426 | // Walk over the class hierarchy to find a match. |
| 6427 | NearLabel loop, success; |
| 6428 | __ Bind(&loop); |
| 6429 | if (cls.IsRegister()) { |
| 6430 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6431 | } else { |
| 6432 | DCHECK(cls.IsStackSlot()) << cls; |
| 6433 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6434 | } |
| 6435 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6436 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6437 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6438 | __ testl(out, out); |
| 6439 | __ j(kNotEqual, &loop); |
| 6440 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6441 | __ jmp(&done); |
| 6442 | __ Bind(&success); |
| 6443 | __ movl(out, Immediate(1)); |
| 6444 | if (zero.IsLinked()) { |
| 6445 | __ jmp(&done); |
| 6446 | } |
| 6447 | break; |
| 6448 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6449 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6450 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6451 | // Do an exact check. |
| 6452 | NearLabel exact_check; |
| 6453 | if (cls.IsRegister()) { |
| 6454 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6455 | } else { |
| 6456 | DCHECK(cls.IsStackSlot()) << cls; |
| 6457 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6458 | } |
| 6459 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6460 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6461 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6462 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6463 | __ testl(out, out); |
| 6464 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6465 | __ j(kEqual, &done); |
| 6466 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6467 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6468 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6469 | __ movl(out, Immediate(1)); |
| 6470 | __ jmp(&done); |
| 6471 | break; |
| 6472 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6473 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6474 | case TypeCheckKind::kArrayCheck: { |
| 6475 | if (cls.IsRegister()) { |
| 6476 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6477 | } else { |
| 6478 | DCHECK(cls.IsStackSlot()) << cls; |
| 6479 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6480 | } |
| 6481 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6482 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6483 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6484 | codegen_->AddSlowPath(slow_path); |
| 6485 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6486 | __ movl(out, Immediate(1)); |
| 6487 | if (zero.IsLinked()) { |
| 6488 | __ jmp(&done); |
| 6489 | } |
| 6490 | break; |
| 6491 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6492 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6493 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6494 | case TypeCheckKind::kInterfaceCheck: { |
| 6495 | // Note that we indeed only call on slow path, but we always go |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6496 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6497 | // cases. |
| 6498 | // |
| 6499 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6500 | // entry point without resorting to a type checking slow path |
| 6501 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6502 | // require to assign fixed registers for the inputs of this |
| 6503 | // HInstanceOf instruction (following the runtime calling |
| 6504 | // convention), which might be cluttered by the potential first |
| 6505 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6506 | // |
| 6507 | // TODO: Introduce a new runtime entry point taking the object |
| 6508 | // to test (instead of its class) as argument, and let it deal |
| 6509 | // with the read barrier issues. This will let us refactor this |
| 6510 | // case of the `switch` code as it was previously (with a direct |
| 6511 | // call to the runtime not using a type checking slow path). |
| 6512 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6513 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6514 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6515 | /* is_fatal */ false); |
| 6516 | codegen_->AddSlowPath(slow_path); |
| 6517 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6518 | if (zero.IsLinked()) { |
| 6519 | __ jmp(&done); |
| 6520 | } |
| 6521 | break; |
| 6522 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6523 | } |
| 6524 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6525 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6526 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6527 | __ xorl(out, out); |
| 6528 | } |
| 6529 | |
| 6530 | if (done.IsLinked()) { |
| 6531 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6532 | } |
| 6533 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6534 | if (slow_path != nullptr) { |
| 6535 | __ Bind(slow_path->GetExitLabel()); |
| 6536 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6537 | } |
| 6538 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6539 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6540 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6541 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6542 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6543 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6544 | case TypeCheckKind::kExactCheck: |
| 6545 | case TypeCheckKind::kAbstractClassCheck: |
| 6546 | case TypeCheckKind::kClassHierarchyCheck: |
| 6547 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6548 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6549 | LocationSummary::kCallOnSlowPath : |
| 6550 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6551 | break; |
| 6552 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6553 | case TypeCheckKind::kUnresolvedCheck: |
| 6554 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6555 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6556 | break; |
| 6557 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6558 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6559 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6560 | locations->SetInAt(1, Location::Any()); |
| 6561 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6562 | locations->AddTemp(Location::RequiresRegister()); |
| 6563 | // When read barriers are enabled, we need an additional temporary |
| 6564 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6565 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6566 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6567 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6571 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6572 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6573 | Location obj_loc = locations->InAt(0); |
| 6574 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6575 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6576 | Location temp_loc = locations->GetTemp(0); |
| 6577 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6578 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6579 | locations->GetTemp(1) : |
| 6580 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6581 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6582 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6583 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6584 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6585 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6586 | bool is_type_check_slow_path_fatal = |
| 6587 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6588 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6589 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6590 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6591 | !instruction->CanThrowIntoCatchBlock(); |
| 6592 | SlowPathCode* type_check_slow_path = |
| 6593 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6594 | is_type_check_slow_path_fatal); |
| 6595 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6596 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6597 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6598 | // Avoid null check if we know obj is not null. |
| 6599 | if (instruction->MustDoNullCheck()) { |
| 6600 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6601 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6602 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6603 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6604 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6605 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6606 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6607 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6608 | case TypeCheckKind::kExactCheck: |
| 6609 | case TypeCheckKind::kArrayCheck: { |
| 6610 | if (cls.IsRegister()) { |
| 6611 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6612 | } else { |
| 6613 | DCHECK(cls.IsStackSlot()) << cls; |
| 6614 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6615 | } |
| 6616 | // Jump to slow path for throwing the exception or doing a |
| 6617 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6618 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6619 | break; |
| 6620 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6621 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6622 | case TypeCheckKind::kAbstractClassCheck: { |
| 6623 | // If the class is abstract, we eagerly fetch the super class of the |
| 6624 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6625 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6626 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6627 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6628 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6629 | |
| 6630 | // If the class reference currently in `temp` is not null, jump |
| 6631 | // to the `compare_classes` label to compare it with the checked |
| 6632 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6633 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6634 | __ j(kNotEqual, &compare_classes); |
| 6635 | // Otherwise, jump to the slow path to throw the exception. |
| 6636 | // |
| 6637 | // But before, move back the object's class into `temp` before |
| 6638 | // going into the slow path, as it has been overwritten in the |
| 6639 | // meantime. |
| 6640 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6641 | GenerateReferenceLoadTwoRegisters( |
| 6642 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6643 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6644 | |
| 6645 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6646 | if (cls.IsRegister()) { |
| 6647 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6648 | } else { |
| 6649 | DCHECK(cls.IsStackSlot()) << cls; |
| 6650 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6651 | } |
| 6652 | __ j(kNotEqual, &loop); |
| 6653 | break; |
| 6654 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6655 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6656 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6657 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6658 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6659 | __ Bind(&loop); |
| 6660 | if (cls.IsRegister()) { |
| 6661 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6662 | } else { |
| 6663 | DCHECK(cls.IsStackSlot()) << cls; |
| 6664 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6665 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6666 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6667 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6668 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6669 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6670 | |
| 6671 | // If the class reference currently in `temp` is not null, jump |
| 6672 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6673 | __ testl(temp, temp); |
| 6674 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6675 | // Otherwise, jump to the slow path to throw the exception. |
| 6676 | // |
| 6677 | // But before, move back the object's class into `temp` before |
| 6678 | // going into the slow path, as it has been overwritten in the |
| 6679 | // meantime. |
| 6680 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6681 | GenerateReferenceLoadTwoRegisters( |
| 6682 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6683 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6684 | break; |
| 6685 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6686 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6687 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6688 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6689 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6690 | if (cls.IsRegister()) { |
| 6691 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6692 | } else { |
| 6693 | DCHECK(cls.IsStackSlot()) << cls; |
| 6694 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6695 | } |
| 6696 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6697 | |
| 6698 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6699 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6700 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6701 | |
| 6702 | // If the component type is not null (i.e. the object is indeed |
| 6703 | // an array), jump to label `check_non_primitive_component_type` |
| 6704 | // to further check that this component type is not a primitive |
| 6705 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6706 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6707 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6708 | // Otherwise, jump to the slow path to throw the exception. |
| 6709 | // |
| 6710 | // But before, move back the object's class into `temp` before |
| 6711 | // going into the slow path, as it has been overwritten in the |
| 6712 | // meantime. |
| 6713 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6714 | GenerateReferenceLoadTwoRegisters( |
| 6715 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6716 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6717 | |
| 6718 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6719 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6720 | __ j(kEqual, &done); |
| 6721 | // Same comment as above regarding `temp` and the slow path. |
| 6722 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6723 | GenerateReferenceLoadTwoRegisters( |
| 6724 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6725 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6726 | break; |
| 6727 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6728 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6729 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6730 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6731 | // We always go into the type check slow path for the unresolved |
| 6732 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6733 | // |
| 6734 | // We cannot directly call the CheckCast runtime entry point |
| 6735 | // without resorting to a type checking slow path here (i.e. by |
| 6736 | // calling InvokeRuntime directly), as it would require to |
| 6737 | // assign fixed registers for the inputs of this HInstanceOf |
| 6738 | // instruction (following the runtime calling convention), which |
| 6739 | // might be cluttered by the potential first read barrier |
| 6740 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6741 | // |
| 6742 | // TODO: Introduce a new runtime entry point taking the object |
| 6743 | // to test (instead of its class) as argument, and let it deal |
| 6744 | // with the read barrier issues. This will let us refactor this |
| 6745 | // case of the `switch` code as it was previously (with a direct |
| 6746 | // call to the runtime not using a type checking slow path). |
| 6747 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6748 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6749 | break; |
| 6750 | } |
| 6751 | __ Bind(&done); |
| 6752 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6753 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6754 | } |
| 6755 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6756 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6757 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6758 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6759 | InvokeRuntimeCallingConvention calling_convention; |
| 6760 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6761 | } |
| 6762 | |
| 6763 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6764 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6765 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6766 | instruction, |
| 6767 | instruction->GetDexPc(), |
| 6768 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6769 | if (instruction->IsEnter()) { |
| 6770 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6771 | } else { |
| 6772 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6773 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6774 | } |
| 6775 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6776 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6777 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6778 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6779 | |
| 6780 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6781 | LocationSummary* locations = |
| 6782 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6783 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6784 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6785 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6786 | locations->SetInAt(1, Location::Any()); |
| 6787 | locations->SetOut(Location::SameAsFirstInput()); |
| 6788 | } |
| 6789 | |
| 6790 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6791 | HandleBitwiseOperation(instruction); |
| 6792 | } |
| 6793 | |
| 6794 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6795 | HandleBitwiseOperation(instruction); |
| 6796 | } |
| 6797 | |
| 6798 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6799 | HandleBitwiseOperation(instruction); |
| 6800 | } |
| 6801 | |
| 6802 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6803 | LocationSummary* locations = instruction->GetLocations(); |
| 6804 | Location first = locations->InAt(0); |
| 6805 | Location second = locations->InAt(1); |
| 6806 | DCHECK(first.Equals(locations->Out())); |
| 6807 | |
| 6808 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6809 | if (second.IsRegister()) { |
| 6810 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6811 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6812 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6813 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6814 | } else { |
| 6815 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6816 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6817 | } |
| 6818 | } else if (second.IsConstant()) { |
| 6819 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6820 | __ andl(first.AsRegister<Register>(), |
| 6821 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6822 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6823 | __ orl(first.AsRegister<Register>(), |
| 6824 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6825 | } else { |
| 6826 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6827 | __ xorl(first.AsRegister<Register>(), |
| 6828 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6829 | } |
| 6830 | } else { |
| 6831 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6832 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6833 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6834 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6835 | } else { |
| 6836 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6837 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6838 | } |
| 6839 | } |
| 6840 | } else { |
| 6841 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6842 | if (second.IsRegisterPair()) { |
| 6843 | if (instruction->IsAnd()) { |
| 6844 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6845 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6846 | } else if (instruction->IsOr()) { |
| 6847 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6848 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6849 | } else { |
| 6850 | DCHECK(instruction->IsXor()); |
| 6851 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6852 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6853 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6854 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6855 | if (instruction->IsAnd()) { |
| 6856 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6857 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6858 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6859 | } else if (instruction->IsOr()) { |
| 6860 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6861 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6862 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6863 | } else { |
| 6864 | DCHECK(instruction->IsXor()); |
| 6865 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6866 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6867 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6868 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6869 | } else { |
| 6870 | DCHECK(second.IsConstant()) << second; |
| 6871 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6872 | int32_t low_value = Low32Bits(value); |
| 6873 | int32_t high_value = High32Bits(value); |
| 6874 | Immediate low(low_value); |
| 6875 | Immediate high(high_value); |
| 6876 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6877 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6878 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6879 | if (low_value == 0) { |
| 6880 | __ xorl(first_low, first_low); |
| 6881 | } else if (low_value != -1) { |
| 6882 | __ andl(first_low, low); |
| 6883 | } |
| 6884 | if (high_value == 0) { |
| 6885 | __ xorl(first_high, first_high); |
| 6886 | } else if (high_value != -1) { |
| 6887 | __ andl(first_high, high); |
| 6888 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6889 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6890 | if (low_value != 0) { |
| 6891 | __ orl(first_low, low); |
| 6892 | } |
| 6893 | if (high_value != 0) { |
| 6894 | __ orl(first_high, high); |
| 6895 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6896 | } else { |
| 6897 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6898 | if (low_value != 0) { |
| 6899 | __ xorl(first_low, low); |
| 6900 | } |
| 6901 | if (high_value != 0) { |
| 6902 | __ xorl(first_high, high); |
| 6903 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6904 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6905 | } |
| 6906 | } |
| 6907 | } |
| 6908 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6909 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6910 | Location out, |
| 6911 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6912 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6913 | Register out_reg = out.AsRegister<Register>(); |
| 6914 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6915 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6916 | if (kUseBakerReadBarrier) { |
| 6917 | // Load with fast path based Baker's read barrier. |
| 6918 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6919 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6920 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6921 | } else { |
| 6922 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6923 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6924 | // in the following move operation, as we will need it for the |
| 6925 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6926 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6927 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6928 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6929 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6930 | } |
| 6931 | } else { |
| 6932 | // Plain load with no read barrier. |
| 6933 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6934 | __ movl(out_reg, Address(out_reg, offset)); |
| 6935 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6936 | } |
| 6937 | } |
| 6938 | |
| 6939 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6940 | Location out, |
| 6941 | Location obj, |
| 6942 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6943 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6944 | Register out_reg = out.AsRegister<Register>(); |
| 6945 | Register obj_reg = obj.AsRegister<Register>(); |
| 6946 | if (kEmitCompilerReadBarrier) { |
| 6947 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6948 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6949 | // Load with fast path based Baker's read barrier. |
| 6950 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6951 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6952 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6953 | } else { |
| 6954 | // Load with slow path based read barrier. |
| 6955 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6956 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6957 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6958 | } |
| 6959 | } else { |
| 6960 | // Plain load with no read barrier. |
| 6961 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6962 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6963 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6964 | } |
| 6965 | } |
| 6966 | |
| 6967 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6968 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6969 | const Address& address, |
| 6970 | Label* fixup_label) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6971 | Register root_reg = root.AsRegister<Register>(); |
| 6972 | if (kEmitCompilerReadBarrier) { |
| 6973 | if (kUseBakerReadBarrier) { |
| 6974 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6975 | // Baker's read barrier are used: |
| 6976 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6977 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6978 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6979 | // root = ReadBarrier::Mark(root) |
| 6980 | // } |
| 6981 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6982 | // /* GcRoot<mirror::Object> */ root = *address |
| 6983 | __ movl(root_reg, address); |
| 6984 | if (fixup_label != nullptr) { |
| 6985 | __ Bind(fixup_label); |
| 6986 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6987 | static_assert( |
| 6988 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6989 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6990 | "have different sizes."); |
| 6991 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6992 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6993 | "have different sizes."); |
| 6994 | |
| 6995 | // Slow path used to mark the GC root `root`. |
| 6996 | SlowPathCode* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 6997 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6998 | codegen_->AddSlowPath(slow_path); |
| 6999 | |
| 7000 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 7001 | Immediate(0)); |
| 7002 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7003 | __ Bind(slow_path->GetExitLabel()); |
| 7004 | } else { |
| 7005 | // GC root loaded through a slow path for read barriers other |
| 7006 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7007 | // /* GcRoot<mirror::Object>* */ root = address |
| 7008 | __ leal(root_reg, address); |
| 7009 | if (fixup_label != nullptr) { |
| 7010 | __ Bind(fixup_label); |
| 7011 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7012 | // /* mirror::Object* */ root = root->Read() |
| 7013 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7014 | } |
| 7015 | } else { |
| 7016 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7017 | // /* GcRoot<mirror::Object> */ root = *address |
| 7018 | __ movl(root_reg, address); |
| 7019 | if (fixup_label != nullptr) { |
| 7020 | __ Bind(fixup_label); |
| 7021 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7022 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7023 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7024 | } |
| 7025 | } |
| 7026 | |
| 7027 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7028 | Location ref, |
| 7029 | Register obj, |
| 7030 | uint32_t offset, |
| 7031 | Location temp, |
| 7032 | bool needs_null_check) { |
| 7033 | DCHECK(kEmitCompilerReadBarrier); |
| 7034 | DCHECK(kUseBakerReadBarrier); |
| 7035 | |
| 7036 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7037 | Address src(obj, offset); |
| 7038 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 7039 | } |
| 7040 | |
| 7041 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7042 | Location ref, |
| 7043 | Register obj, |
| 7044 | uint32_t data_offset, |
| 7045 | Location index, |
| 7046 | Location temp, |
| 7047 | bool needs_null_check) { |
| 7048 | DCHECK(kEmitCompilerReadBarrier); |
| 7049 | DCHECK(kUseBakerReadBarrier); |
| 7050 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7051 | static_assert( |
| 7052 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7053 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7054 | // /* HeapReference<Object> */ ref = |
| 7055 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 7056 | Address src = index.IsConstant() ? |
| 7057 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 7058 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 7059 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 7060 | } |
| 7061 | |
| 7062 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7063 | Location ref, |
| 7064 | Register obj, |
| 7065 | const Address& src, |
| 7066 | Location temp, |
| 7067 | bool needs_null_check) { |
| 7068 | DCHECK(kEmitCompilerReadBarrier); |
| 7069 | DCHECK(kUseBakerReadBarrier); |
| 7070 | |
| 7071 | // In slow path based read barriers, the read barrier call is |
| 7072 | // inserted after the original load. However, in fast path based |
| 7073 | // Baker's read barriers, we need to perform the load of |
| 7074 | // mirror::Object::monitor_ *before* the original reference load. |
| 7075 | // This load-load ordering is required by the read barrier. |
| 7076 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7077 | // |
| 7078 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7079 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7080 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7081 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 7082 | // if (is_gray) { |
| 7083 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7084 | // } |
| 7085 | // |
| 7086 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7087 | // slightly more complex as: |
| 7088 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7089 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7090 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7091 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7092 | // - it performs additional checks that we do not do here for |
| 7093 | // performance reasons. |
| 7094 | |
| 7095 | Register ref_reg = ref.AsRegister<Register>(); |
| 7096 | Register temp_reg = temp.AsRegister<Register>(); |
| 7097 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7098 | |
| 7099 | // /* int32_t */ monitor = obj->monitor_ |
| 7100 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 7101 | if (needs_null_check) { |
| 7102 | MaybeRecordImplicitNullCheck(instruction); |
| 7103 | } |
| 7104 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7105 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7106 | "art::LockWord and int32_t have different sizes."); |
| 7107 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 7108 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 7109 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 7110 | static_assert( |
| 7111 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 7112 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 7113 | |
| 7114 | // Load fence to prevent load-load reordering. |
| 7115 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7116 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7117 | |
| 7118 | // The actual reference load. |
| 7119 | // /* HeapReference<Object> */ ref = *src |
| 7120 | __ movl(ref_reg, src); |
| 7121 | |
| 7122 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7123 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7124 | |
| 7125 | // Slow path used to mark the object `ref` when it is gray. |
| 7126 | SlowPathCode* slow_path = |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 7127 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7128 | AddSlowPath(slow_path); |
| 7129 | |
| 7130 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 7131 | // ref = ReadBarrier::Mark(ref); |
| 7132 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 7133 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7134 | __ Bind(slow_path->GetExitLabel()); |
| 7135 | } |
| 7136 | |
| 7137 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7138 | Location out, |
| 7139 | Location ref, |
| 7140 | Location obj, |
| 7141 | uint32_t offset, |
| 7142 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7143 | DCHECK(kEmitCompilerReadBarrier); |
| 7144 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7145 | // Insert a slow path based read barrier *after* the reference load. |
| 7146 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7147 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7148 | // reference will be carried out by the runtime within the slow |
| 7149 | // path. |
| 7150 | // |
| 7151 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7152 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7153 | // not used by the artReadBarrierSlow entry point. |
| 7154 | // |
| 7155 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7156 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7157 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7158 | AddSlowPath(slow_path); |
| 7159 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7160 | __ jmp(slow_path->GetEntryLabel()); |
| 7161 | __ Bind(slow_path->GetExitLabel()); |
| 7162 | } |
| 7163 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7164 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7165 | Location out, |
| 7166 | Location ref, |
| 7167 | Location obj, |
| 7168 | uint32_t offset, |
| 7169 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7170 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7171 | // Baker's read barriers shall be handled by the fast path |
| 7172 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7173 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7174 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7175 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7176 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7177 | } else if (kPoisonHeapReferences) { |
| 7178 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7179 | } |
| 7180 | } |
| 7181 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7182 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7183 | Location out, |
| 7184 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7185 | DCHECK(kEmitCompilerReadBarrier); |
| 7186 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7187 | // Insert a slow path based read barrier *after* the GC root load. |
| 7188 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7189 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7190 | // not need to do anything special for this here. |
| 7191 | SlowPathCode* slow_path = |
| 7192 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7193 | AddSlowPath(slow_path); |
| 7194 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7195 | __ jmp(slow_path->GetEntryLabel()); |
| 7196 | __ Bind(slow_path->GetExitLabel()); |
| 7197 | } |
| 7198 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7199 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7200 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7201 | LOG(FATAL) << "Unreachable"; |
| 7202 | } |
| 7203 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7204 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7205 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7206 | LOG(FATAL) << "Unreachable"; |
| 7207 | } |
| 7208 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7209 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7210 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7211 | LocationSummary* locations = |
| 7212 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7213 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7214 | } |
| 7215 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7216 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7217 | int32_t lower_bound, |
| 7218 | uint32_t num_entries, |
| 7219 | HBasicBlock* switch_block, |
| 7220 | HBasicBlock* default_block) { |
| 7221 | // Figure out the correct compare values and jump conditions. |
| 7222 | // Handle the first compare/branch as a special case because it might |
| 7223 | // jump to the default case. |
| 7224 | DCHECK_GT(num_entries, 2u); |
| 7225 | Condition first_condition; |
| 7226 | uint32_t index; |
| 7227 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7228 | if (lower_bound != 0) { |
| 7229 | first_condition = kLess; |
| 7230 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7231 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7232 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7233 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7234 | index = 1; |
| 7235 | } else { |
| 7236 | // Handle all the compare/jumps below. |
| 7237 | first_condition = kBelow; |
| 7238 | index = 0; |
| 7239 | } |
| 7240 | |
| 7241 | // Handle the rest of the compare/jumps. |
| 7242 | for (; index + 1 < num_entries; index += 2) { |
| 7243 | int32_t compare_to_value = lower_bound + index + 1; |
| 7244 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7245 | // Jump to successors[index] if value < case_value[index]. |
| 7246 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7247 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7248 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7249 | } |
| 7250 | |
| 7251 | if (index != num_entries) { |
| 7252 | // There are an odd number of entries. Handle the last one. |
| 7253 | DCHECK_EQ(index + 1, num_entries); |
| 7254 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7255 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7256 | } |
| 7257 | |
| 7258 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7259 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7260 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7261 | } |
| 7262 | } |
| 7263 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7264 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7265 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7266 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7267 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7268 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7269 | |
| 7270 | GenPackedSwitchWithCompares(value_reg, |
| 7271 | lower_bound, |
| 7272 | num_entries, |
| 7273 | switch_instr->GetBlock(), |
| 7274 | switch_instr->GetDefaultBlock()); |
| 7275 | } |
| 7276 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7277 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7278 | LocationSummary* locations = |
| 7279 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7280 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7281 | |
| 7282 | // Constant area pointer. |
| 7283 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7284 | |
| 7285 | // And the temporary we need. |
| 7286 | locations->AddTemp(Location::RequiresRegister()); |
| 7287 | } |
| 7288 | |
| 7289 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7290 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7291 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7292 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7293 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7294 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7295 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7296 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7297 | GenPackedSwitchWithCompares(value_reg, |
| 7298 | lower_bound, |
| 7299 | num_entries, |
| 7300 | switch_instr->GetBlock(), |
| 7301 | default_block); |
| 7302 | return; |
| 7303 | } |
| 7304 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7305 | // Optimizing has a jump area. |
| 7306 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7307 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7308 | |
| 7309 | // Remove the bias, if needed. |
| 7310 | if (lower_bound != 0) { |
| 7311 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7312 | value_reg = temp_reg; |
| 7313 | } |
| 7314 | |
| 7315 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7316 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7317 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7318 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7319 | |
| 7320 | // We are in the range of the table. |
| 7321 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7322 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7323 | |
| 7324 | // Compute the actual target address by adding in constant_area. |
| 7325 | __ addl(temp_reg, constant_area); |
| 7326 | |
| 7327 | // And jump. |
| 7328 | __ jmp(temp_reg); |
| 7329 | } |
| 7330 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7331 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7332 | HX86ComputeBaseMethodAddress* insn) { |
| 7333 | LocationSummary* locations = |
| 7334 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7335 | locations->SetOut(Location::RequiresRegister()); |
| 7336 | } |
| 7337 | |
| 7338 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7339 | HX86ComputeBaseMethodAddress* insn) { |
| 7340 | LocationSummary* locations = insn->GetLocations(); |
| 7341 | Register reg = locations->Out().AsRegister<Register>(); |
| 7342 | |
| 7343 | // Generate call to next instruction. |
| 7344 | Label next_instruction; |
| 7345 | __ call(&next_instruction); |
| 7346 | __ Bind(&next_instruction); |
| 7347 | |
| 7348 | // Remember this offset for later use with constant area. |
| 7349 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7350 | |
| 7351 | // Grab the return address off the stack. |
| 7352 | __ popl(reg); |
| 7353 | } |
| 7354 | |
| 7355 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7356 | HX86LoadFromConstantTable* insn) { |
| 7357 | LocationSummary* locations = |
| 7358 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7359 | |
| 7360 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7361 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7362 | |
| 7363 | // If we don't need to be materialized, we only need the inputs to be set. |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7364 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7365 | return; |
| 7366 | } |
| 7367 | |
| 7368 | switch (insn->GetType()) { |
| 7369 | case Primitive::kPrimFloat: |
| 7370 | case Primitive::kPrimDouble: |
| 7371 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7372 | break; |
| 7373 | |
| 7374 | case Primitive::kPrimInt: |
| 7375 | locations->SetOut(Location::RequiresRegister()); |
| 7376 | break; |
| 7377 | |
| 7378 | default: |
| 7379 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7380 | } |
| 7381 | } |
| 7382 | |
| 7383 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7384 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7385 | return; |
| 7386 | } |
| 7387 | |
| 7388 | LocationSummary* locations = insn->GetLocations(); |
| 7389 | Location out = locations->Out(); |
| 7390 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7391 | HConstant *value = insn->GetConstant(); |
| 7392 | |
| 7393 | switch (insn->GetType()) { |
| 7394 | case Primitive::kPrimFloat: |
| 7395 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7396 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7397 | break; |
| 7398 | |
| 7399 | case Primitive::kPrimDouble: |
| 7400 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7401 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7402 | break; |
| 7403 | |
| 7404 | case Primitive::kPrimInt: |
| 7405 | __ movl(out.AsRegister<Register>(), |
| 7406 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7407 | break; |
| 7408 | |
| 7409 | default: |
| 7410 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7411 | } |
| 7412 | } |
| 7413 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7414 | /** |
| 7415 | * Class to handle late fixup of offsets into constant area. |
| 7416 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7417 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7418 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7419 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7420 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7421 | |
| 7422 | protected: |
| 7423 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7424 | |
| 7425 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7426 | |
| 7427 | private: |
| 7428 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7429 | // Patch the correct offset for the instruction. The place to patch is the |
| 7430 | // last 4 bytes of the instruction. |
| 7431 | // The value to patch is the distance from the offset in the constant area |
| 7432 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7433 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7434 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7435 | |
| 7436 | // Patch in the right value. |
| 7437 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7438 | } |
| 7439 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7440 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7441 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7442 | }; |
| 7443 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7444 | /** |
| 7445 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7446 | * constant area. |
| 7447 | */ |
| 7448 | class JumpTableRIPFixup : public RIPFixup { |
| 7449 | public: |
| 7450 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7451 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7452 | |
| 7453 | void CreateJumpTable() { |
| 7454 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7455 | |
| 7456 | // Ensure that the reference to the jump table has the correct offset. |
| 7457 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7458 | SetOffset(offset_in_constant_table); |
| 7459 | |
| 7460 | // The label values in the jump table are computed relative to the |
| 7461 | // instruction addressing the constant area. |
| 7462 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7463 | |
| 7464 | // Populate the jump table with the correct values for the jump table. |
| 7465 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7466 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7467 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7468 | // The value that we want is the target offset - the position of the table. |
| 7469 | for (int32_t i = 0; i < num_entries; i++) { |
| 7470 | HBasicBlock* b = successors[i]; |
| 7471 | Label* l = codegen_->GetLabelOf(b); |
| 7472 | DCHECK(l->IsBound()); |
| 7473 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7474 | assembler->AppendInt32(offset_to_block); |
| 7475 | } |
| 7476 | } |
| 7477 | |
| 7478 | private: |
| 7479 | const HX86PackedSwitch* switch_instr_; |
| 7480 | }; |
| 7481 | |
| 7482 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7483 | // Generate the constant area if needed. |
| 7484 | X86Assembler* assembler = GetAssembler(); |
| 7485 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7486 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7487 | // byte values. |
| 7488 | assembler->Align(4, 0); |
| 7489 | constant_area_start_ = assembler->CodeSize(); |
| 7490 | |
| 7491 | // Populate any jump tables. |
| 7492 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7493 | jump_table->CreateJumpTable(); |
| 7494 | } |
| 7495 | |
| 7496 | // And now add the constant area to the generated code. |
| 7497 | assembler->AddConstantArea(); |
| 7498 | } |
| 7499 | |
| 7500 | // And finish up. |
| 7501 | CodeGenerator::Finalize(allocator); |
| 7502 | } |
| 7503 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7504 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7505 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7506 | return Address(reg, kDummy32BitOffset, fixup); |
| 7507 | } |
| 7508 | |
| 7509 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7510 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7511 | return Address(reg, kDummy32BitOffset, fixup); |
| 7512 | } |
| 7513 | |
| 7514 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7515 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7516 | return Address(reg, kDummy32BitOffset, fixup); |
| 7517 | } |
| 7518 | |
| 7519 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7520 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7521 | return Address(reg, kDummy32BitOffset, fixup); |
| 7522 | } |
| 7523 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7524 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7525 | if (value == 0) { |
| 7526 | __ xorl(dest, dest); |
| 7527 | } else { |
| 7528 | __ movl(dest, Immediate(value)); |
| 7529 | } |
| 7530 | } |
| 7531 | |
| 7532 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7533 | if (value == 0) { |
| 7534 | __ testl(dest, dest); |
| 7535 | } else { |
| 7536 | __ cmpl(dest, Immediate(value)); |
| 7537 | } |
| 7538 | } |
| 7539 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7540 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7541 | Register reg, |
| 7542 | Register value) { |
| 7543 | // Create a fixup to be used to create and address the jump table. |
| 7544 | JumpTableRIPFixup* table_fixup = |
| 7545 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7546 | |
| 7547 | // We have to populate the jump tables. |
| 7548 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7549 | |
| 7550 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7551 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7552 | } |
| 7553 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7554 | // TODO: target as memory. |
| 7555 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7556 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7557 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7558 | return; |
| 7559 | } |
| 7560 | |
| 7561 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7562 | |
| 7563 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7564 | if (target.Equals(return_loc)) { |
| 7565 | return; |
| 7566 | } |
| 7567 | |
| 7568 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7569 | // with the else branch. |
| 7570 | if (type == Primitive::kPrimLong) { |
| 7571 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7572 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7573 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7574 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7575 | } else { |
| 7576 | // Let the parallel move resolver take care of all of this. |
| 7577 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7578 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7579 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7580 | } |
| 7581 | } |
| 7582 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7583 | #undef __ |
| 7584 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7585 | } // namespace x86 |
| 7586 | } // namespace art |