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 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 50 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 51 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 52 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, 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 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 65 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 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()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 87 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 88 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 91 | bool IsFatal() const OVERRIDE { return true; } |
| 92 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 93 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 94 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 97 | }; |
| 98 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 99 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 101 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 102 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 104 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 106 | if (is_div_) { |
| 107 | __ negl(reg_); |
| 108 | } else { |
| 109 | __ movl(reg_, Immediate(0)); |
| 110 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | __ jmp(GetExitLabel()); |
| 112 | } |
| 113 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 114 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 115 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 116 | private: |
| 117 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 118 | bool is_div_; |
| 119 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 122 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 123 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 124 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 125 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 126 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 127 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 128 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 130 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 131 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 132 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 133 | // Live registers will be restored in the catch block if caught. |
| 134 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 135 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 136 | |
| 137 | // Are we using an array length from memory? |
| 138 | HInstruction* array_length = instruction_->InputAt(1); |
| 139 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 141 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 142 | // Load the array length into our temporary. |
| 143 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 144 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 145 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 146 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 147 | // Check for conflicts with index. |
| 148 | if (length_loc.Equals(locations->InAt(0))) { |
| 149 | // We know we aren't using parameter 2. |
| 150 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 151 | } |
| 152 | __ movl(length_loc.AsRegister<Register>(), array_len); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 153 | if (mirror::kUseStringCompression) { |
| 154 | __ andl(length_loc.AsRegister<Register>(), Immediate(INT32_MAX)); |
| 155 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 156 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 157 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 158 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 159 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 160 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 161 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 162 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 163 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 164 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 165 | ? kQuickThrowStringBounds |
| 166 | : kQuickThrowArrayBounds; |
| 167 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 168 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 169 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 172 | bool IsFatal() const OVERRIDE { return true; } |
| 173 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 174 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 175 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 176 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 178 | }; |
| 179 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 180 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 181 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 182 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 183 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 185 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 186 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 187 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 188 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 189 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 190 | if (successor_ == nullptr) { |
| 191 | __ jmp(GetReturnLabel()); |
| 192 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 193 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 194 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 197 | Label* GetReturnLabel() { |
| 198 | DCHECK(successor_ == nullptr); |
| 199 | return &return_label_; |
| 200 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 201 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 202 | HBasicBlock* GetSuccessor() const { |
| 203 | return successor_; |
| 204 | } |
| 205 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 206 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 207 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 208 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 209 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 210 | Label return_label_; |
| 211 | |
| 212 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 213 | }; |
| 214 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 215 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 216 | public: |
| 217 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 218 | |
| 219 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 220 | LocationSummary* locations = instruction_->GetLocations(); |
| 221 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 222 | |
| 223 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 224 | __ Bind(GetEntryLabel()); |
| 225 | SaveLiveRegisters(codegen, locations); |
| 226 | |
| 227 | InvokeRuntimeCallingConvention calling_convention; |
| 228 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 229 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); |
| 230 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 231 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 232 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 233 | RestoreLiveRegisters(codegen, locations); |
| 234 | |
| 235 | // Store the resolved String to the BSS entry. |
| 236 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 237 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 238 | locations->Out().AsRegister<Register>()); |
| 239 | Label* fixup_label = x86_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 240 | __ Bind(fixup_label); |
| 241 | |
| 242 | __ jmp(GetExitLabel()); |
| 243 | } |
| 244 | |
| 245 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 246 | |
| 247 | private: |
| 248 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 249 | }; |
| 250 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 251 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 252 | public: |
| 253 | LoadClassSlowPathX86(HLoadClass* cls, |
| 254 | HInstruction* at, |
| 255 | uint32_t dex_pc, |
| 256 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 257 | : 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] | 258 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 259 | } |
| 260 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 261 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 262 | LocationSummary* locations = at_->GetLocations(); |
| 263 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 264 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 265 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | |
| 267 | InvokeRuntimeCallingConvention calling_convention; |
| 268 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 269 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 270 | : kQuickInitializeType, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 271 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 272 | if (do_clinit_) { |
| 273 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 274 | } else { |
| 275 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 276 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | |
| 278 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 279 | Location out = locations->Out(); |
| 280 | if (out.IsValid()) { |
| 281 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 282 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 284 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 285 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | __ jmp(GetExitLabel()); |
| 287 | } |
| 288 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 289 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 290 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 291 | private: |
| 292 | // The class this slow path will load. |
| 293 | HLoadClass* const cls_; |
| 294 | |
| 295 | // The instruction where this slow path is happening. |
| 296 | // (Might be the load class or an initialization check). |
| 297 | HInstruction* const at_; |
| 298 | |
| 299 | // The dex PC of `at_`. |
| 300 | const uint32_t dex_pc_; |
| 301 | |
| 302 | // Whether to initialize the class. |
| 303 | const bool do_clinit_; |
| 304 | |
| 305 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 306 | }; |
| 307 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 308 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 309 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 310 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 311 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 313 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 314 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 315 | Location arg0, arg1; |
| 316 | if (instruction_->IsInstanceOf()) { |
| 317 | arg0 = locations->InAt(1); |
| 318 | arg1 = locations->Out(); |
| 319 | } else { |
| 320 | arg0 = locations->InAt(0); |
| 321 | arg1 = locations->InAt(1); |
| 322 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 323 | DCHECK(instruction_->IsCheckCast() |
| 324 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 325 | |
| 326 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 327 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 328 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 329 | if (!is_fatal_) { |
| 330 | SaveLiveRegisters(codegen, locations); |
| 331 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
| 333 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 334 | // move resolver. |
| 335 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 336 | x86_codegen->EmitParallelMoves(arg0, |
| 337 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 338 | Primitive::kPrimNot, |
| 339 | arg1, |
| 340 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 341 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 342 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 343 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 344 | instruction_, |
| 345 | instruction_->GetDexPc(), |
| 346 | this); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 347 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Class*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 348 | } else { |
| 349 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 350 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 351 | instruction_, |
| 352 | instruction_->GetDexPc(), |
| 353 | this); |
| 354 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | if (!is_fatal_) { |
| 358 | if (instruction_->IsInstanceOf()) { |
| 359 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 360 | } |
| 361 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 362 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | __ jmp(GetExitLabel()); |
| 364 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 367 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 368 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 369 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 370 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 371 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 372 | |
| 373 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 374 | }; |
| 375 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 376 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 377 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 378 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 379 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 380 | |
| 381 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 382 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 384 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 385 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 388 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 389 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 392 | }; |
| 393 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 394 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 395 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 396 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 397 | |
| 398 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 399 | LocationSummary* locations = instruction_->GetLocations(); |
| 400 | __ Bind(GetEntryLabel()); |
| 401 | SaveLiveRegisters(codegen, locations); |
| 402 | |
| 403 | InvokeRuntimeCallingConvention calling_convention; |
| 404 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 405 | parallel_move.AddMove( |
| 406 | locations->InAt(0), |
| 407 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 408 | Primitive::kPrimNot, |
| 409 | nullptr); |
| 410 | parallel_move.AddMove( |
| 411 | locations->InAt(1), |
| 412 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 413 | Primitive::kPrimInt, |
| 414 | nullptr); |
| 415 | parallel_move.AddMove( |
| 416 | locations->InAt(2), |
| 417 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 418 | Primitive::kPrimNot, |
| 419 | nullptr); |
| 420 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 421 | |
| 422 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 423 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 424 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 425 | RestoreLiveRegisters(codegen, locations); |
| 426 | __ jmp(GetExitLabel()); |
| 427 | } |
| 428 | |
| 429 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 430 | |
| 431 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 432 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 433 | }; |
| 434 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 435 | // Slow path marking an object reference `ref` during a read |
| 436 | // barrier. The field `obj.field` in the object `obj` holding this |
| 437 | // reference does not get updated by this slow path after marking (see |
| 438 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 439 | // |
| 440 | // This means that after the execution of this slow path, `ref` will |
| 441 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 442 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 443 | // probably still be a from-space reference (unless it gets updated by |
| 444 | // another thread, or if another thread installed another object |
| 445 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 446 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 447 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 448 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 449 | Location ref, |
| 450 | bool unpoison_ref_before_marking) |
| 451 | : SlowPathCode(instruction), |
| 452 | ref_(ref), |
| 453 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 454 | DCHECK(kEmitCompilerReadBarrier); |
| 455 | } |
| 456 | |
| 457 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 458 | |
| 459 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 460 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 461 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 462 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 463 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 464 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 465 | instruction_->IsStaticFieldGet() || |
| 466 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 467 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 468 | instruction_->IsLoadClass() || |
| 469 | instruction_->IsLoadString() || |
| 470 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 471 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 472 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 473 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 474 | << "Unexpected instruction in read barrier marking slow path: " |
| 475 | << instruction_->DebugName(); |
| 476 | |
| 477 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 478 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 479 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 480 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 481 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 482 | // No need to save live registers; it's taken care of by the |
| 483 | // entrypoint. Also, there is no need to update the stack mask, |
| 484 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 485 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 486 | DCHECK_NE(ref_reg, ESP); |
| 487 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 488 | // "Compact" slow path, saving two moves. |
| 489 | // |
| 490 | // Instead of using the standard runtime calling convention (input |
| 491 | // and output in EAX): |
| 492 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 493 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 494 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 495 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 496 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 498 | // of a dedicated entrypoint: |
| 499 | // |
| 500 | // rX <- ReadBarrierMarkRegX(rX) |
| 501 | // |
| 502 | int32_t entry_point_offset = |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 504 | // This runtime call does not require a stack map. |
| 505 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 506 | __ jmp(GetExitLabel()); |
| 507 | } |
| 508 | |
| 509 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | // The location (register) of the marked object reference. |
| 511 | const Location ref_; |
| 512 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 513 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 514 | |
| 515 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 516 | }; |
| 517 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 518 | // Slow path marking an object reference `ref` during a read barrier, |
| 519 | // and if needed, atomically updating the field `obj.field` in the |
| 520 | // object `obj` holding this reference after marking (contrary to |
| 521 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 522 | // `obj.field`). |
| 523 | // |
| 524 | // This means that after the execution of this slow path, both `ref` |
| 525 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 526 | // hold the same to-space reference (unless another thread installed |
| 527 | // another object reference (different from `ref`) in `obj.field`). |
| 528 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 529 | public: |
| 530 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 531 | Location ref, |
| 532 | Register obj, |
| 533 | const Address& field_addr, |
| 534 | bool unpoison_ref_before_marking, |
| 535 | Register temp) |
| 536 | : SlowPathCode(instruction), |
| 537 | ref_(ref), |
| 538 | obj_(obj), |
| 539 | field_addr_(field_addr), |
| 540 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 541 | temp_(temp) { |
| 542 | DCHECK(kEmitCompilerReadBarrier); |
| 543 | } |
| 544 | |
| 545 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 546 | |
| 547 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 548 | LocationSummary* locations = instruction_->GetLocations(); |
| 549 | Register ref_reg = ref_.AsRegister<Register>(); |
| 550 | DCHECK(locations->CanCall()); |
| 551 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 552 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 553 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 554 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 555 | << instruction_->DebugName(); |
| 556 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 557 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 558 | |
| 559 | __ Bind(GetEntryLabel()); |
| 560 | if (unpoison_ref_before_marking_) { |
| 561 | // Object* ref = ref_addr->AsMirrorPtr() |
| 562 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 563 | } |
| 564 | |
| 565 | // Save the old (unpoisoned) reference. |
| 566 | __ movl(temp_, ref_reg); |
| 567 | |
| 568 | // No need to save live registers; it's taken care of by the |
| 569 | // entrypoint. Also, there is no need to update the stack mask, |
| 570 | // as this runtime call will not trigger a garbage collection. |
| 571 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 572 | DCHECK_NE(ref_reg, ESP); |
| 573 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 574 | // "Compact" slow path, saving two moves. |
| 575 | // |
| 576 | // Instead of using the standard runtime calling convention (input |
| 577 | // and output in EAX): |
| 578 | // |
| 579 | // EAX <- ref |
| 580 | // EAX <- ReadBarrierMark(EAX) |
| 581 | // ref <- EAX |
| 582 | // |
| 583 | // we just use rX (the register containing `ref`) as input and output |
| 584 | // of a dedicated entrypoint: |
| 585 | // |
| 586 | // rX <- ReadBarrierMarkRegX(rX) |
| 587 | // |
| 588 | int32_t entry_point_offset = |
| 589 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| 590 | // This runtime call does not require a stack map. |
| 591 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 592 | |
| 593 | // If the new reference is different from the old reference, |
| 594 | // update the field in the holder (`*field_addr`). |
| 595 | // |
| 596 | // Note that this field could also hold a different object, if |
| 597 | // another thread had concurrently changed it. In that case, the |
| 598 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 599 | // operation below would abort the CAS, leaving the field as-is. |
| 600 | NearLabel done; |
| 601 | __ cmpl(temp_, ref_reg); |
| 602 | __ j(kEqual, &done); |
| 603 | |
| 604 | // Update the the holder's field atomically. This may fail if |
| 605 | // mutator updates before us, but it's OK. This is achieved |
| 606 | // using a strong compare-and-set (CAS) operation with relaxed |
| 607 | // memory synchronization ordering, where the expected value is |
| 608 | // the old reference and the desired value is the new reference. |
| 609 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 610 | // instruction, which requires the expected value (the old |
| 611 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 612 | // expected value (stored in `temp_`) into EAX. |
| 613 | __ pushl(EAX); |
| 614 | __ movl(EAX, temp_); |
| 615 | |
| 616 | // Convenience aliases. |
| 617 | Register base = obj_; |
| 618 | Register expected = EAX; |
| 619 | Register value = ref_reg; |
| 620 | |
| 621 | bool base_equals_value = (base == value); |
| 622 | if (kPoisonHeapReferences) { |
| 623 | if (base_equals_value) { |
| 624 | // If `base` and `value` are the same register location, move |
| 625 | // `value` to a temporary register. This way, poisoning |
| 626 | // `value` won't invalidate `base`. |
| 627 | value = temp_; |
| 628 | __ movl(value, base); |
| 629 | } |
| 630 | |
| 631 | // Check that the register allocator did not assign the location |
| 632 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 633 | // poisoning (when enabled) works as intended below. |
| 634 | // - If `value` were equal to `expected`, both references would |
| 635 | // be poisoned twice, meaning they would not be poisoned at |
| 636 | // all, as heap poisoning uses address negation. |
| 637 | // - If `base` were equal to `expected`, poisoning `expected` |
| 638 | // would invalidate `base`. |
| 639 | DCHECK_NE(value, expected); |
| 640 | DCHECK_NE(base, expected); |
| 641 | |
| 642 | __ PoisonHeapReference(expected); |
| 643 | __ PoisonHeapReference(value); |
| 644 | } |
| 645 | |
| 646 | __ LockCmpxchgl(field_addr_, value); |
| 647 | |
| 648 | // If heap poisoning is enabled, we need to unpoison the values |
| 649 | // that were poisoned earlier. |
| 650 | if (kPoisonHeapReferences) { |
| 651 | if (base_equals_value) { |
| 652 | // `value` has been moved to a temporary register, no need |
| 653 | // to unpoison it. |
| 654 | } else { |
| 655 | __ UnpoisonHeapReference(value); |
| 656 | } |
| 657 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 658 | } |
| 659 | |
| 660 | // Restore EAX. |
| 661 | __ popl(EAX); |
| 662 | |
| 663 | __ Bind(&done); |
| 664 | __ jmp(GetExitLabel()); |
| 665 | } |
| 666 | |
| 667 | private: |
| 668 | // The location (register) of the marked object reference. |
| 669 | const Location ref_; |
| 670 | // The register containing the object holding the marked object reference field. |
| 671 | const Register obj_; |
| 672 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 673 | const Address field_addr_; |
| 674 | |
| 675 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 676 | const bool unpoison_ref_before_marking_; |
| 677 | |
| 678 | const Register temp_; |
| 679 | |
| 680 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 681 | }; |
| 682 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 683 | // Slow path generating a read barrier for a heap reference. |
| 684 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 685 | public: |
| 686 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 687 | Location out, |
| 688 | Location ref, |
| 689 | Location obj, |
| 690 | uint32_t offset, |
| 691 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 692 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 693 | out_(out), |
| 694 | ref_(ref), |
| 695 | obj_(obj), |
| 696 | offset_(offset), |
| 697 | index_(index) { |
| 698 | DCHECK(kEmitCompilerReadBarrier); |
| 699 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 700 | // has been overwritten by (or after) the heap object reference load |
| 701 | // to be instrumented, e.g.: |
| 702 | // |
| 703 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 704 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 705 | // |
| 706 | // In that case, we have lost the information about the original |
| 707 | // object, and the emitted read barrier cannot work properly. |
| 708 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 709 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 710 | } |
| 711 | |
| 712 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 713 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 714 | LocationSummary* locations = instruction_->GetLocations(); |
| 715 | Register reg_out = out_.AsRegister<Register>(); |
| 716 | DCHECK(locations->CanCall()); |
| 717 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 718 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 719 | instruction_->IsStaticFieldGet() || |
| 720 | instruction_->IsArrayGet() || |
| 721 | instruction_->IsInstanceOf() || |
| 722 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 723 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 724 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 725 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 726 | |
| 727 | __ Bind(GetEntryLabel()); |
| 728 | SaveLiveRegisters(codegen, locations); |
| 729 | |
| 730 | // We may have to change the index's value, but as `index_` is a |
| 731 | // constant member (like other "inputs" of this slow path), |
| 732 | // introduce a copy of it, `index`. |
| 733 | Location index = index_; |
| 734 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 735 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 736 | if (instruction_->IsArrayGet()) { |
| 737 | // Compute the actual memory offset and store it in `index`. |
| 738 | Register index_reg = index_.AsRegister<Register>(); |
| 739 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 740 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 741 | // We are about to change the value of `index_reg` (see the |
| 742 | // calls to art::x86::X86Assembler::shll and |
| 743 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 744 | // not been saved by the previous call to |
| 745 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 746 | // callee-save register -- |
| 747 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 748 | // callee-save registers, as it has been designed with the |
| 749 | // assumption that callee-save registers are supposed to be |
| 750 | // handled by the called function. So, as a callee-save |
| 751 | // register, `index_reg` _would_ eventually be saved onto |
| 752 | // the stack, but it would be too late: we would have |
| 753 | // changed its value earlier. Therefore, we manually save |
| 754 | // it here into another freely available register, |
| 755 | // `free_reg`, chosen of course among the caller-save |
| 756 | // registers (as a callee-save `free_reg` register would |
| 757 | // exhibit the same problem). |
| 758 | // |
| 759 | // Note we could have requested a temporary register from |
| 760 | // the register allocator instead; but we prefer not to, as |
| 761 | // this is a slow path, and we know we can find a |
| 762 | // caller-save register that is available. |
| 763 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 764 | __ movl(free_reg, index_reg); |
| 765 | index_reg = free_reg; |
| 766 | index = Location::RegisterLocation(index_reg); |
| 767 | } else { |
| 768 | // The initial register stored in `index_` has already been |
| 769 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 770 | // (as it is not a callee-save register), so we can freely |
| 771 | // use it. |
| 772 | } |
| 773 | // Shifting the index value contained in `index_reg` by the scale |
| 774 | // factor (2) cannot overflow in practice, as the runtime is |
| 775 | // unable to allocate object arrays with a size larger than |
| 776 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 777 | __ shll(index_reg, Immediate(TIMES_4)); |
| 778 | static_assert( |
| 779 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 780 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 781 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 782 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 783 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 784 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 785 | // (as in the case of ArrayGet), as it is actually an offset |
| 786 | // to an object field within an object. |
| 787 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 788 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 789 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 790 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 791 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 792 | DCHECK_EQ(offset_, 0U); |
| 793 | DCHECK(index_.IsRegisterPair()); |
| 794 | // UnsafeGet's offset location is a register pair, the low |
| 795 | // part contains the correct offset. |
| 796 | index = index_.ToLow(); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | // We're moving two or three locations to locations that could |
| 801 | // overlap, so we need a parallel move resolver. |
| 802 | InvokeRuntimeCallingConvention calling_convention; |
| 803 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 804 | parallel_move.AddMove(ref_, |
| 805 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 806 | Primitive::kPrimNot, |
| 807 | nullptr); |
| 808 | parallel_move.AddMove(obj_, |
| 809 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 810 | Primitive::kPrimNot, |
| 811 | nullptr); |
| 812 | if (index.IsValid()) { |
| 813 | parallel_move.AddMove(index, |
| 814 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 815 | Primitive::kPrimInt, |
| 816 | nullptr); |
| 817 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 818 | } else { |
| 819 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 820 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 821 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 822 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 823 | CheckEntrypointTypes< |
| 824 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 825 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 826 | |
| 827 | RestoreLiveRegisters(codegen, locations); |
| 828 | __ jmp(GetExitLabel()); |
| 829 | } |
| 830 | |
| 831 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 832 | |
| 833 | private: |
| 834 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 835 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 836 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 837 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 838 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 839 | return static_cast<Register>(i); |
| 840 | } |
| 841 | } |
| 842 | // We shall never fail to find a free caller-save register, as |
| 843 | // there are more than two core caller-save registers on x86 |
| 844 | // (meaning it is possible to find one which is different from |
| 845 | // `ref` and `obj`). |
| 846 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 847 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 848 | UNREACHABLE(); |
| 849 | } |
| 850 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 851 | const Location out_; |
| 852 | const Location ref_; |
| 853 | const Location obj_; |
| 854 | const uint32_t offset_; |
| 855 | // An additional location containing an index to an array. |
| 856 | // Only used for HArrayGet and the UnsafeGetObject & |
| 857 | // UnsafeGetObjectVolatile intrinsics. |
| 858 | const Location index_; |
| 859 | |
| 860 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 861 | }; |
| 862 | |
| 863 | // Slow path generating a read barrier for a GC root. |
| 864 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 865 | public: |
| 866 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 867 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 868 | DCHECK(kEmitCompilerReadBarrier); |
| 869 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 870 | |
| 871 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 872 | LocationSummary* locations = instruction_->GetLocations(); |
| 873 | Register reg_out = out_.AsRegister<Register>(); |
| 874 | DCHECK(locations->CanCall()); |
| 875 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 876 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 877 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 878 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 879 | |
| 880 | __ Bind(GetEntryLabel()); |
| 881 | SaveLiveRegisters(codegen, locations); |
| 882 | |
| 883 | InvokeRuntimeCallingConvention calling_convention; |
| 884 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 885 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 886 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 887 | instruction_, |
| 888 | instruction_->GetDexPc(), |
| 889 | this); |
| 890 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 891 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 892 | |
| 893 | RestoreLiveRegisters(codegen, locations); |
| 894 | __ jmp(GetExitLabel()); |
| 895 | } |
| 896 | |
| 897 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 898 | |
| 899 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 900 | const Location out_; |
| 901 | const Location root_; |
| 902 | |
| 903 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 904 | }; |
| 905 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 906 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 907 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 908 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 909 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 910 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 911 | switch (cond) { |
| 912 | case kCondEQ: return kEqual; |
| 913 | case kCondNE: return kNotEqual; |
| 914 | case kCondLT: return kLess; |
| 915 | case kCondLE: return kLessEqual; |
| 916 | case kCondGT: return kGreater; |
| 917 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 918 | case kCondB: return kBelow; |
| 919 | case kCondBE: return kBelowEqual; |
| 920 | case kCondA: return kAbove; |
| 921 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 922 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 923 | LOG(FATAL) << "Unreachable"; |
| 924 | UNREACHABLE(); |
| 925 | } |
| 926 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 927 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 928 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 929 | switch (cond) { |
| 930 | case kCondEQ: return kEqual; |
| 931 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 932 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 933 | case kCondLT: return kBelow; |
| 934 | case kCondLE: return kBelowEqual; |
| 935 | case kCondGT: return kAbove; |
| 936 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 937 | // Unsigned remain unchanged. |
| 938 | case kCondB: return kBelow; |
| 939 | case kCondBE: return kBelowEqual; |
| 940 | case kCondA: return kAbove; |
| 941 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 942 | } |
| 943 | LOG(FATAL) << "Unreachable"; |
| 944 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 947 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 948 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 952 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 953 | } |
| 954 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 955 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 956 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 957 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 958 | } |
| 959 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 960 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 961 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 962 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 965 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 966 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 967 | return GetFloatingPointSpillSlotSize(); |
| 968 | } |
| 969 | |
| 970 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 971 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 972 | return GetFloatingPointSpillSlotSize(); |
| 973 | } |
| 974 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 975 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 976 | HInstruction* instruction, |
| 977 | uint32_t dex_pc, |
| 978 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 979 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 980 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 981 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 982 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 983 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 984 | } |
| 985 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 986 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 987 | HInstruction* instruction, |
| 988 | SlowPathCode* slow_path) { |
| 989 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 990 | GenerateInvokeRuntime(entry_point_offset); |
| 991 | } |
| 992 | |
| 993 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 994 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 995 | } |
| 996 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 997 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 998 | const X86InstructionSetFeatures& isa_features, |
| 999 | const CompilerOptions& compiler_options, |
| 1000 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1001 | : CodeGenerator(graph, |
| 1002 | kNumberOfCpuRegisters, |
| 1003 | kNumberOfXmmRegisters, |
| 1004 | kNumberOfRegisterPairs, |
| 1005 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1006 | arraysize(kCoreCalleeSaves)) |
| 1007 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1008 | 0, |
| 1009 | compiler_options, |
| 1010 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1011 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1012 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1013 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1014 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1015 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1016 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1017 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1018 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1019 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1020 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1021 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1022 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1023 | constant_area_start_(-1), |
| 1024 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1025 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1026 | // Use a fake return address register to mimic Quick. |
| 1027 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1028 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1029 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1030 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1031 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1032 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1035 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1036 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1037 | assembler_(codegen->GetAssembler()), |
| 1038 | codegen_(codegen) {} |
| 1039 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1040 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1041 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1044 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1045 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1046 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1047 | bool skip_overflow_check = |
| 1048 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1049 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1050 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1051 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1052 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1053 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1056 | if (HasEmptyFrame()) { |
| 1057 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1058 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1059 | |
| 1060 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1061 | Register reg = kCoreCalleeSaves[i]; |
| 1062 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1063 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1064 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1065 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1069 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1070 | __ subl(ESP, Immediate(adjust)); |
| 1071 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1072 | // Save the current method if we need it. Note that we do not |
| 1073 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1074 | // in the SSA graph. |
| 1075 | if (RequiresCurrentMethod()) { |
| 1076 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1077 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1081 | __ cfi().RememberState(); |
| 1082 | if (!HasEmptyFrame()) { |
| 1083 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1084 | __ addl(ESP, Immediate(adjust)); |
| 1085 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1086 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1087 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1088 | Register reg = kCoreCalleeSaves[i]; |
| 1089 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1090 | __ popl(reg); |
| 1091 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1092 | __ cfi().Restore(DWARFReg(reg)); |
| 1093 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1094 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1095 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1096 | __ ret(); |
| 1097 | __ cfi().RestoreState(); |
| 1098 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1101 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1102 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1105 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 1106 | switch (type) { |
| 1107 | case Primitive::kPrimBoolean: |
| 1108 | case Primitive::kPrimByte: |
| 1109 | case Primitive::kPrimChar: |
| 1110 | case Primitive::kPrimShort: |
| 1111 | case Primitive::kPrimInt: |
| 1112 | case Primitive::kPrimNot: |
| 1113 | return Location::RegisterLocation(EAX); |
| 1114 | |
| 1115 | case Primitive::kPrimLong: |
| 1116 | return Location::RegisterPairLocation(EAX, EDX); |
| 1117 | |
| 1118 | case Primitive::kPrimVoid: |
| 1119 | return Location::NoLocation(); |
| 1120 | |
| 1121 | case Primitive::kPrimDouble: |
| 1122 | case Primitive::kPrimFloat: |
| 1123 | return Location::FpuRegisterLocation(XMM0); |
| 1124 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1125 | |
| 1126 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1130 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1131 | } |
| 1132 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1133 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1134 | switch (type) { |
| 1135 | case Primitive::kPrimBoolean: |
| 1136 | case Primitive::kPrimByte: |
| 1137 | case Primitive::kPrimChar: |
| 1138 | case Primitive::kPrimShort: |
| 1139 | case Primitive::kPrimInt: |
| 1140 | case Primitive::kPrimNot: { |
| 1141 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1142 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1143 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1144 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1145 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1146 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1147 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1148 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1149 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1150 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1151 | uint32_t index = gp_index_; |
| 1152 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1153 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1154 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1155 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1156 | calling_convention.GetRegisterPairAt(index)); |
| 1157 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1158 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1159 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1164 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1165 | stack_index_++; |
| 1166 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1167 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1168 | } else { |
| 1169 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1174 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1175 | stack_index_ += 2; |
| 1176 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1177 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1178 | } else { |
| 1179 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1183 | case Primitive::kPrimVoid: |
| 1184 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1185 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1186 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1187 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1188 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1189 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1190 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1191 | if (source.Equals(destination)) { |
| 1192 | return; |
| 1193 | } |
| 1194 | if (destination.IsRegister()) { |
| 1195 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1196 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1197 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1198 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1199 | } else { |
| 1200 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1201 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1202 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1203 | } else if (destination.IsFpuRegister()) { |
| 1204 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1205 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1206 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1207 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1208 | } else { |
| 1209 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1210 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1211 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1212 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1213 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1214 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1215 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1216 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1217 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1218 | } else if (source.IsConstant()) { |
| 1219 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1220 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1221 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1222 | } else { |
| 1223 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1224 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1225 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1231 | if (source.Equals(destination)) { |
| 1232 | return; |
| 1233 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1234 | if (destination.IsRegisterPair()) { |
| 1235 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1236 | EmitParallelMoves( |
| 1237 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1238 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1239 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1240 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1241 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1242 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1243 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1244 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1245 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1246 | __ psrlq(src_reg, Immediate(32)); |
| 1247 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1248 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1249 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1250 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1251 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1252 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1253 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1254 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1255 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1256 | if (source.IsFpuRegister()) { |
| 1257 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1258 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1259 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1260 | } else if (source.IsRegisterPair()) { |
| 1261 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1262 | // Create stack space for 2 elements. |
| 1263 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1264 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1265 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1266 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1267 | // And remove the temporary stack space we allocated. |
| 1268 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1269 | } else { |
| 1270 | LOG(FATAL) << "Unimplemented"; |
| 1271 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1272 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1273 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1274 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1275 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1276 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1277 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1278 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1279 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1280 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1281 | } else if (source.IsConstant()) { |
| 1282 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1283 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1284 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1285 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1286 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1287 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1288 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1289 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1290 | EmitParallelMoves( |
| 1291 | Location::StackSlot(source.GetStackIndex()), |
| 1292 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1293 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1294 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1295 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1296 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1301 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1302 | DCHECK(location.IsRegister()); |
| 1303 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1304 | } |
| 1305 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1306 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1307 | HParallelMove move(GetGraph()->GetArena()); |
| 1308 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1309 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1310 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1311 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1312 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1313 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1314 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1318 | if (location.IsRegister()) { |
| 1319 | locations->AddTemp(location); |
| 1320 | } else if (location.IsRegisterPair()) { |
| 1321 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1322 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1323 | } else { |
| 1324 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1325 | } |
| 1326 | } |
| 1327 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1328 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1329 | DCHECK(!successor->IsExitBlock()); |
| 1330 | |
| 1331 | HBasicBlock* block = got->GetBlock(); |
| 1332 | HInstruction* previous = got->GetPrevious(); |
| 1333 | |
| 1334 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1335 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1336 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1337 | return; |
| 1338 | } |
| 1339 | |
| 1340 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1341 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1342 | } |
| 1343 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1344 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1348 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1349 | got->SetLocations(nullptr); |
| 1350 | } |
| 1351 | |
| 1352 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1353 | HandleGoto(got, got->GetSuccessor()); |
| 1354 | } |
| 1355 | |
| 1356 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1357 | try_boundary->SetLocations(nullptr); |
| 1358 | } |
| 1359 | |
| 1360 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1361 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1362 | if (!successor->IsExitBlock()) { |
| 1363 | HandleGoto(try_boundary, successor); |
| 1364 | } |
| 1365 | } |
| 1366 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1367 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1368 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1371 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1374 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1375 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1376 | LabelType* true_label, |
| 1377 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1378 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1379 | __ j(kUnordered, true_label); |
| 1380 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1381 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1382 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1383 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1384 | } |
| 1385 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1386 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1387 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1388 | LabelType* true_label, |
| 1389 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1390 | LocationSummary* locations = cond->GetLocations(); |
| 1391 | Location left = locations->InAt(0); |
| 1392 | Location right = locations->InAt(1); |
| 1393 | IfCondition if_cond = cond->GetCondition(); |
| 1394 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1395 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1396 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1397 | IfCondition true_high_cond = if_cond; |
| 1398 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1399 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1400 | |
| 1401 | // Set the conditions for the test, remembering that == needs to be |
| 1402 | // decided using the low words. |
| 1403 | switch (if_cond) { |
| 1404 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1405 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1406 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1407 | break; |
| 1408 | case kCondLT: |
| 1409 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1410 | break; |
| 1411 | case kCondLE: |
| 1412 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1413 | break; |
| 1414 | case kCondGT: |
| 1415 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1416 | break; |
| 1417 | case kCondGE: |
| 1418 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1419 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1420 | case kCondB: |
| 1421 | false_high_cond = kCondA; |
| 1422 | break; |
| 1423 | case kCondBE: |
| 1424 | true_high_cond = kCondB; |
| 1425 | break; |
| 1426 | case kCondA: |
| 1427 | false_high_cond = kCondB; |
| 1428 | break; |
| 1429 | case kCondAE: |
| 1430 | true_high_cond = kCondA; |
| 1431 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | if (right.IsConstant()) { |
| 1435 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1436 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1437 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1438 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1439 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1440 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1441 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1442 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1443 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1444 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1445 | __ j(X86Condition(true_high_cond), true_label); |
| 1446 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1447 | } |
| 1448 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1449 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1450 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1451 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1452 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1453 | |
| 1454 | __ cmpl(left_high, right_high); |
| 1455 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1456 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1457 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1458 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1459 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1460 | __ j(X86Condition(true_high_cond), true_label); |
| 1461 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1462 | } |
| 1463 | // Must be equal high, so compare the lows. |
| 1464 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1465 | } else { |
| 1466 | DCHECK(right.IsDoubleStackSlot()); |
| 1467 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1468 | if (if_cond == kCondNE) { |
| 1469 | __ j(X86Condition(true_high_cond), true_label); |
| 1470 | } else if (if_cond == kCondEQ) { |
| 1471 | __ j(X86Condition(false_high_cond), false_label); |
| 1472 | } else { |
| 1473 | __ j(X86Condition(true_high_cond), true_label); |
| 1474 | __ j(X86Condition(false_high_cond), false_label); |
| 1475 | } |
| 1476 | // Must be equal high, so compare the lows. |
| 1477 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1478 | } |
| 1479 | // The last comparison might be unsigned. |
| 1480 | __ j(final_condition, true_label); |
| 1481 | } |
| 1482 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1483 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1484 | Location rhs, |
| 1485 | HInstruction* insn, |
| 1486 | bool is_double) { |
| 1487 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1488 | if (is_double) { |
| 1489 | if (rhs.IsFpuRegister()) { |
| 1490 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1491 | } else if (const_area != nullptr) { |
| 1492 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1493 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1494 | codegen_->LiteralDoubleAddress( |
| 1495 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1496 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1497 | } else { |
| 1498 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1499 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1500 | } |
| 1501 | } else { |
| 1502 | if (rhs.IsFpuRegister()) { |
| 1503 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1504 | } else if (const_area != nullptr) { |
| 1505 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1506 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1507 | codegen_->LiteralFloatAddress( |
| 1508 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1509 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1510 | } else { |
| 1511 | DCHECK(rhs.IsStackSlot()); |
| 1512 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1513 | } |
| 1514 | } |
| 1515 | } |
| 1516 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1517 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1518 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1519 | LabelType* true_target_in, |
| 1520 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1521 | // Generated branching requires both targets to be explicit. If either of the |
| 1522 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1523 | LabelType fallthrough_target; |
| 1524 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1525 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1526 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1527 | LocationSummary* locations = condition->GetLocations(); |
| 1528 | Location left = locations->InAt(0); |
| 1529 | Location right = locations->InAt(1); |
| 1530 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1531 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1532 | switch (type) { |
| 1533 | case Primitive::kPrimLong: |
| 1534 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1535 | break; |
| 1536 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1537 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1538 | GenerateFPJumps(condition, true_target, false_target); |
| 1539 | break; |
| 1540 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1541 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1542 | GenerateFPJumps(condition, true_target, false_target); |
| 1543 | break; |
| 1544 | default: |
| 1545 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1546 | } |
| 1547 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1548 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1549 | __ jmp(false_target); |
| 1550 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1551 | |
| 1552 | if (fallthrough_target.IsLinked()) { |
| 1553 | __ Bind(&fallthrough_target); |
| 1554 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1555 | } |
| 1556 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1557 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1558 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1559 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1560 | // conditions if they are materialized due to the complex branching. |
| 1561 | return cond->IsCondition() && |
| 1562 | cond->GetNext() == branch && |
| 1563 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1564 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1565 | } |
| 1566 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1567 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1568 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1569 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1570 | LabelType* true_target, |
| 1571 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1572 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1573 | |
| 1574 | if (true_target == nullptr && false_target == nullptr) { |
| 1575 | // Nothing to do. The code always falls through. |
| 1576 | return; |
| 1577 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1578 | // Constant condition, statically compared against "true" (integer value 1). |
| 1579 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1580 | if (true_target != nullptr) { |
| 1581 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1582 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1583 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1584 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1585 | if (false_target != nullptr) { |
| 1586 | __ jmp(false_target); |
| 1587 | } |
| 1588 | } |
| 1589 | return; |
| 1590 | } |
| 1591 | |
| 1592 | // The following code generates these patterns: |
| 1593 | // (1) true_target == nullptr && false_target != nullptr |
| 1594 | // - opposite condition true => branch to false_target |
| 1595 | // (2) true_target != nullptr && false_target == nullptr |
| 1596 | // - condition true => branch to true_target |
| 1597 | // (3) true_target != nullptr && false_target != nullptr |
| 1598 | // - condition true => branch to true_target |
| 1599 | // - branch to false_target |
| 1600 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1601 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1602 | if (true_target == nullptr) { |
| 1603 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1604 | } else { |
| 1605 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1606 | } |
| 1607 | } else { |
| 1608 | // Materialized condition, compare against 0. |
| 1609 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1610 | if (lhs.IsRegister()) { |
| 1611 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1612 | } else { |
| 1613 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1614 | } |
| 1615 | if (true_target == nullptr) { |
| 1616 | __ j(kEqual, false_target); |
| 1617 | } else { |
| 1618 | __ j(kNotEqual, true_target); |
| 1619 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1620 | } |
| 1621 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1622 | // Condition has not been materialized, use its inputs as the comparison and |
| 1623 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1624 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1625 | |
| 1626 | // If this is a long or FP comparison that has been folded into |
| 1627 | // the HCondition, generate the comparison directly. |
| 1628 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1629 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1630 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1631 | return; |
| 1632 | } |
| 1633 | |
| 1634 | Location lhs = condition->GetLocations()->InAt(0); |
| 1635 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1636 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1637 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1638 | if (true_target == nullptr) { |
| 1639 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1640 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1641 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1642 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1643 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1644 | |
| 1645 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1646 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1647 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1648 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1649 | } |
| 1650 | } |
| 1651 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1652 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1653 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1654 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1655 | locations->SetInAt(0, Location::Any()); |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1660 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1661 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1662 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1663 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1664 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1665 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1666 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1670 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1671 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1672 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1673 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1674 | locations->SetInAt(0, Location::Any()); |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1679 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1680 | GenerateTestAndBranch<Label>(deoptimize, |
| 1681 | /* condition_input_index */ 0, |
| 1682 | slow_path->GetEntryLabel(), |
| 1683 | /* false_target */ nullptr); |
| 1684 | } |
| 1685 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1686 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1687 | // There are no conditional move instructions for XMMs. |
| 1688 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1689 | return false; |
| 1690 | } |
| 1691 | |
| 1692 | // A FP condition doesn't generate the single CC that we need. |
| 1693 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1694 | HInstruction* condition = select->GetCondition(); |
| 1695 | if (condition->IsCondition()) { |
| 1696 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1697 | if (compare_type == Primitive::kPrimLong || |
| 1698 | Primitive::IsFloatingPointType(compare_type)) { |
| 1699 | return false; |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | // We can generate a CMOV for this Select. |
| 1704 | return true; |
| 1705 | } |
| 1706 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1707 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1708 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1709 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1710 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1711 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1712 | } else { |
| 1713 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1714 | if (SelectCanUseCMOV(select)) { |
| 1715 | if (select->InputAt(1)->IsConstant()) { |
| 1716 | // Cmov can't handle a constant value. |
| 1717 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1718 | } else { |
| 1719 | locations->SetInAt(1, Location::Any()); |
| 1720 | } |
| 1721 | } else { |
| 1722 | locations->SetInAt(1, Location::Any()); |
| 1723 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1724 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1725 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1726 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1727 | } |
| 1728 | locations->SetOut(Location::SameAsFirstInput()); |
| 1729 | } |
| 1730 | |
| 1731 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1732 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1733 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1734 | if (SelectCanUseCMOV(select)) { |
| 1735 | // If both the condition and the source types are integer, we can generate |
| 1736 | // a CMOV to implement Select. |
| 1737 | |
| 1738 | HInstruction* select_condition = select->GetCondition(); |
| 1739 | Condition cond = kNotEqual; |
| 1740 | |
| 1741 | // Figure out how to test the 'condition'. |
| 1742 | if (select_condition->IsCondition()) { |
| 1743 | HCondition* condition = select_condition->AsCondition(); |
| 1744 | if (!condition->IsEmittedAtUseSite()) { |
| 1745 | // This was a previously materialized condition. |
| 1746 | // Can we use the existing condition code? |
| 1747 | if (AreEflagsSetFrom(condition, select)) { |
| 1748 | // Materialization was the previous instruction. Condition codes are right. |
| 1749 | cond = X86Condition(condition->GetCondition()); |
| 1750 | } else { |
| 1751 | // No, we have to recreate the condition code. |
| 1752 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1753 | __ testl(cond_reg, cond_reg); |
| 1754 | } |
| 1755 | } else { |
| 1756 | // We can't handle FP or long here. |
| 1757 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1758 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1759 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1760 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1761 | cond = X86Condition(condition->GetCondition()); |
| 1762 | } |
| 1763 | } else { |
| 1764 | // Must be a boolean condition, which needs to be compared to 0. |
| 1765 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1766 | __ testl(cond_reg, cond_reg); |
| 1767 | } |
| 1768 | |
| 1769 | // If the condition is true, overwrite the output, which already contains false. |
| 1770 | Location false_loc = locations->InAt(0); |
| 1771 | Location true_loc = locations->InAt(1); |
| 1772 | if (select->GetType() == Primitive::kPrimLong) { |
| 1773 | // 64 bit conditional move. |
| 1774 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1775 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1776 | if (true_loc.IsRegisterPair()) { |
| 1777 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1778 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1779 | } else { |
| 1780 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1781 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1782 | } |
| 1783 | } else { |
| 1784 | // 32 bit conditional move. |
| 1785 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1786 | if (true_loc.IsRegister()) { |
| 1787 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1788 | } else { |
| 1789 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1790 | } |
| 1791 | } |
| 1792 | } else { |
| 1793 | NearLabel false_target; |
| 1794 | GenerateTestAndBranch<NearLabel>( |
| 1795 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1796 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1797 | __ Bind(&false_target); |
| 1798 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1801 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1802 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1803 | } |
| 1804 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1805 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1806 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void CodeGeneratorX86::GenerateNop() { |
| 1810 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1813 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1814 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1815 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1816 | // Handle the long/FP comparisons made in instruction simplification. |
| 1817 | switch (cond->InputAt(0)->GetType()) { |
| 1818 | case Primitive::kPrimLong: { |
| 1819 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1820 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1821 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1822 | locations->SetOut(Location::RequiresRegister()); |
| 1823 | } |
| 1824 | break; |
| 1825 | } |
| 1826 | case Primitive::kPrimFloat: |
| 1827 | case Primitive::kPrimDouble: { |
| 1828 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1829 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1830 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1831 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1832 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1833 | } else { |
| 1834 | locations->SetInAt(1, Location::Any()); |
| 1835 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1836 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1837 | locations->SetOut(Location::RequiresRegister()); |
| 1838 | } |
| 1839 | break; |
| 1840 | } |
| 1841 | default: |
| 1842 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1843 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1844 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1845 | // We need a byte register. |
| 1846 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1847 | } |
| 1848 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1849 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1852 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1853 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1854 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1855 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1856 | |
| 1857 | LocationSummary* locations = cond->GetLocations(); |
| 1858 | Location lhs = locations->InAt(0); |
| 1859 | Location rhs = locations->InAt(1); |
| 1860 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1861 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1862 | |
| 1863 | switch (cond->InputAt(0)->GetType()) { |
| 1864 | default: { |
| 1865 | // Integer case. |
| 1866 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1867 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1868 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1869 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1870 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1871 | return; |
| 1872 | } |
| 1873 | case Primitive::kPrimLong: |
| 1874 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1875 | break; |
| 1876 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1877 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1878 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1879 | break; |
| 1880 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1881 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1882 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1883 | break; |
| 1884 | } |
| 1885 | |
| 1886 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1887 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1888 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1889 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1890 | __ Bind(&false_label); |
| 1891 | __ xorl(reg, reg); |
| 1892 | __ jmp(&done_label); |
| 1893 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1894 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1895 | __ Bind(&true_label); |
| 1896 | __ movl(reg, Immediate(1)); |
| 1897 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1901 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1905 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1909 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1913 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1917 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1921 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1925 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1929 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1933 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1937 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1941 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1945 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1948 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1949 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1953 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1957 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1961 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1965 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1969 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1973 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1977 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1980 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1981 | LocationSummary* locations = |
| 1982 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1983 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1984 | } |
| 1985 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1986 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1987 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1990 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1991 | LocationSummary* locations = |
| 1992 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1993 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1994 | } |
| 1995 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1996 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1997 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2000 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2001 | LocationSummary* locations = |
| 2002 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2003 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2004 | } |
| 2005 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2006 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2007 | // Will be generated at use site. |
| 2008 | } |
| 2009 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2010 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2011 | LocationSummary* locations = |
| 2012 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2013 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2014 | } |
| 2015 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2016 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2017 | // Will be generated at use site. |
| 2018 | } |
| 2019 | |
| 2020 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2021 | LocationSummary* locations = |
| 2022 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2023 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2024 | } |
| 2025 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2026 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2027 | // Will be generated at use site. |
| 2028 | } |
| 2029 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2030 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2031 | memory_barrier->SetLocations(nullptr); |
| 2032 | } |
| 2033 | |
| 2034 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2035 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2036 | } |
| 2037 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2038 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2039 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2042 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2043 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2046 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2047 | LocationSummary* locations = |
| 2048 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2049 | switch (ret->InputAt(0)->GetType()) { |
| 2050 | case Primitive::kPrimBoolean: |
| 2051 | case Primitive::kPrimByte: |
| 2052 | case Primitive::kPrimChar: |
| 2053 | case Primitive::kPrimShort: |
| 2054 | case Primitive::kPrimInt: |
| 2055 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2056 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2057 | break; |
| 2058 | |
| 2059 | case Primitive::kPrimLong: |
| 2060 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2061 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2062 | break; |
| 2063 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2064 | case Primitive::kPrimFloat: |
| 2065 | case Primitive::kPrimDouble: |
| 2066 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2067 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2068 | break; |
| 2069 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2070 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2071 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2072 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2075 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2076 | if (kIsDebugBuild) { |
| 2077 | switch (ret->InputAt(0)->GetType()) { |
| 2078 | case Primitive::kPrimBoolean: |
| 2079 | case Primitive::kPrimByte: |
| 2080 | case Primitive::kPrimChar: |
| 2081 | case Primitive::kPrimShort: |
| 2082 | case Primitive::kPrimInt: |
| 2083 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2084 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2085 | break; |
| 2086 | |
| 2087 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2088 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2089 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2090 | break; |
| 2091 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2092 | case Primitive::kPrimFloat: |
| 2093 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2094 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2095 | break; |
| 2096 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2097 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2098 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2099 | } |
| 2100 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2101 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2104 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2105 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2106 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2107 | // the method_idx. |
| 2108 | HandleInvoke(invoke); |
| 2109 | } |
| 2110 | |
| 2111 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2112 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2113 | } |
| 2114 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2115 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2116 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2117 | // art::PrepareForRegisterAllocation. |
| 2118 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2119 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2120 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2121 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2122 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2123 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2124 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2125 | return; |
| 2126 | } |
| 2127 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2128 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2129 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2130 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2131 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2132 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2133 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2134 | } |
| 2135 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2136 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2137 | if (invoke->GetLocations()->Intrinsified()) { |
| 2138 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2139 | intrinsic.Dispatch(invoke); |
| 2140 | return true; |
| 2141 | } |
| 2142 | return false; |
| 2143 | } |
| 2144 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2145 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2146 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2147 | // art::PrepareForRegisterAllocation. |
| 2148 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2149 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2150 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2151 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2152 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2153 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2154 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2155 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2156 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2157 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2161 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2162 | if (intrinsic.TryDispatch(invoke)) { |
| 2163 | return; |
| 2164 | } |
| 2165 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2166 | HandleInvoke(invoke); |
| 2167 | } |
| 2168 | |
| 2169 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2170 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2171 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2172 | } |
| 2173 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2174 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2175 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2176 | return; |
| 2177 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2178 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2179 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2180 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2181 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2184 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2185 | // This call to HandleInvoke allocates a temporary (core) register |
| 2186 | // which is also used to transfer the hidden argument from FP to |
| 2187 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2188 | HandleInvoke(invoke); |
| 2189 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2190 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2194 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2195 | LocationSummary* locations = invoke->GetLocations(); |
| 2196 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2197 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2198 | Location receiver = locations->InAt(0); |
| 2199 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2200 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2201 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2202 | // won't be modified thereafter, before the `call` instruction. |
| 2203 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2204 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2205 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2206 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2207 | if (receiver.IsStackSlot()) { |
| 2208 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2209 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2210 | __ movl(temp, Address(temp, class_offset)); |
| 2211 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2212 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2213 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2214 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2215 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2216 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2217 | // emit a read barrier for the previous class reference load. |
| 2218 | // However this is not required in practice, as this is an |
| 2219 | // intermediate/temporary reference and because the current |
| 2220 | // concurrent copying collector keeps the from-space memory |
| 2221 | // intact/accessible until the end of the marking phase (the |
| 2222 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2223 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2224 | // temp = temp->GetAddressOfIMT() |
| 2225 | __ movl(temp, |
| 2226 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2227 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2228 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2229 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2230 | __ movl(temp, Address(temp, method_offset)); |
| 2231 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2232 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2233 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2234 | |
| 2235 | DCHECK(!codegen_->IsLeafMethod()); |
| 2236 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2237 | } |
| 2238 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2239 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2240 | LocationSummary* locations = |
| 2241 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2242 | switch (neg->GetResultType()) { |
| 2243 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2244 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2245 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2246 | locations->SetOut(Location::SameAsFirstInput()); |
| 2247 | break; |
| 2248 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2249 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2250 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2251 | locations->SetOut(Location::SameAsFirstInput()); |
| 2252 | locations->AddTemp(Location::RequiresRegister()); |
| 2253 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2254 | break; |
| 2255 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2256 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2257 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2258 | locations->SetOut(Location::SameAsFirstInput()); |
| 2259 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2260 | break; |
| 2261 | |
| 2262 | default: |
| 2263 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2268 | LocationSummary* locations = neg->GetLocations(); |
| 2269 | Location out = locations->Out(); |
| 2270 | Location in = locations->InAt(0); |
| 2271 | switch (neg->GetResultType()) { |
| 2272 | case Primitive::kPrimInt: |
| 2273 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2274 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2275 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2276 | break; |
| 2277 | |
| 2278 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2279 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2280 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2281 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2282 | // Negation is similar to subtraction from zero. The least |
| 2283 | // significant byte triggers a borrow when it is different from |
| 2284 | // zero; to take it into account, add 1 to the most significant |
| 2285 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2286 | // operation. |
| 2287 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2288 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2289 | break; |
| 2290 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2291 | case Primitive::kPrimFloat: { |
| 2292 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2293 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2294 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2295 | // Implement float negation with an exclusive or with value |
| 2296 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2297 | // single-precision floating-point number). |
| 2298 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2299 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2300 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2301 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2302 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2303 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2304 | case Primitive::kPrimDouble: { |
| 2305 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2306 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2307 | // Implement double negation with an exclusive or with value |
| 2308 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2309 | // a double-precision floating-point number). |
| 2310 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2311 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2312 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2313 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2314 | |
| 2315 | default: |
| 2316 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2317 | } |
| 2318 | } |
| 2319 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2320 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2321 | LocationSummary* locations = |
| 2322 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2323 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2324 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2325 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2326 | locations->SetOut(Location::SameAsFirstInput()); |
| 2327 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2328 | } |
| 2329 | |
| 2330 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2331 | LocationSummary* locations = neg->GetLocations(); |
| 2332 | Location out = locations->Out(); |
| 2333 | DCHECK(locations->InAt(0).Equals(out)); |
| 2334 | |
| 2335 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2336 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2337 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2338 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2339 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2340 | } else { |
| 2341 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2342 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2343 | } |
| 2344 | } |
| 2345 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2346 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2347 | Primitive::Type result_type = conversion->GetResultType(); |
| 2348 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2349 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2350 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2351 | // The float-to-long and double-to-long type conversions rely on a |
| 2352 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2353 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2354 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2355 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2356 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2357 | : LocationSummary::kNoCall; |
| 2358 | LocationSummary* locations = |
| 2359 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2360 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2361 | // The Java language does not allow treating boolean as an integral type but |
| 2362 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2363 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2364 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimByte: |
| 2366 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2367 | case Primitive::kPrimLong: { |
| 2368 | // Type conversion from long to byte is a result of code transformations. |
| 2369 | HInstruction* input = conversion->InputAt(0); |
| 2370 | Location input_location = input->IsConstant() |
| 2371 | ? Location::ConstantLocation(input->AsConstant()) |
| 2372 | : Location::RegisterPairLocation(EAX, EDX); |
| 2373 | locations->SetInAt(0, input_location); |
| 2374 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2375 | // the validation of the linear scan implementation |
| 2376 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2377 | break; |
| 2378 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2379 | case Primitive::kPrimBoolean: |
| 2380 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2381 | case Primitive::kPrimShort: |
| 2382 | case Primitive::kPrimInt: |
| 2383 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2384 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2385 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2386 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2387 | // the validation of the linear scan implementation |
| 2388 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2389 | break; |
| 2390 | |
| 2391 | default: |
| 2392 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2393 | << " to " << result_type; |
| 2394 | } |
| 2395 | break; |
| 2396 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimShort: |
| 2398 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2399 | case Primitive::kPrimLong: |
| 2400 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2401 | case Primitive::kPrimBoolean: |
| 2402 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2403 | case Primitive::kPrimByte: |
| 2404 | case Primitive::kPrimInt: |
| 2405 | case Primitive::kPrimChar: |
| 2406 | // Processing a Dex `int-to-short' instruction. |
| 2407 | locations->SetInAt(0, Location::Any()); |
| 2408 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2409 | break; |
| 2410 | |
| 2411 | default: |
| 2412 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2413 | << " to " << result_type; |
| 2414 | } |
| 2415 | break; |
| 2416 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2417 | case Primitive::kPrimInt: |
| 2418 | switch (input_type) { |
| 2419 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2420 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2421 | locations->SetInAt(0, Location::Any()); |
| 2422 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2423 | break; |
| 2424 | |
| 2425 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2426 | // Processing a Dex `float-to-int' instruction. |
| 2427 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2428 | locations->SetOut(Location::RequiresRegister()); |
| 2429 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2430 | break; |
| 2431 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2433 | // Processing a Dex `double-to-int' instruction. |
| 2434 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2435 | locations->SetOut(Location::RequiresRegister()); |
| 2436 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2437 | break; |
| 2438 | |
| 2439 | default: |
| 2440 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2441 | << " to " << result_type; |
| 2442 | } |
| 2443 | break; |
| 2444 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2445 | case Primitive::kPrimLong: |
| 2446 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2447 | case Primitive::kPrimBoolean: |
| 2448 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2449 | case Primitive::kPrimByte: |
| 2450 | case Primitive::kPrimShort: |
| 2451 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2452 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2453 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2454 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2455 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2456 | break; |
| 2457 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2459 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2460 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2461 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2462 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2463 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2464 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2465 | // The runtime helper puts the result in EAX, EDX. |
| 2466 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2467 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2468 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2469 | |
| 2470 | default: |
| 2471 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2472 | << " to " << result_type; |
| 2473 | } |
| 2474 | break; |
| 2475 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2476 | case Primitive::kPrimChar: |
| 2477 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2478 | case Primitive::kPrimLong: |
| 2479 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2480 | case Primitive::kPrimBoolean: |
| 2481 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2482 | case Primitive::kPrimByte: |
| 2483 | case Primitive::kPrimShort: |
| 2484 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2485 | // Processing a Dex `int-to-char' instruction. |
| 2486 | locations->SetInAt(0, Location::Any()); |
| 2487 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2488 | break; |
| 2489 | |
| 2490 | default: |
| 2491 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2492 | << " to " << result_type; |
| 2493 | } |
| 2494 | break; |
| 2495 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2496 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2497 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2498 | case Primitive::kPrimBoolean: |
| 2499 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2500 | case Primitive::kPrimByte: |
| 2501 | case Primitive::kPrimShort: |
| 2502 | case Primitive::kPrimInt: |
| 2503 | case Primitive::kPrimChar: |
| 2504 | // Processing a Dex `int-to-float' instruction. |
| 2505 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2506 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2507 | break; |
| 2508 | |
| 2509 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2510 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2511 | locations->SetInAt(0, Location::Any()); |
| 2512 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2513 | break; |
| 2514 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2515 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2516 | // Processing a Dex `double-to-float' instruction. |
| 2517 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2518 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2519 | break; |
| 2520 | |
| 2521 | default: |
| 2522 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2523 | << " to " << result_type; |
| 2524 | }; |
| 2525 | break; |
| 2526 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2527 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2528 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2529 | case Primitive::kPrimBoolean: |
| 2530 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimByte: |
| 2532 | case Primitive::kPrimShort: |
| 2533 | case Primitive::kPrimInt: |
| 2534 | case Primitive::kPrimChar: |
| 2535 | // Processing a Dex `int-to-double' instruction. |
| 2536 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2537 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2538 | break; |
| 2539 | |
| 2540 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2541 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2542 | locations->SetInAt(0, Location::Any()); |
| 2543 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2544 | break; |
| 2545 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2546 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2547 | // Processing a Dex `float-to-double' instruction. |
| 2548 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2549 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2550 | break; |
| 2551 | |
| 2552 | default: |
| 2553 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2554 | << " to " << result_type; |
| 2555 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2556 | break; |
| 2557 | |
| 2558 | default: |
| 2559 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2560 | << " to " << result_type; |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2565 | LocationSummary* locations = conversion->GetLocations(); |
| 2566 | Location out = locations->Out(); |
| 2567 | Location in = locations->InAt(0); |
| 2568 | Primitive::Type result_type = conversion->GetResultType(); |
| 2569 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2570 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2571 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2572 | case Primitive::kPrimByte: |
| 2573 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2574 | case Primitive::kPrimLong: |
| 2575 | // Type conversion from long to byte is a result of code transformations. |
| 2576 | if (in.IsRegisterPair()) { |
| 2577 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2578 | } else { |
| 2579 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2580 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2581 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2582 | } |
| 2583 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2584 | case Primitive::kPrimBoolean: |
| 2585 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2586 | case Primitive::kPrimShort: |
| 2587 | case Primitive::kPrimInt: |
| 2588 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2589 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2590 | if (in.IsRegister()) { |
| 2591 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2592 | } else { |
| 2593 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2594 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2595 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2596 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | |
| 2599 | default: |
| 2600 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2601 | << " to " << result_type; |
| 2602 | } |
| 2603 | break; |
| 2604 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimShort: |
| 2606 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2607 | case Primitive::kPrimLong: |
| 2608 | // Type conversion from long to short is a result of code transformations. |
| 2609 | if (in.IsRegisterPair()) { |
| 2610 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2611 | } else if (in.IsDoubleStackSlot()) { |
| 2612 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2613 | } else { |
| 2614 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2615 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2616 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2617 | } |
| 2618 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2619 | case Primitive::kPrimBoolean: |
| 2620 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2621 | case Primitive::kPrimByte: |
| 2622 | case Primitive::kPrimInt: |
| 2623 | case Primitive::kPrimChar: |
| 2624 | // Processing a Dex `int-to-short' instruction. |
| 2625 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2626 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2627 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2628 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2629 | } else { |
| 2630 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2631 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2632 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2633 | } |
| 2634 | break; |
| 2635 | |
| 2636 | default: |
| 2637 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2638 | << " to " << result_type; |
| 2639 | } |
| 2640 | break; |
| 2641 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2642 | case Primitive::kPrimInt: |
| 2643 | switch (input_type) { |
| 2644 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2645 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2646 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2647 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2648 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2649 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2650 | } else { |
| 2651 | DCHECK(in.IsConstant()); |
| 2652 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2653 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2654 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2655 | } |
| 2656 | break; |
| 2657 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2658 | case Primitive::kPrimFloat: { |
| 2659 | // Processing a Dex `float-to-int' instruction. |
| 2660 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2661 | Register output = out.AsRegister<Register>(); |
| 2662 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2663 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2664 | |
| 2665 | __ movl(output, Immediate(kPrimIntMax)); |
| 2666 | // temp = int-to-float(output) |
| 2667 | __ cvtsi2ss(temp, output); |
| 2668 | // if input >= temp goto done |
| 2669 | __ comiss(input, temp); |
| 2670 | __ j(kAboveEqual, &done); |
| 2671 | // if input == NaN goto nan |
| 2672 | __ j(kUnordered, &nan); |
| 2673 | // output = float-to-int-truncate(input) |
| 2674 | __ cvttss2si(output, input); |
| 2675 | __ jmp(&done); |
| 2676 | __ Bind(&nan); |
| 2677 | // output = 0 |
| 2678 | __ xorl(output, output); |
| 2679 | __ Bind(&done); |
| 2680 | break; |
| 2681 | } |
| 2682 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2683 | case Primitive::kPrimDouble: { |
| 2684 | // Processing a Dex `double-to-int' instruction. |
| 2685 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2686 | Register output = out.AsRegister<Register>(); |
| 2687 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2688 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2689 | |
| 2690 | __ movl(output, Immediate(kPrimIntMax)); |
| 2691 | // temp = int-to-double(output) |
| 2692 | __ cvtsi2sd(temp, output); |
| 2693 | // if input >= temp goto done |
| 2694 | __ comisd(input, temp); |
| 2695 | __ j(kAboveEqual, &done); |
| 2696 | // if input == NaN goto nan |
| 2697 | __ j(kUnordered, &nan); |
| 2698 | // output = double-to-int-truncate(input) |
| 2699 | __ cvttsd2si(output, input); |
| 2700 | __ jmp(&done); |
| 2701 | __ Bind(&nan); |
| 2702 | // output = 0 |
| 2703 | __ xorl(output, output); |
| 2704 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2705 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2706 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2707 | |
| 2708 | default: |
| 2709 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2710 | << " to " << result_type; |
| 2711 | } |
| 2712 | break; |
| 2713 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2714 | case Primitive::kPrimLong: |
| 2715 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2716 | case Primitive::kPrimBoolean: |
| 2717 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2718 | case Primitive::kPrimByte: |
| 2719 | case Primitive::kPrimShort: |
| 2720 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2721 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2722 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2723 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2724 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2725 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2726 | __ cdq(); |
| 2727 | break; |
| 2728 | |
| 2729 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2730 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2731 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2732 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2733 | break; |
| 2734 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2735 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2736 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2737 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2738 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2739 | break; |
| 2740 | |
| 2741 | default: |
| 2742 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2743 | << " to " << result_type; |
| 2744 | } |
| 2745 | break; |
| 2746 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2747 | case Primitive::kPrimChar: |
| 2748 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2749 | case Primitive::kPrimLong: |
| 2750 | // Type conversion from long to short is a result of code transformations. |
| 2751 | if (in.IsRegisterPair()) { |
| 2752 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2753 | } else if (in.IsDoubleStackSlot()) { |
| 2754 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2755 | } else { |
| 2756 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2757 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2758 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2759 | } |
| 2760 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2761 | case Primitive::kPrimBoolean: |
| 2762 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2763 | case Primitive::kPrimByte: |
| 2764 | case Primitive::kPrimShort: |
| 2765 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2766 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2767 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2768 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2769 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2770 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2771 | } else { |
| 2772 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2773 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2774 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2775 | } |
| 2776 | break; |
| 2777 | |
| 2778 | default: |
| 2779 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2780 | << " to " << result_type; |
| 2781 | } |
| 2782 | break; |
| 2783 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2784 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2785 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2786 | case Primitive::kPrimBoolean: |
| 2787 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2788 | case Primitive::kPrimByte: |
| 2789 | case Primitive::kPrimShort: |
| 2790 | case Primitive::kPrimInt: |
| 2791 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2792 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2793 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2794 | break; |
| 2795 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2796 | case Primitive::kPrimLong: { |
| 2797 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2798 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2799 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2800 | // Create stack space for the call to |
| 2801 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2802 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2803 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2804 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2805 | __ subl(ESP, Immediate(adjustment)); |
| 2806 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2807 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2808 | // Load the value to the FP stack, using temporaries if needed. |
| 2809 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2810 | |
| 2811 | if (out.IsStackSlot()) { |
| 2812 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2813 | } else { |
| 2814 | __ fstps(Address(ESP, 0)); |
| 2815 | Location stack_temp = Location::StackSlot(0); |
| 2816 | codegen_->Move32(out, stack_temp); |
| 2817 | } |
| 2818 | |
| 2819 | // Remove the temporary stack space we allocated. |
| 2820 | if (adjustment != 0) { |
| 2821 | __ addl(ESP, Immediate(adjustment)); |
| 2822 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2823 | break; |
| 2824 | } |
| 2825 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2826 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2827 | // Processing a Dex `double-to-float' instruction. |
| 2828 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2829 | break; |
| 2830 | |
| 2831 | default: |
| 2832 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2833 | << " to " << result_type; |
| 2834 | }; |
| 2835 | break; |
| 2836 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2837 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2838 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2839 | case Primitive::kPrimBoolean: |
| 2840 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2841 | case Primitive::kPrimByte: |
| 2842 | case Primitive::kPrimShort: |
| 2843 | case Primitive::kPrimInt: |
| 2844 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2845 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2846 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2847 | break; |
| 2848 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2849 | case Primitive::kPrimLong: { |
| 2850 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2851 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2852 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2853 | // Create stack space for the call to |
| 2854 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2855 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2856 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2857 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2858 | __ subl(ESP, Immediate(adjustment)); |
| 2859 | } |
| 2860 | |
| 2861 | // Load the value to the FP stack, using temporaries if needed. |
| 2862 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2863 | |
| 2864 | if (out.IsDoubleStackSlot()) { |
| 2865 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2866 | } else { |
| 2867 | __ fstpl(Address(ESP, 0)); |
| 2868 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2869 | codegen_->Move64(out, stack_temp); |
| 2870 | } |
| 2871 | |
| 2872 | // Remove the temporary stack space we allocated. |
| 2873 | if (adjustment != 0) { |
| 2874 | __ addl(ESP, Immediate(adjustment)); |
| 2875 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2876 | break; |
| 2877 | } |
| 2878 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2879 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2880 | // Processing a Dex `float-to-double' instruction. |
| 2881 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2882 | break; |
| 2883 | |
| 2884 | default: |
| 2885 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2886 | << " to " << result_type; |
| 2887 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2888 | break; |
| 2889 | |
| 2890 | default: |
| 2891 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2892 | << " to " << result_type; |
| 2893 | } |
| 2894 | } |
| 2895 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2896 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2897 | LocationSummary* locations = |
| 2898 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2899 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2900 | case Primitive::kPrimInt: { |
| 2901 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2902 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2903 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2904 | break; |
| 2905 | } |
| 2906 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2907 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2908 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2909 | locations->SetInAt(1, Location::Any()); |
| 2910 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2911 | break; |
| 2912 | } |
| 2913 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2914 | case Primitive::kPrimFloat: |
| 2915 | case Primitive::kPrimDouble: { |
| 2916 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2917 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2918 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2919 | } else if (add->InputAt(1)->IsConstant()) { |
| 2920 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2921 | } else { |
| 2922 | locations->SetInAt(1, Location::Any()); |
| 2923 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2924 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2925 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2926 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2927 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2928 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2929 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2930 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2931 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2935 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2936 | Location first = locations->InAt(0); |
| 2937 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2938 | Location out = locations->Out(); |
| 2939 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2940 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2941 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2942 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2943 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2944 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2945 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2946 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2947 | } else { |
| 2948 | __ leal(out.AsRegister<Register>(), Address( |
| 2949 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2950 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2951 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2952 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2953 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2954 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2955 | } else { |
| 2956 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2957 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2958 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2959 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2960 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2961 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2962 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2966 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2967 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2968 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2969 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2970 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2971 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2972 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2973 | } else { |
| 2974 | DCHECK(second.IsConstant()) << second; |
| 2975 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2976 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2977 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2978 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2979 | break; |
| 2980 | } |
| 2981 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2982 | case Primitive::kPrimFloat: { |
| 2983 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2984 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2985 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2986 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2987 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2988 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2989 | codegen_->LiteralFloatAddress( |
| 2990 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2991 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2992 | } else { |
| 2993 | DCHECK(second.IsStackSlot()); |
| 2994 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2995 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2996 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | case Primitive::kPrimDouble: { |
| 3000 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3001 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3002 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3003 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3004 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3005 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3006 | codegen_->LiteralDoubleAddress( |
| 3007 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3008 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3009 | } else { |
| 3010 | DCHECK(second.IsDoubleStackSlot()); |
| 3011 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3012 | } |
| 3013 | break; |
| 3014 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3015 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3016 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3017 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3018 | } |
| 3019 | } |
| 3020 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3021 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3022 | LocationSummary* locations = |
| 3023 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3024 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3025 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3026 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3027 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3028 | locations->SetInAt(1, Location::Any()); |
| 3029 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3030 | break; |
| 3031 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3032 | case Primitive::kPrimFloat: |
| 3033 | case Primitive::kPrimDouble: { |
| 3034 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3035 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3036 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3037 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3038 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3039 | } else { |
| 3040 | locations->SetInAt(1, Location::Any()); |
| 3041 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3042 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3043 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3044 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3045 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3046 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3047 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3048 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3052 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3053 | Location first = locations->InAt(0); |
| 3054 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3055 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3056 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3057 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3058 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3059 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3060 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3061 | __ subl(first.AsRegister<Register>(), |
| 3062 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3063 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3064 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3065 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3066 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3070 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3071 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3072 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3073 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3074 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3075 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3076 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3077 | } else { |
| 3078 | DCHECK(second.IsConstant()) << second; |
| 3079 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3080 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3081 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3082 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3083 | break; |
| 3084 | } |
| 3085 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3086 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3087 | if (second.IsFpuRegister()) { |
| 3088 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3089 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3090 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3091 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3092 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3093 | codegen_->LiteralFloatAddress( |
| 3094 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3095 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3096 | } else { |
| 3097 | DCHECK(second.IsStackSlot()); |
| 3098 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3099 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3100 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3104 | if (second.IsFpuRegister()) { |
| 3105 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3106 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3107 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3108 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3109 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3110 | codegen_->LiteralDoubleAddress( |
| 3111 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3112 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3113 | } else { |
| 3114 | DCHECK(second.IsDoubleStackSlot()); |
| 3115 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3116 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3117 | break; |
| 3118 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3119 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3120 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3121 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3122 | } |
| 3123 | } |
| 3124 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3125 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3126 | LocationSummary* locations = |
| 3127 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3128 | switch (mul->GetResultType()) { |
| 3129 | case Primitive::kPrimInt: |
| 3130 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3131 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3132 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3133 | // Can use 3 operand multiply. |
| 3134 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3135 | } else { |
| 3136 | locations->SetOut(Location::SameAsFirstInput()); |
| 3137 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3138 | break; |
| 3139 | case Primitive::kPrimLong: { |
| 3140 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3141 | locations->SetInAt(1, Location::Any()); |
| 3142 | locations->SetOut(Location::SameAsFirstInput()); |
| 3143 | // Needed for imul on 32bits with 64bits output. |
| 3144 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3145 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3146 | break; |
| 3147 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3148 | case Primitive::kPrimFloat: |
| 3149 | case Primitive::kPrimDouble: { |
| 3150 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3151 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3152 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3153 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3154 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3155 | } else { |
| 3156 | locations->SetInAt(1, Location::Any()); |
| 3157 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3158 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3159 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3160 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3161 | |
| 3162 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3163 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3168 | LocationSummary* locations = mul->GetLocations(); |
| 3169 | Location first = locations->InAt(0); |
| 3170 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3171 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3172 | |
| 3173 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3174 | case Primitive::kPrimInt: |
| 3175 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3176 | // problems where the output may not be the same as the first operand. |
| 3177 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3178 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3179 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3180 | } else if (second.IsRegister()) { |
| 3181 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3182 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3183 | } else { |
| 3184 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3185 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3186 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3187 | } |
| 3188 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3189 | |
| 3190 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3191 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3192 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3193 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3194 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3195 | |
| 3196 | DCHECK_EQ(EAX, eax); |
| 3197 | DCHECK_EQ(EDX, edx); |
| 3198 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3199 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3200 | // output: in1 |
| 3201 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3202 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3203 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3204 | if (second.IsConstant()) { |
| 3205 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3206 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3207 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3208 | int32_t low_value = Low32Bits(value); |
| 3209 | int32_t high_value = High32Bits(value); |
| 3210 | Immediate low(low_value); |
| 3211 | Immediate high(high_value); |
| 3212 | |
| 3213 | __ movl(eax, high); |
| 3214 | // eax <- in1.lo * in2.hi |
| 3215 | __ imull(eax, in1_lo); |
| 3216 | // in1.hi <- in1.hi * in2.lo |
| 3217 | __ imull(in1_hi, low); |
| 3218 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3219 | __ addl(in1_hi, eax); |
| 3220 | // move in2_lo to eax to prepare for double precision |
| 3221 | __ movl(eax, low); |
| 3222 | // edx:eax <- in1.lo * in2.lo |
| 3223 | __ mull(in1_lo); |
| 3224 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3225 | __ addl(in1_hi, edx); |
| 3226 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3227 | __ movl(in1_lo, eax); |
| 3228 | } else if (second.IsRegisterPair()) { |
| 3229 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3230 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3231 | |
| 3232 | __ movl(eax, in2_hi); |
| 3233 | // eax <- in1.lo * in2.hi |
| 3234 | __ imull(eax, in1_lo); |
| 3235 | // in1.hi <- in1.hi * in2.lo |
| 3236 | __ imull(in1_hi, in2_lo); |
| 3237 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3238 | __ addl(in1_hi, eax); |
| 3239 | // move in1_lo to eax to prepare for double precision |
| 3240 | __ movl(eax, in1_lo); |
| 3241 | // edx:eax <- in1.lo * in2.lo |
| 3242 | __ mull(in2_lo); |
| 3243 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3244 | __ addl(in1_hi, edx); |
| 3245 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3246 | __ movl(in1_lo, eax); |
| 3247 | } else { |
| 3248 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3249 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3250 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3251 | |
| 3252 | __ movl(eax, in2_hi); |
| 3253 | // eax <- in1.lo * in2.hi |
| 3254 | __ imull(eax, in1_lo); |
| 3255 | // in1.hi <- in1.hi * in2.lo |
| 3256 | __ imull(in1_hi, in2_lo); |
| 3257 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3258 | __ addl(in1_hi, eax); |
| 3259 | // move in1_lo to eax to prepare for double precision |
| 3260 | __ movl(eax, in1_lo); |
| 3261 | // edx:eax <- in1.lo * in2.lo |
| 3262 | __ mull(in2_lo); |
| 3263 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3264 | __ addl(in1_hi, edx); |
| 3265 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3266 | __ movl(in1_lo, eax); |
| 3267 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3268 | |
| 3269 | break; |
| 3270 | } |
| 3271 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3272 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3273 | DCHECK(first.Equals(locations->Out())); |
| 3274 | if (second.IsFpuRegister()) { |
| 3275 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3276 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3277 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3278 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3279 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3280 | codegen_->LiteralFloatAddress( |
| 3281 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3282 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3283 | } else { |
| 3284 | DCHECK(second.IsStackSlot()); |
| 3285 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3286 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3287 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3288 | } |
| 3289 | |
| 3290 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3291 | DCHECK(first.Equals(locations->Out())); |
| 3292 | if (second.IsFpuRegister()) { |
| 3293 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3294 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3295 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3296 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3297 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3298 | codegen_->LiteralDoubleAddress( |
| 3299 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3300 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3301 | } else { |
| 3302 | DCHECK(second.IsDoubleStackSlot()); |
| 3303 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3304 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3305 | break; |
| 3306 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3307 | |
| 3308 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3309 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3310 | } |
| 3311 | } |
| 3312 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3313 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3314 | uint32_t temp_offset, |
| 3315 | uint32_t stack_adjustment, |
| 3316 | bool is_fp, |
| 3317 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3318 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3319 | DCHECK(!is_wide); |
| 3320 | if (is_fp) { |
| 3321 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3322 | } else { |
| 3323 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3324 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3325 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3326 | DCHECK(is_wide); |
| 3327 | if (is_fp) { |
| 3328 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3329 | } else { |
| 3330 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3331 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3332 | } else { |
| 3333 | // 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] | 3334 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3335 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3336 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3337 | if (is_fp) { |
| 3338 | __ flds(Address(ESP, temp_offset)); |
| 3339 | } else { |
| 3340 | __ filds(Address(ESP, temp_offset)); |
| 3341 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3342 | } else { |
| 3343 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3344 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3345 | if (is_fp) { |
| 3346 | __ fldl(Address(ESP, temp_offset)); |
| 3347 | } else { |
| 3348 | __ fildl(Address(ESP, temp_offset)); |
| 3349 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3350 | } |
| 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3355 | Primitive::Type type = rem->GetResultType(); |
| 3356 | bool is_float = type == Primitive::kPrimFloat; |
| 3357 | size_t elem_size = Primitive::ComponentSize(type); |
| 3358 | LocationSummary* locations = rem->GetLocations(); |
| 3359 | Location first = locations->InAt(0); |
| 3360 | Location second = locations->InAt(1); |
| 3361 | Location out = locations->Out(); |
| 3362 | |
| 3363 | // Create stack space for 2 elements. |
| 3364 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3365 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3366 | |
| 3367 | // 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] | 3368 | const bool is_wide = !is_float; |
| 3369 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3370 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3371 | |
| 3372 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3373 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3374 | __ Bind(&retry); |
| 3375 | __ fprem(); |
| 3376 | |
| 3377 | // Move FP status to AX. |
| 3378 | __ fstsw(); |
| 3379 | |
| 3380 | // And see if the argument reduction is complete. This is signaled by the |
| 3381 | // C2 FPU flag bit set to 0. |
| 3382 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3383 | __ j(kNotEqual, &retry); |
| 3384 | |
| 3385 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3386 | // Store FP top of stack to real stack. |
| 3387 | if (is_float) { |
| 3388 | __ fsts(Address(ESP, 0)); |
| 3389 | } else { |
| 3390 | __ fstl(Address(ESP, 0)); |
| 3391 | } |
| 3392 | |
| 3393 | // Pop the 2 items from the FP stack. |
| 3394 | __ fucompp(); |
| 3395 | |
| 3396 | // Load the value from the stack into an XMM register. |
| 3397 | DCHECK(out.IsFpuRegister()) << out; |
| 3398 | if (is_float) { |
| 3399 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3400 | } else { |
| 3401 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3402 | } |
| 3403 | |
| 3404 | // And remove the temporary stack space we allocated. |
| 3405 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3406 | } |
| 3407 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3408 | |
| 3409 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3410 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3411 | |
| 3412 | LocationSummary* locations = instruction->GetLocations(); |
| 3413 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3414 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3415 | |
| 3416 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3417 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3418 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3419 | |
| 3420 | DCHECK(imm == 1 || imm == -1); |
| 3421 | |
| 3422 | if (instruction->IsRem()) { |
| 3423 | __ xorl(out_register, out_register); |
| 3424 | } else { |
| 3425 | __ movl(out_register, input_register); |
| 3426 | if (imm == -1) { |
| 3427 | __ negl(out_register); |
| 3428 | } |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3433 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3434 | LocationSummary* locations = instruction->GetLocations(); |
| 3435 | |
| 3436 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3437 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3438 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3439 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3440 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3441 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3442 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3443 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3444 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3445 | __ testl(input_register, input_register); |
| 3446 | __ cmovl(kGreaterEqual, num, input_register); |
| 3447 | int shift = CTZ(imm); |
| 3448 | __ sarl(num, Immediate(shift)); |
| 3449 | |
| 3450 | if (imm < 0) { |
| 3451 | __ negl(num); |
| 3452 | } |
| 3453 | |
| 3454 | __ movl(out_register, num); |
| 3455 | } |
| 3456 | |
| 3457 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3458 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3459 | |
| 3460 | LocationSummary* locations = instruction->GetLocations(); |
| 3461 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3462 | |
| 3463 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3464 | Register out = locations->Out().AsRegister<Register>(); |
| 3465 | Register num; |
| 3466 | Register edx; |
| 3467 | |
| 3468 | if (instruction->IsDiv()) { |
| 3469 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3470 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3471 | } else { |
| 3472 | edx = locations->Out().AsRegister<Register>(); |
| 3473 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3474 | } |
| 3475 | |
| 3476 | DCHECK_EQ(EAX, eax); |
| 3477 | DCHECK_EQ(EDX, edx); |
| 3478 | if (instruction->IsDiv()) { |
| 3479 | DCHECK_EQ(EAX, out); |
| 3480 | } else { |
| 3481 | DCHECK_EQ(EDX, out); |
| 3482 | } |
| 3483 | |
| 3484 | int64_t magic; |
| 3485 | int shift; |
| 3486 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3487 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3488 | // Save the numerator. |
| 3489 | __ movl(num, eax); |
| 3490 | |
| 3491 | // EAX = magic |
| 3492 | __ movl(eax, Immediate(magic)); |
| 3493 | |
| 3494 | // EDX:EAX = magic * numerator |
| 3495 | __ imull(num); |
| 3496 | |
| 3497 | if (imm > 0 && magic < 0) { |
| 3498 | // EDX += num |
| 3499 | __ addl(edx, num); |
| 3500 | } else if (imm < 0 && magic > 0) { |
| 3501 | __ subl(edx, num); |
| 3502 | } |
| 3503 | |
| 3504 | // Shift if needed. |
| 3505 | if (shift != 0) { |
| 3506 | __ sarl(edx, Immediate(shift)); |
| 3507 | } |
| 3508 | |
| 3509 | // EDX += 1 if EDX < 0 |
| 3510 | __ movl(eax, edx); |
| 3511 | __ shrl(edx, Immediate(31)); |
| 3512 | __ addl(edx, eax); |
| 3513 | |
| 3514 | if (instruction->IsRem()) { |
| 3515 | __ movl(eax, num); |
| 3516 | __ imull(edx, Immediate(imm)); |
| 3517 | __ subl(eax, edx); |
| 3518 | __ movl(edx, eax); |
| 3519 | } else { |
| 3520 | __ movl(eax, edx); |
| 3521 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3522 | } |
| 3523 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3524 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3525 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3526 | |
| 3527 | LocationSummary* locations = instruction->GetLocations(); |
| 3528 | Location out = locations->Out(); |
| 3529 | Location first = locations->InAt(0); |
| 3530 | Location second = locations->InAt(1); |
| 3531 | bool is_div = instruction->IsDiv(); |
| 3532 | |
| 3533 | switch (instruction->GetResultType()) { |
| 3534 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3535 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3536 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3537 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3538 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3539 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3540 | |
| 3541 | if (imm == 0) { |
| 3542 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3543 | } else if (imm == 1 || imm == -1) { |
| 3544 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3545 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3546 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3547 | } else { |
| 3548 | DCHECK(imm <= -2 || imm >= 2); |
| 3549 | GenerateDivRemWithAnyConstant(instruction); |
| 3550 | } |
| 3551 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3552 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3553 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3554 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3555 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3556 | Register second_reg = second.AsRegister<Register>(); |
| 3557 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3558 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3559 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3560 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3561 | __ cmpl(second_reg, Immediate(-1)); |
| 3562 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3563 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3564 | // edx:eax <- sign-extended of eax |
| 3565 | __ cdq(); |
| 3566 | // eax = quotient, edx = remainder |
| 3567 | __ idivl(second_reg); |
| 3568 | __ Bind(slow_path->GetExitLabel()); |
| 3569 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3570 | break; |
| 3571 | } |
| 3572 | |
| 3573 | case Primitive::kPrimLong: { |
| 3574 | InvokeRuntimeCallingConvention calling_convention; |
| 3575 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3576 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3577 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3578 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3579 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3580 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3581 | |
| 3582 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3583 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3584 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3585 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3586 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3587 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3588 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3589 | break; |
| 3590 | } |
| 3591 | |
| 3592 | default: |
| 3593 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3594 | } |
| 3595 | } |
| 3596 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3597 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3598 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3599 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3600 | : LocationSummary::kNoCall; |
| 3601 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3602 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3603 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3604 | case Primitive::kPrimInt: { |
| 3605 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3606 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3607 | locations->SetOut(Location::SameAsFirstInput()); |
| 3608 | // Intel uses edx:eax as the dividend. |
| 3609 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3610 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3611 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3612 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3613 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3614 | locations->AddTemp(Location::RequiresRegister()); |
| 3615 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3616 | break; |
| 3617 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3618 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3619 | InvokeRuntimeCallingConvention calling_convention; |
| 3620 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3621 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3622 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3623 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3624 | // Runtime helper puts the result in EAX, EDX. |
| 3625 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3626 | break; |
| 3627 | } |
| 3628 | case Primitive::kPrimFloat: |
| 3629 | case Primitive::kPrimDouble: { |
| 3630 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3631 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3632 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3633 | } else if (div->InputAt(1)->IsConstant()) { |
| 3634 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3635 | } else { |
| 3636 | locations->SetInAt(1, Location::Any()); |
| 3637 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3638 | locations->SetOut(Location::SameAsFirstInput()); |
| 3639 | break; |
| 3640 | } |
| 3641 | |
| 3642 | default: |
| 3643 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3644 | } |
| 3645 | } |
| 3646 | |
| 3647 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3648 | LocationSummary* locations = div->GetLocations(); |
| 3649 | Location first = locations->InAt(0); |
| 3650 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3651 | |
| 3652 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3653 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3654 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3655 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3656 | break; |
| 3657 | } |
| 3658 | |
| 3659 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3660 | if (second.IsFpuRegister()) { |
| 3661 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3662 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3663 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3664 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3665 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3666 | codegen_->LiteralFloatAddress( |
| 3667 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3668 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3669 | } else { |
| 3670 | DCHECK(second.IsStackSlot()); |
| 3671 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3672 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3673 | break; |
| 3674 | } |
| 3675 | |
| 3676 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3677 | if (second.IsFpuRegister()) { |
| 3678 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3679 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3680 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3681 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3682 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3683 | codegen_->LiteralDoubleAddress( |
| 3684 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3685 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3686 | } else { |
| 3687 | DCHECK(second.IsDoubleStackSlot()); |
| 3688 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3689 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3690 | break; |
| 3691 | } |
| 3692 | |
| 3693 | default: |
| 3694 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3695 | } |
| 3696 | } |
| 3697 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3698 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3699 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3700 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3701 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3702 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3703 | : LocationSummary::kNoCall; |
| 3704 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3705 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3706 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3707 | case Primitive::kPrimInt: { |
| 3708 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3709 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3710 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3711 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3712 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3713 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3714 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3715 | locations->AddTemp(Location::RequiresRegister()); |
| 3716 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3717 | break; |
| 3718 | } |
| 3719 | case Primitive::kPrimLong: { |
| 3720 | InvokeRuntimeCallingConvention calling_convention; |
| 3721 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3722 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3723 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3724 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3725 | // Runtime helper puts the result in EAX, EDX. |
| 3726 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3727 | break; |
| 3728 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3729 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3730 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3731 | locations->SetInAt(0, Location::Any()); |
| 3732 | locations->SetInAt(1, Location::Any()); |
| 3733 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3734 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3735 | break; |
| 3736 | } |
| 3737 | |
| 3738 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3739 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3744 | Primitive::Type type = rem->GetResultType(); |
| 3745 | switch (type) { |
| 3746 | case Primitive::kPrimInt: |
| 3747 | case Primitive::kPrimLong: { |
| 3748 | GenerateDivRemIntegral(rem); |
| 3749 | break; |
| 3750 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3751 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3752 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3753 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3754 | break; |
| 3755 | } |
| 3756 | default: |
| 3757 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3758 | } |
| 3759 | } |
| 3760 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3761 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3762 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3763 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3764 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3765 | case Primitive::kPrimByte: |
| 3766 | case Primitive::kPrimChar: |
| 3767 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3768 | case Primitive::kPrimInt: { |
| 3769 | locations->SetInAt(0, Location::Any()); |
| 3770 | break; |
| 3771 | } |
| 3772 | case Primitive::kPrimLong: { |
| 3773 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3774 | if (!instruction->IsConstant()) { |
| 3775 | locations->AddTemp(Location::RequiresRegister()); |
| 3776 | } |
| 3777 | break; |
| 3778 | } |
| 3779 | default: |
| 3780 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3781 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3785 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3786 | codegen_->AddSlowPath(slow_path); |
| 3787 | |
| 3788 | LocationSummary* locations = instruction->GetLocations(); |
| 3789 | Location value = locations->InAt(0); |
| 3790 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3791 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3792 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3793 | case Primitive::kPrimByte: |
| 3794 | case Primitive::kPrimChar: |
| 3795 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3796 | case Primitive::kPrimInt: { |
| 3797 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3798 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3799 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3800 | } else if (value.IsStackSlot()) { |
| 3801 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3802 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3803 | } else { |
| 3804 | DCHECK(value.IsConstant()) << value; |
| 3805 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3806 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3807 | } |
| 3808 | } |
| 3809 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3810 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3811 | case Primitive::kPrimLong: { |
| 3812 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3813 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3814 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3815 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3816 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3817 | } else { |
| 3818 | DCHECK(value.IsConstant()) << value; |
| 3819 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3820 | __ jmp(slow_path->GetEntryLabel()); |
| 3821 | } |
| 3822 | } |
| 3823 | break; |
| 3824 | } |
| 3825 | default: |
| 3826 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3827 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3828 | } |
| 3829 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3830 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3831 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3832 | |
| 3833 | LocationSummary* locations = |
| 3834 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3835 | |
| 3836 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3837 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3838 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3839 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3840 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3841 | // The shift count needs to be in CL or a constant. |
| 3842 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3843 | locations->SetOut(Location::SameAsFirstInput()); |
| 3844 | break; |
| 3845 | } |
| 3846 | default: |
| 3847 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3852 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3853 | |
| 3854 | LocationSummary* locations = op->GetLocations(); |
| 3855 | Location first = locations->InAt(0); |
| 3856 | Location second = locations->InAt(1); |
| 3857 | DCHECK(first.Equals(locations->Out())); |
| 3858 | |
| 3859 | switch (op->GetResultType()) { |
| 3860 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3861 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3862 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3863 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3864 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3865 | DCHECK_EQ(ECX, second_reg); |
| 3866 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3867 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3868 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3869 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3870 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3871 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3872 | } |
| 3873 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3874 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3875 | if (shift == 0) { |
| 3876 | return; |
| 3877 | } |
| 3878 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3879 | if (op->IsShl()) { |
| 3880 | __ shll(first_reg, imm); |
| 3881 | } else if (op->IsShr()) { |
| 3882 | __ sarl(first_reg, imm); |
| 3883 | } else { |
| 3884 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | break; |
| 3888 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3889 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3890 | if (second.IsRegister()) { |
| 3891 | Register second_reg = second.AsRegister<Register>(); |
| 3892 | DCHECK_EQ(ECX, second_reg); |
| 3893 | if (op->IsShl()) { |
| 3894 | GenerateShlLong(first, second_reg); |
| 3895 | } else if (op->IsShr()) { |
| 3896 | GenerateShrLong(first, second_reg); |
| 3897 | } else { |
| 3898 | GenerateUShrLong(first, second_reg); |
| 3899 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3900 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3901 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3902 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3903 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3904 | if (shift != 0) { |
| 3905 | if (op->IsShl()) { |
| 3906 | GenerateShlLong(first, shift); |
| 3907 | } else if (op->IsShr()) { |
| 3908 | GenerateShrLong(first, shift); |
| 3909 | } else { |
| 3910 | GenerateUShrLong(first, shift); |
| 3911 | } |
| 3912 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3913 | } |
| 3914 | break; |
| 3915 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3916 | default: |
| 3917 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3918 | } |
| 3919 | } |
| 3920 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3921 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3922 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3923 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3924 | if (shift == 1) { |
| 3925 | // This is just an addition. |
| 3926 | __ addl(low, low); |
| 3927 | __ adcl(high, high); |
| 3928 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3929 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3930 | codegen_->EmitParallelMoves( |
| 3931 | loc.ToLow(), |
| 3932 | loc.ToHigh(), |
| 3933 | Primitive::kPrimInt, |
| 3934 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3935 | loc.ToLow(), |
| 3936 | Primitive::kPrimInt); |
| 3937 | } else if (shift > 32) { |
| 3938 | // Low part becomes 0. High part is low part << (shift-32). |
| 3939 | __ movl(high, low); |
| 3940 | __ shll(high, Immediate(shift - 32)); |
| 3941 | __ xorl(low, low); |
| 3942 | } else { |
| 3943 | // Between 1 and 31. |
| 3944 | __ shld(high, low, Immediate(shift)); |
| 3945 | __ shll(low, Immediate(shift)); |
| 3946 | } |
| 3947 | } |
| 3948 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3949 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3950 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3951 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3952 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3953 | __ testl(shifter, Immediate(32)); |
| 3954 | __ j(kEqual, &done); |
| 3955 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3956 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3957 | __ Bind(&done); |
| 3958 | } |
| 3959 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3960 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3961 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3962 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3963 | if (shift == 32) { |
| 3964 | // Need to copy the sign. |
| 3965 | DCHECK_NE(low, high); |
| 3966 | __ movl(low, high); |
| 3967 | __ sarl(high, Immediate(31)); |
| 3968 | } else if (shift > 32) { |
| 3969 | DCHECK_NE(low, high); |
| 3970 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3971 | __ movl(low, high); |
| 3972 | __ sarl(high, Immediate(31)); |
| 3973 | __ sarl(low, Immediate(shift - 32)); |
| 3974 | } else { |
| 3975 | // Between 1 and 31. |
| 3976 | __ shrd(low, high, Immediate(shift)); |
| 3977 | __ sarl(high, Immediate(shift)); |
| 3978 | } |
| 3979 | } |
| 3980 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3981 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3982 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3983 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3984 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3985 | __ testl(shifter, Immediate(32)); |
| 3986 | __ j(kEqual, &done); |
| 3987 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3988 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3989 | __ Bind(&done); |
| 3990 | } |
| 3991 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3992 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3993 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3994 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3995 | if (shift == 32) { |
| 3996 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3997 | codegen_->EmitParallelMoves( |
| 3998 | loc.ToHigh(), |
| 3999 | loc.ToLow(), |
| 4000 | Primitive::kPrimInt, |
| 4001 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4002 | loc.ToHigh(), |
| 4003 | Primitive::kPrimInt); |
| 4004 | } else if (shift > 32) { |
| 4005 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4006 | __ movl(low, high); |
| 4007 | __ shrl(low, Immediate(shift - 32)); |
| 4008 | __ xorl(high, high); |
| 4009 | } else { |
| 4010 | // Between 1 and 31. |
| 4011 | __ shrd(low, high, Immediate(shift)); |
| 4012 | __ shrl(high, Immediate(shift)); |
| 4013 | } |
| 4014 | } |
| 4015 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4016 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4017 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4018 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4019 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4020 | __ testl(shifter, Immediate(32)); |
| 4021 | __ j(kEqual, &done); |
| 4022 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4023 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4024 | __ Bind(&done); |
| 4025 | } |
| 4026 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4027 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4028 | LocationSummary* locations = |
| 4029 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4030 | |
| 4031 | switch (ror->GetResultType()) { |
| 4032 | case Primitive::kPrimLong: |
| 4033 | // Add the temporary needed. |
| 4034 | locations->AddTemp(Location::RequiresRegister()); |
| 4035 | FALLTHROUGH_INTENDED; |
| 4036 | case Primitive::kPrimInt: |
| 4037 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4038 | // The shift count needs to be in CL (unless it is a constant). |
| 4039 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4040 | locations->SetOut(Location::SameAsFirstInput()); |
| 4041 | break; |
| 4042 | default: |
| 4043 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4044 | UNREACHABLE(); |
| 4045 | } |
| 4046 | } |
| 4047 | |
| 4048 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4049 | LocationSummary* locations = ror->GetLocations(); |
| 4050 | Location first = locations->InAt(0); |
| 4051 | Location second = locations->InAt(1); |
| 4052 | |
| 4053 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 4054 | Register first_reg = first.AsRegister<Register>(); |
| 4055 | if (second.IsRegister()) { |
| 4056 | Register second_reg = second.AsRegister<Register>(); |
| 4057 | __ rorl(first_reg, second_reg); |
| 4058 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4059 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4060 | __ rorl(first_reg, imm); |
| 4061 | } |
| 4062 | return; |
| 4063 | } |
| 4064 | |
| 4065 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 4066 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4067 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4068 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4069 | if (second.IsRegister()) { |
| 4070 | Register second_reg = second.AsRegister<Register>(); |
| 4071 | DCHECK_EQ(second_reg, ECX); |
| 4072 | __ movl(temp_reg, first_reg_hi); |
| 4073 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4074 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4075 | __ movl(temp_reg, first_reg_hi); |
| 4076 | __ testl(second_reg, Immediate(32)); |
| 4077 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4078 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4079 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4080 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4081 | if (shift_amt == 0) { |
| 4082 | // Already fine. |
| 4083 | return; |
| 4084 | } |
| 4085 | if (shift_amt == 32) { |
| 4086 | // Just swap. |
| 4087 | __ movl(temp_reg, first_reg_lo); |
| 4088 | __ movl(first_reg_lo, first_reg_hi); |
| 4089 | __ movl(first_reg_hi, temp_reg); |
| 4090 | return; |
| 4091 | } |
| 4092 | |
| 4093 | Immediate imm(shift_amt); |
| 4094 | // Save the constents of the low value. |
| 4095 | __ movl(temp_reg, first_reg_lo); |
| 4096 | |
| 4097 | // Shift right into low, feeding bits from high. |
| 4098 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4099 | |
| 4100 | // Shift right into high, feeding bits from the original low. |
| 4101 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4102 | |
| 4103 | // Swap if needed. |
| 4104 | if (shift_amt > 32) { |
| 4105 | __ movl(temp_reg, first_reg_lo); |
| 4106 | __ movl(first_reg_lo, first_reg_hi); |
| 4107 | __ movl(first_reg_hi, temp_reg); |
| 4108 | } |
| 4109 | } |
| 4110 | } |
| 4111 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4112 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4113 | HandleShift(shl); |
| 4114 | } |
| 4115 | |
| 4116 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4117 | HandleShift(shl); |
| 4118 | } |
| 4119 | |
| 4120 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4121 | HandleShift(shr); |
| 4122 | } |
| 4123 | |
| 4124 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4125 | HandleShift(shr); |
| 4126 | } |
| 4127 | |
| 4128 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4129 | HandleShift(ushr); |
| 4130 | } |
| 4131 | |
| 4132 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4133 | HandleShift(ushr); |
| 4134 | } |
| 4135 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4136 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4137 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4138 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4139 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4140 | if (instruction->IsStringAlloc()) { |
| 4141 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4142 | } else { |
| 4143 | InvokeRuntimeCallingConvention calling_convention; |
| 4144 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4145 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4146 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4150 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4151 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4152 | if (instruction->IsStringAlloc()) { |
| 4153 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4154 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4155 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4156 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4157 | __ call(Address(temp, code_offset.Int32Value())); |
| 4158 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4159 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4160 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4161 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4162 | DCHECK(!codegen_->IsLeafMethod()); |
| 4163 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4164 | } |
| 4165 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4166 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4167 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4168 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4169 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4170 | InvokeRuntimeCallingConvention calling_convention; |
| 4171 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4172 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4173 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4177 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4178 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4179 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4180 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4181 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4182 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4183 | DCHECK(!codegen_->IsLeafMethod()); |
| 4184 | } |
| 4185 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4186 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4187 | LocationSummary* locations = |
| 4188 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4189 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4190 | if (location.IsStackSlot()) { |
| 4191 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4192 | } else if (location.IsDoubleStackSlot()) { |
| 4193 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4194 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4195 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4196 | } |
| 4197 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4198 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4199 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4200 | } |
| 4201 | |
| 4202 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4203 | LocationSummary* locations = |
| 4204 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4205 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4206 | } |
| 4207 | |
| 4208 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4209 | } |
| 4210 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4211 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4212 | LocationSummary* locations = |
| 4213 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4214 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4215 | locations->SetOut(Location::RequiresRegister()); |
| 4216 | } |
| 4217 | |
| 4218 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4219 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4220 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4221 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4222 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4223 | __ movl(locations->Out().AsRegister<Register>(), |
| 4224 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4225 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4226 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4227 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4228 | __ movl(locations->Out().AsRegister<Register>(), |
| 4229 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4230 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4231 | // temp = temp->GetImtEntryAt(method_offset); |
| 4232 | __ movl(locations->Out().AsRegister<Register>(), |
| 4233 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4234 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4235 | } |
| 4236 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4237 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4238 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4239 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4240 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4241 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4242 | } |
| 4243 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4244 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4245 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4246 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4247 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4248 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4249 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4250 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4251 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4252 | break; |
| 4253 | |
| 4254 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4255 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4256 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4257 | break; |
| 4258 | |
| 4259 | default: |
| 4260 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4261 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4262 | } |
| 4263 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4264 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4265 | LocationSummary* locations = |
| 4266 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4267 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4268 | locations->SetOut(Location::SameAsFirstInput()); |
| 4269 | } |
| 4270 | |
| 4271 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4272 | LocationSummary* locations = bool_not->GetLocations(); |
| 4273 | Location in = locations->InAt(0); |
| 4274 | Location out = locations->Out(); |
| 4275 | DCHECK(in.Equals(out)); |
| 4276 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4277 | } |
| 4278 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4279 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4280 | LocationSummary* locations = |
| 4281 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4282 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4283 | case Primitive::kPrimBoolean: |
| 4284 | case Primitive::kPrimByte: |
| 4285 | case Primitive::kPrimShort: |
| 4286 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4287 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4288 | case Primitive::kPrimLong: { |
| 4289 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4290 | locations->SetInAt(1, Location::Any()); |
| 4291 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4292 | break; |
| 4293 | } |
| 4294 | case Primitive::kPrimFloat: |
| 4295 | case Primitive::kPrimDouble: { |
| 4296 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4297 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4298 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4299 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4300 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4301 | } else { |
| 4302 | locations->SetInAt(1, Location::Any()); |
| 4303 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4304 | locations->SetOut(Location::RequiresRegister()); |
| 4305 | break; |
| 4306 | } |
| 4307 | default: |
| 4308 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4309 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4313 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4314 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4315 | Location left = locations->InAt(0); |
| 4316 | Location right = locations->InAt(1); |
| 4317 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4318 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4319 | Condition less_cond = kLess; |
| 4320 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4321 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4322 | case Primitive::kPrimBoolean: |
| 4323 | case Primitive::kPrimByte: |
| 4324 | case Primitive::kPrimShort: |
| 4325 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4326 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4327 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4328 | break; |
| 4329 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4330 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4331 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4332 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4333 | int32_t val_low = 0; |
| 4334 | int32_t val_high = 0; |
| 4335 | bool right_is_const = false; |
| 4336 | |
| 4337 | if (right.IsConstant()) { |
| 4338 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4339 | right_is_const = true; |
| 4340 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4341 | val_low = Low32Bits(val); |
| 4342 | val_high = High32Bits(val); |
| 4343 | } |
| 4344 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4345 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4346 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4347 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4348 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4349 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4350 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4351 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4352 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4353 | __ j(kLess, &less); // Signed compare. |
| 4354 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4355 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4356 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4357 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4358 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4359 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4360 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4361 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4362 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4363 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4364 | break; |
| 4365 | } |
| 4366 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4367 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4368 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4369 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4370 | break; |
| 4371 | } |
| 4372 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4373 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4374 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4375 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4376 | break; |
| 4377 | } |
| 4378 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4379 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4380 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4381 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4382 | __ movl(out, Immediate(0)); |
| 4383 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4384 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4385 | |
| 4386 | __ Bind(&greater); |
| 4387 | __ movl(out, Immediate(1)); |
| 4388 | __ jmp(&done); |
| 4389 | |
| 4390 | __ Bind(&less); |
| 4391 | __ movl(out, Immediate(-1)); |
| 4392 | |
| 4393 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4394 | } |
| 4395 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4396 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4397 | LocationSummary* locations = |
| 4398 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4399 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4400 | locations->SetInAt(i, Location::Any()); |
| 4401 | } |
| 4402 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4403 | } |
| 4404 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4405 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4406 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4407 | } |
| 4408 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4409 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4410 | /* |
| 4411 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4412 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4413 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4414 | */ |
| 4415 | switch (kind) { |
| 4416 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4417 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4418 | break; |
| 4419 | } |
| 4420 | case MemBarrierKind::kAnyStore: |
| 4421 | case MemBarrierKind::kLoadAny: |
| 4422 | case MemBarrierKind::kStoreStore: { |
| 4423 | // nop |
| 4424 | break; |
| 4425 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4426 | case MemBarrierKind::kNTStoreStore: |
| 4427 | // Non-Temporal Store/Store needs an explicit fence. |
| 4428 | MemoryFence(/* non-temporal */ true); |
| 4429 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4430 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4431 | } |
| 4432 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4433 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4434 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4435 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4436 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4437 | |
| 4438 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4439 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4440 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4441 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4442 | if (GetGraph()->HasIrreducibleLoops() && |
| 4443 | (dispatch_info.method_load_kind == |
| 4444 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4445 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4446 | } |
| 4447 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4448 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4449 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4450 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4451 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4452 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4453 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4454 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4455 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4456 | 0u |
| 4457 | }; |
| 4458 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4459 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4460 | } |
| 4461 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4462 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4463 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4464 | Register temp) { |
| 4465 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4466 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4467 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4468 | return location.AsRegister<Register>(); |
| 4469 | } |
| 4470 | // For intrinsics we allow any location, so it may be on the stack. |
| 4471 | if (!location.IsRegister()) { |
| 4472 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4473 | return temp; |
| 4474 | } |
| 4475 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4476 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4477 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4478 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4479 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4480 | if (slow_path != nullptr) { |
| 4481 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4482 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4483 | __ movl(temp, Address(ESP, stack_offset)); |
| 4484 | return temp; |
| 4485 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4486 | } |
| 4487 | return location.AsRegister<Register>(); |
| 4488 | } |
| 4489 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4490 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4491 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4492 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4493 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4494 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4495 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4496 | uint32_t offset = |
| 4497 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4498 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4499 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4500 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4501 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4502 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | break; |
| 4504 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4505 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4506 | break; |
| 4507 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4508 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4509 | method_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 4510 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4511 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4512 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4513 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4514 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4515 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4516 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4517 | // Bind a new fixup label at the end of the "movl" insn. |
| 4518 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4519 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4520 | break; |
| 4521 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4522 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4523 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4524 | Register method_reg; |
| 4525 | Register reg = temp.AsRegister<Register>(); |
| 4526 | if (current_method.IsRegister()) { |
| 4527 | method_reg = current_method.AsRegister<Register>(); |
| 4528 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4529 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4530 | DCHECK(!current_method.IsValid()); |
| 4531 | method_reg = reg; |
| 4532 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4533 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4534 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4535 | __ movl(reg, Address(method_reg, |
| 4536 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4537 | // temp = temp[index_in_cache]; |
| 4538 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4539 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4540 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4541 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4542 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4543 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4544 | return callee_method; |
| 4545 | } |
| 4546 | |
| 4547 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4548 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4549 | |
| 4550 | switch (invoke->GetCodePtrLocation()) { |
| 4551 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4552 | __ call(GetFrameEntryLabel()); |
| 4553 | break; |
| 4554 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4555 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 4556 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4557 | Label* label = &relative_call_patches_.back().label; |
| 4558 | __ call(label); // Bind to the patch label, override at link time. |
| 4559 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4560 | break; |
| 4561 | } |
| 4562 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4563 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4564 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4565 | LOG(FATAL) << "Unsupported"; |
| 4566 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4567 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4568 | // (callee_method + offset_of_quick_compiled_code)() |
| 4569 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4570 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4571 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4572 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4573 | } |
| 4574 | |
| 4575 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4576 | } |
| 4577 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4578 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4579 | Register temp = temp_in.AsRegister<Register>(); |
| 4580 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4581 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4582 | |
| 4583 | // Use the calling convention instead of the location of the receiver, as |
| 4584 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4585 | // slow path, the arguments have been moved to the right place, so here we are |
| 4586 | // guaranteed that the receiver is the first register of the calling convention. |
| 4587 | InvokeDexCallingConvention calling_convention; |
| 4588 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4589 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4590 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4591 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4592 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4593 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4594 | // emit a read barrier for the previous class reference load. |
| 4595 | // However this is not required in practice, as this is an |
| 4596 | // intermediate/temporary reference and because the current |
| 4597 | // concurrent copying collector keeps the from-space memory |
| 4598 | // intact/accessible until the end of the marking phase (the |
| 4599 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4600 | __ MaybeUnpoisonHeapReference(temp); |
| 4601 | // temp = temp->GetMethodAt(method_offset); |
| 4602 | __ movl(temp, Address(temp, method_offset)); |
| 4603 | // call temp->GetEntryPoint(); |
| 4604 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4605 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4606 | } |
| 4607 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4608 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4609 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4610 | simple_patches_.emplace_back(); |
| 4611 | __ Bind(&simple_patches_.back()); |
| 4612 | } |
| 4613 | } |
| 4614 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4615 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
| 4616 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4617 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4618 | __ Bind(&string_patches_.back().label); |
| 4619 | } |
| 4620 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4621 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
| 4622 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 4623 | __ Bind(&type_patches_.back().label); |
| 4624 | } |
| 4625 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4626 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4627 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| 4628 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4629 | return &string_patches_.back().label; |
| 4630 | } |
| 4631 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4632 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4633 | uint32_t element_offset) { |
| 4634 | // Add the patch entry and bind its label at the end of the instruction. |
| 4635 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4636 | return &pc_relative_dex_cache_patches_.back().label; |
| 4637 | } |
| 4638 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4639 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4640 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4641 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4642 | |
| 4643 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4644 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| 4645 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 4646 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4647 | for (const PatchInfo<Label>& info : infos) { |
| 4648 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4649 | linker_patches->push_back( |
| 4650 | Factory(literal_offset, &info.dex_file, GetMethodAddressOffset(), info.index)); |
| 4651 | } |
| 4652 | } |
| 4653 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4654 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4655 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4656 | size_t size = |
| 4657 | method_patches_.size() + |
| 4658 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4659 | pc_relative_dex_cache_patches_.size() + |
| 4660 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4661 | string_patches_.size() + |
| 4662 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4663 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4664 | for (const PatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4665 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4666 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4667 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4668 | for (const PatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4669 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4670 | linker_patches->push_back( |
| 4671 | LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4672 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4673 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 4674 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4675 | for (const Label& label : simple_patches_) { |
| 4676 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4677 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4678 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4679 | if (!GetCompilerOptions().IsBootImage()) { |
| 4680 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 4681 | } else if (GetCompilerOptions().GetCompilePic()) { |
| 4682 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4683 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4684 | for (const PatchInfo<Label>& info : string_patches_) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4685 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4686 | linker_patches->push_back( |
| 4687 | LinkerPatch::StringPatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4688 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4689 | } |
| 4690 | if (GetCompilerOptions().GetCompilePic()) { |
| 4691 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(type_patches_, linker_patches); |
| 4692 | } else { |
| 4693 | for (const PatchInfo<Label>& info : type_patches_) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4694 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4695 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4696 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4697 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4698 | } |
| 4699 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4700 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4701 | Register card, |
| 4702 | Register object, |
| 4703 | Register value, |
| 4704 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4705 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4706 | if (value_can_be_null) { |
| 4707 | __ testl(value, value); |
| 4708 | __ j(kEqual, &is_null); |
| 4709 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4710 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4711 | __ movl(temp, object); |
| 4712 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4713 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4714 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4715 | if (value_can_be_null) { |
| 4716 | __ Bind(&is_null); |
| 4717 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4718 | } |
| 4719 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4720 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4721 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4722 | |
| 4723 | bool object_field_get_with_read_barrier = |
| 4724 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4725 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4726 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4727 | kEmitCompilerReadBarrier ? |
| 4728 | LocationSummary::kCallOnSlowPath : |
| 4729 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4730 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4731 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4732 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4733 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4734 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4735 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4736 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4737 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4738 | // The output overlaps in case of long: we don't want the low move |
| 4739 | // to overwrite the object's location. Likewise, in the case of |
| 4740 | // an object field get with read barriers enabled, we do not want |
| 4741 | // the move to overwrite the object's location, as we need it to emit |
| 4742 | // the read barrier. |
| 4743 | locations->SetOut( |
| 4744 | Location::RequiresRegister(), |
| 4745 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4746 | Location::kOutputOverlap : |
| 4747 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4748 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4749 | |
| 4750 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4751 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4752 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4753 | // load the temp into the XMM and then copy the XMM into the |
| 4754 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4755 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4756 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4757 | } |
| 4758 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4759 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4760 | const FieldInfo& field_info) { |
| 4761 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4762 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4763 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4764 | Location base_loc = locations->InAt(0); |
| 4765 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4766 | Location out = locations->Out(); |
| 4767 | bool is_volatile = field_info.IsVolatile(); |
| 4768 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4769 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4770 | |
| 4771 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4772 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4773 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4774 | break; |
| 4775 | } |
| 4776 | |
| 4777 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4778 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4779 | break; |
| 4780 | } |
| 4781 | |
| 4782 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4783 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4784 | break; |
| 4785 | } |
| 4786 | |
| 4787 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4788 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4789 | break; |
| 4790 | } |
| 4791 | |
| 4792 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4793 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4794 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4795 | |
| 4796 | case Primitive::kPrimNot: { |
| 4797 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4798 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4799 | // Note that a potential implicit null check is handled in this |
| 4800 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4801 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4802 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4803 | if (is_volatile) { |
| 4804 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4805 | } |
| 4806 | } else { |
| 4807 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4808 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4809 | if (is_volatile) { |
| 4810 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4811 | } |
| 4812 | // If read barriers are enabled, emit read barriers other than |
| 4813 | // Baker's using a slow path (and also unpoison the loaded |
| 4814 | // reference, if heap poisoning is enabled). |
| 4815 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4816 | } |
| 4817 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4821 | if (is_volatile) { |
| 4822 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4823 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4824 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4825 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4826 | __ psrlq(temp, Immediate(32)); |
| 4827 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4828 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4829 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4830 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4831 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4832 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4833 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4834 | break; |
| 4835 | } |
| 4836 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4837 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4838 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4839 | break; |
| 4840 | } |
| 4841 | |
| 4842 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4843 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4844 | break; |
| 4845 | } |
| 4846 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4847 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4848 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4849 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4850 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4851 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4852 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4853 | // Potential implicit null checks, in the case of reference or |
| 4854 | // long fields, are handled in the previous switch statement. |
| 4855 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4856 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4857 | } |
| 4858 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4859 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4860 | if (field_type == Primitive::kPrimNot) { |
| 4861 | // Memory barriers, in the case of references, are also handled |
| 4862 | // in the previous switch statement. |
| 4863 | } else { |
| 4864 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4865 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4866 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4870 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4871 | |
| 4872 | LocationSummary* locations = |
| 4873 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4875 | bool is_volatile = field_info.IsVolatile(); |
| 4876 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4877 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4878 | || (field_type == Primitive::kPrimByte); |
| 4879 | |
| 4880 | // The register allocator does not support multiple |
| 4881 | // inputs that die at entry with one in a specific register. |
| 4882 | if (is_byte_type) { |
| 4883 | // Ensure the value is in a byte register. |
| 4884 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4885 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4886 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4887 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4888 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4889 | } else { |
| 4890 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4891 | } |
| 4892 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4893 | // 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] | 4894 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4895 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4896 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4897 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4898 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4899 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4900 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4901 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4902 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4903 | } else { |
| 4904 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4905 | |
| 4906 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4907 | // Temporary registers for the write barrier. |
| 4908 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4909 | // Ensure the card is in a byte register. |
| 4910 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4911 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4912 | } |
| 4913 | } |
| 4914 | |
| 4915 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4916 | const FieldInfo& field_info, |
| 4917 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4918 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4919 | |
| 4920 | LocationSummary* locations = instruction->GetLocations(); |
| 4921 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4922 | Location value = locations->InAt(1); |
| 4923 | bool is_volatile = field_info.IsVolatile(); |
| 4924 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4925 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4926 | bool needs_write_barrier = |
| 4927 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4928 | |
| 4929 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4930 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4931 | } |
| 4932 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4933 | bool maybe_record_implicit_null_check_done = false; |
| 4934 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4935 | switch (field_type) { |
| 4936 | case Primitive::kPrimBoolean: |
| 4937 | case Primitive::kPrimByte: { |
| 4938 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4939 | break; |
| 4940 | } |
| 4941 | |
| 4942 | case Primitive::kPrimShort: |
| 4943 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4944 | if (value.IsConstant()) { |
| 4945 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4946 | __ movw(Address(base, offset), Immediate(v)); |
| 4947 | } else { |
| 4948 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4949 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4950 | break; |
| 4951 | } |
| 4952 | |
| 4953 | case Primitive::kPrimInt: |
| 4954 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4955 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4956 | // Note that in the case where `value` is a null reference, |
| 4957 | // we do not enter this block, as the reference does not |
| 4958 | // need poisoning. |
| 4959 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4960 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4961 | __ movl(temp, value.AsRegister<Register>()); |
| 4962 | __ PoisonHeapReference(temp); |
| 4963 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4964 | } else if (value.IsConstant()) { |
| 4965 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4966 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4967 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4968 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4969 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4970 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4971 | break; |
| 4972 | } |
| 4973 | |
| 4974 | case Primitive::kPrimLong: { |
| 4975 | if (is_volatile) { |
| 4976 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4977 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4978 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4979 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4980 | __ punpckldq(temp1, temp2); |
| 4981 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4982 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4983 | } else if (value.IsConstant()) { |
| 4984 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4985 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4986 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4987 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4988 | } else { |
| 4989 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4990 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4991 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4992 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4993 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4994 | break; |
| 4995 | } |
| 4996 | |
| 4997 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4998 | if (value.IsConstant()) { |
| 4999 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5000 | __ movl(Address(base, offset), Immediate(v)); |
| 5001 | } else { |
| 5002 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5003 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5004 | break; |
| 5005 | } |
| 5006 | |
| 5007 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5008 | if (value.IsConstant()) { |
| 5009 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5010 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5011 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5012 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5013 | maybe_record_implicit_null_check_done = true; |
| 5014 | } else { |
| 5015 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5016 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5017 | break; |
| 5018 | } |
| 5019 | |
| 5020 | case Primitive::kPrimVoid: |
| 5021 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5022 | UNREACHABLE(); |
| 5023 | } |
| 5024 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5025 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5026 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5027 | } |
| 5028 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5029 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5030 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5031 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5032 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5035 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5036 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5037 | } |
| 5038 | } |
| 5039 | |
| 5040 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5041 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5042 | } |
| 5043 | |
| 5044 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5045 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5046 | } |
| 5047 | |
| 5048 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5049 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5050 | } |
| 5051 | |
| 5052 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5053 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5057 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5058 | } |
| 5059 | |
| 5060 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5061 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5065 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5066 | } |
| 5067 | |
| 5068 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5069 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5070 | } |
| 5071 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5072 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5073 | HUnresolvedInstanceFieldGet* instruction) { |
| 5074 | FieldAccessCallingConventionX86 calling_convention; |
| 5075 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5076 | instruction, instruction->GetFieldType(), calling_convention); |
| 5077 | } |
| 5078 | |
| 5079 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5080 | HUnresolvedInstanceFieldGet* instruction) { |
| 5081 | FieldAccessCallingConventionX86 calling_convention; |
| 5082 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5083 | instruction->GetFieldType(), |
| 5084 | instruction->GetFieldIndex(), |
| 5085 | instruction->GetDexPc(), |
| 5086 | calling_convention); |
| 5087 | } |
| 5088 | |
| 5089 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5090 | HUnresolvedInstanceFieldSet* instruction) { |
| 5091 | FieldAccessCallingConventionX86 calling_convention; |
| 5092 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5093 | instruction, instruction->GetFieldType(), calling_convention); |
| 5094 | } |
| 5095 | |
| 5096 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5097 | HUnresolvedInstanceFieldSet* instruction) { |
| 5098 | FieldAccessCallingConventionX86 calling_convention; |
| 5099 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5100 | instruction->GetFieldType(), |
| 5101 | instruction->GetFieldIndex(), |
| 5102 | instruction->GetDexPc(), |
| 5103 | calling_convention); |
| 5104 | } |
| 5105 | |
| 5106 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5107 | HUnresolvedStaticFieldGet* instruction) { |
| 5108 | FieldAccessCallingConventionX86 calling_convention; |
| 5109 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5110 | instruction, instruction->GetFieldType(), calling_convention); |
| 5111 | } |
| 5112 | |
| 5113 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5114 | HUnresolvedStaticFieldGet* instruction) { |
| 5115 | FieldAccessCallingConventionX86 calling_convention; |
| 5116 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5117 | instruction->GetFieldType(), |
| 5118 | instruction->GetFieldIndex(), |
| 5119 | instruction->GetDexPc(), |
| 5120 | calling_convention); |
| 5121 | } |
| 5122 | |
| 5123 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5124 | HUnresolvedStaticFieldSet* instruction) { |
| 5125 | FieldAccessCallingConventionX86 calling_convention; |
| 5126 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5127 | instruction, instruction->GetFieldType(), calling_convention); |
| 5128 | } |
| 5129 | |
| 5130 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5131 | HUnresolvedStaticFieldSet* instruction) { |
| 5132 | FieldAccessCallingConventionX86 calling_convention; |
| 5133 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5134 | instruction->GetFieldType(), |
| 5135 | instruction->GetFieldIndex(), |
| 5136 | instruction->GetDexPc(), |
| 5137 | calling_convention); |
| 5138 | } |
| 5139 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5140 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5141 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5142 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5143 | ? Location::RequiresRegister() |
| 5144 | : Location::Any(); |
| 5145 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5146 | } |
| 5147 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5148 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5149 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5150 | return; |
| 5151 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5152 | LocationSummary* locations = instruction->GetLocations(); |
| 5153 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5154 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5155 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5156 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5157 | } |
| 5158 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5159 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5160 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5161 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5162 | |
| 5163 | LocationSummary* locations = instruction->GetLocations(); |
| 5164 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5165 | |
| 5166 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5167 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5168 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5169 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5170 | } else { |
| 5171 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5172 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5173 | __ jmp(slow_path->GetEntryLabel()); |
| 5174 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5175 | } |
| 5176 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5177 | } |
| 5178 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5179 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5180 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5181 | } |
| 5182 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5183 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5184 | bool object_array_get_with_read_barrier = |
| 5185 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5186 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5187 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5188 | object_array_get_with_read_barrier ? |
| 5189 | LocationSummary::kCallOnSlowPath : |
| 5190 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5191 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5192 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5193 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5194 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5195 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5196 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5197 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5198 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5199 | // The output overlaps in case of long: we don't want the low move |
| 5200 | // to overwrite the array's location. Likewise, in the case of an |
| 5201 | // object array get with read barriers enabled, we do not want the |
| 5202 | // move to overwrite the array's location, as we need it to emit |
| 5203 | // the read barrier. |
| 5204 | locations->SetOut( |
| 5205 | Location::RequiresRegister(), |
| 5206 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5207 | Location::kOutputOverlap : |
| 5208 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5209 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5213 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5214 | Location obj_loc = locations->InAt(0); |
| 5215 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5216 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5217 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5218 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5219 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5220 | Primitive::Type type = instruction->GetType(); |
| 5221 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5222 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5223 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5224 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5225 | break; |
| 5226 | } |
| 5227 | |
| 5228 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5229 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5230 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5231 | break; |
| 5232 | } |
| 5233 | |
| 5234 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5235 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5236 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5237 | break; |
| 5238 | } |
| 5239 | |
| 5240 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5241 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5242 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5243 | // Branch cases into compressed and uncompressed for each index's type. |
| 5244 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5245 | NearLabel done, not_compressed; |
| 5246 | __ cmpl(Address(obj, count_offset), Immediate(0)); |
| 5247 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5248 | __ j(kGreaterEqual, ¬_compressed); |
| 5249 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5250 | __ jmp(&done); |
| 5251 | __ Bind(¬_compressed); |
| 5252 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5253 | __ Bind(&done); |
| 5254 | } else { |
| 5255 | // Common case for charAt of array of char or when string compression's |
| 5256 | // feature is turned off. |
| 5257 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5258 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5259 | break; |
| 5260 | } |
| 5261 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5262 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5263 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5264 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5265 | break; |
| 5266 | } |
| 5267 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5268 | case Primitive::kPrimNot: { |
| 5269 | static_assert( |
| 5270 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5271 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5272 | // /* HeapReference<Object> */ out = |
| 5273 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5274 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5275 | // Note that a potential implicit null check is handled in this |
| 5276 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5277 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5278 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5279 | } else { |
| 5280 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5281 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5282 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5283 | // If read barriers are enabled, emit read barriers other than |
| 5284 | // Baker's using a slow path (and also unpoison the loaded |
| 5285 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5286 | if (index.IsConstant()) { |
| 5287 | uint32_t offset = |
| 5288 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5289 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5290 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5291 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5292 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5293 | } |
| 5294 | } |
| 5295 | break; |
| 5296 | } |
| 5297 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5298 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5299 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5300 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5301 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5302 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5303 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5304 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5305 | break; |
| 5306 | } |
| 5307 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5308 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5309 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5310 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5311 | break; |
| 5312 | } |
| 5313 | |
| 5314 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5315 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5316 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5317 | break; |
| 5318 | } |
| 5319 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5320 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5321 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5322 | UNREACHABLE(); |
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 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5325 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5326 | // Potential implicit null checks, in the case of reference or |
| 5327 | // long arrays, are handled in the previous switch statement. |
| 5328 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5329 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5330 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5334 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5335 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5336 | bool needs_write_barrier = |
| 5337 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5338 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5339 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5340 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5341 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5342 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5343 | LocationSummary::kCallOnSlowPath : |
| 5344 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5345 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5346 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5347 | || (value_type == Primitive::kPrimByte); |
| 5348 | // We need the inputs to be different than the output in case of long operation. |
| 5349 | // In case of a byte operation, the register allocator does not support multiple |
| 5350 | // inputs that die at entry with one in a specific register. |
| 5351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5352 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5353 | if (is_byte_type) { |
| 5354 | // Ensure the value is in a byte register. |
| 5355 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5356 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5357 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5358 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5359 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5360 | } |
| 5361 | if (needs_write_barrier) { |
| 5362 | // Temporary registers for the write barrier. |
| 5363 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5364 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5365 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5366 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5367 | } |
| 5368 | |
| 5369 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5370 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5371 | Location array_loc = locations->InAt(0); |
| 5372 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5373 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5374 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5375 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5376 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5377 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5378 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5379 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5380 | bool needs_write_barrier = |
| 5381 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5382 | |
| 5383 | switch (value_type) { |
| 5384 | case Primitive::kPrimBoolean: |
| 5385 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5386 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5387 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5388 | if (value.IsRegister()) { |
| 5389 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5390 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5391 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5392 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5393 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5394 | break; |
| 5395 | } |
| 5396 | |
| 5397 | case Primitive::kPrimShort: |
| 5398 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5399 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5400 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5401 | if (value.IsRegister()) { |
| 5402 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5403 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5404 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5405 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5406 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5407 | break; |
| 5408 | } |
| 5409 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5410 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5411 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5412 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5413 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5414 | if (!value.IsRegister()) { |
| 5415 | // Just setting null. |
| 5416 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5417 | DCHECK(value.IsConstant()) << value; |
| 5418 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5419 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5420 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5421 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5422 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5423 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5424 | |
| 5425 | DCHECK(needs_write_barrier); |
| 5426 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5427 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5428 | // short when Baker read barriers are enabled. |
| 5429 | Label done; |
| 5430 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5431 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5432 | Location temp_loc = locations->GetTemp(0); |
| 5433 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5434 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5435 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5436 | codegen_->AddSlowPath(slow_path); |
| 5437 | if (instruction->GetValueCanBeNull()) { |
| 5438 | __ testl(register_value, register_value); |
| 5439 | __ j(kNotEqual, ¬_null); |
| 5440 | __ movl(address, Immediate(0)); |
| 5441 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5442 | __ jmp(&done); |
| 5443 | __ Bind(¬_null); |
| 5444 | } |
| 5445 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5446 | // Note that when Baker read barriers are enabled, the type |
| 5447 | // checks are performed without read barriers. This is fine, |
| 5448 | // even in the case where a class object is in the from-space |
| 5449 | // after the flip, as a comparison involving such a type would |
| 5450 | // not produce a false positive; it may of course produce a |
| 5451 | // false negative, in which case we would take the ArraySet |
| 5452 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5453 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5454 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5455 | __ movl(temp, Address(array, class_offset)); |
| 5456 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5457 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5458 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5459 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5460 | __ movl(temp, Address(temp, component_offset)); |
| 5461 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5462 | // nor the object reference in `register_value->klass`, as |
| 5463 | // we are comparing two poisoned references. |
| 5464 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5465 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5466 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5467 | __ j(kEqual, &do_put); |
| 5468 | // If heap poisoning is enabled, the `temp` reference has |
| 5469 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5470 | __ MaybeUnpoisonHeapReference(temp); |
| 5471 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5472 | // If heap poisoning is enabled, no need to unpoison the |
| 5473 | // heap reference loaded below, as it is only used for a |
| 5474 | // comparison with null. |
| 5475 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5476 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5477 | __ Bind(&do_put); |
| 5478 | } else { |
| 5479 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5480 | } |
| 5481 | } |
| 5482 | |
| 5483 | if (kPoisonHeapReferences) { |
| 5484 | __ movl(temp, register_value); |
| 5485 | __ PoisonHeapReference(temp); |
| 5486 | __ movl(address, temp); |
| 5487 | } else { |
| 5488 | __ movl(address, register_value); |
| 5489 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5490 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5491 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5492 | } |
| 5493 | |
| 5494 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5495 | codegen_->MarkGCCard( |
| 5496 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5497 | __ Bind(&done); |
| 5498 | |
| 5499 | if (slow_path != nullptr) { |
| 5500 | __ Bind(slow_path->GetExitLabel()); |
| 5501 | } |
| 5502 | |
| 5503 | break; |
| 5504 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5505 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5506 | case Primitive::kPrimInt: { |
| 5507 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5508 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5509 | if (value.IsRegister()) { |
| 5510 | __ movl(address, value.AsRegister<Register>()); |
| 5511 | } else { |
| 5512 | DCHECK(value.IsConstant()) << value; |
| 5513 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5514 | __ movl(address, Immediate(v)); |
| 5515 | } |
| 5516 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5517 | break; |
| 5518 | } |
| 5519 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5520 | case Primitive::kPrimLong: { |
| 5521 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5522 | if (value.IsRegisterPair()) { |
| 5523 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5524 | value.AsRegisterPairLow<Register>()); |
| 5525 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5526 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5527 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5528 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5529 | DCHECK(value.IsConstant()); |
| 5530 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5531 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5532 | Immediate(Low32Bits(val))); |
| 5533 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5534 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5535 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5536 | } |
| 5537 | break; |
| 5538 | } |
| 5539 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5540 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5541 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5542 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5543 | if (value.IsFpuRegister()) { |
| 5544 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5545 | } else { |
| 5546 | DCHECK(value.IsConstant()); |
| 5547 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5548 | __ movl(address, Immediate(v)); |
| 5549 | } |
| 5550 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5551 | break; |
| 5552 | } |
| 5553 | |
| 5554 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5555 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5556 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5557 | if (value.IsFpuRegister()) { |
| 5558 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5559 | } else { |
| 5560 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5561 | Address address_hi = |
| 5562 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5563 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5564 | __ movl(address, Immediate(Low32Bits(v))); |
| 5565 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5566 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5567 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5568 | break; |
| 5569 | } |
| 5570 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5571 | case Primitive::kPrimVoid: |
| 5572 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5573 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5574 | } |
| 5575 | } |
| 5576 | |
| 5577 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5578 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5579 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5580 | if (!instruction->IsEmittedAtUseSite()) { |
| 5581 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5582 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5583 | } |
| 5584 | |
| 5585 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5586 | if (instruction->IsEmittedAtUseSite()) { |
| 5587 | return; |
| 5588 | } |
| 5589 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5590 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5591 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5592 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5593 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5594 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5595 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5596 | // Mask out most significant bit in case the array is String's array of char. |
| 5597 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 5598 | __ andl(out, Immediate(INT32_MAX)); |
| 5599 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5603 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5604 | InvokeRuntimeCallingConvention calling_convention; |
| 5605 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5606 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5607 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5608 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5609 | HInstruction* length = instruction->InputAt(1); |
| 5610 | if (!length->IsEmittedAtUseSite()) { |
| 5611 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5612 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5613 | // Need register to see array's length. |
| 5614 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5615 | locations->AddTemp(Location::RequiresRegister()); |
| 5616 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5620 | const bool is_string_compressed_char_at = |
| 5621 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5622 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5623 | Location index_loc = locations->InAt(0); |
| 5624 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5625 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5626 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5627 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5628 | if (length_loc.IsConstant()) { |
| 5629 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5630 | if (index_loc.IsConstant()) { |
| 5631 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5632 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5633 | if (index < 0 || index >= length) { |
| 5634 | codegen_->AddSlowPath(slow_path); |
| 5635 | __ jmp(slow_path->GetEntryLabel()); |
| 5636 | } else { |
| 5637 | // Some optimization after BCE may have generated this, and we should not |
| 5638 | // generate a bounds check if it is a valid range. |
| 5639 | } |
| 5640 | return; |
| 5641 | } |
| 5642 | |
| 5643 | // We have to reverse the jump condition because the length is the constant. |
| 5644 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5645 | __ cmpl(index_reg, Immediate(length)); |
| 5646 | codegen_->AddSlowPath(slow_path); |
| 5647 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5648 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5649 | HInstruction* array_length = instruction->InputAt(1); |
| 5650 | if (array_length->IsEmittedAtUseSite()) { |
| 5651 | // Address the length field in the array. |
| 5652 | DCHECK(array_length->IsArrayLength()); |
| 5653 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5654 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5655 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5656 | if (is_string_compressed_char_at) { |
| 5657 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5658 | __ movl(length_reg, array_len); |
| 5659 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| 5660 | __ andl(length_reg, Immediate(INT32_MAX)); |
| 5661 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5662 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5663 | // Checking bounds for general case: |
| 5664 | // Array of char or string's array with feature compression off. |
| 5665 | if (index_loc.IsConstant()) { |
| 5666 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5667 | __ cmpl(array_len, Immediate(value)); |
| 5668 | } else { |
| 5669 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5670 | } |
| 5671 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5672 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5673 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5674 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5675 | } |
| 5676 | codegen_->AddSlowPath(slow_path); |
| 5677 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5678 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5679 | } |
| 5680 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5681 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5682 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5683 | } |
| 5684 | |
| 5685 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5686 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5687 | } |
| 5688 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5689 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5690 | LocationSummary* locations = |
| 5691 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5692 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5693 | } |
| 5694 | |
| 5695 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5696 | HBasicBlock* block = instruction->GetBlock(); |
| 5697 | if (block->GetLoopInformation() != nullptr) { |
| 5698 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5699 | // The back edge will generate the suspend check. |
| 5700 | return; |
| 5701 | } |
| 5702 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5703 | // The goto will generate the suspend check. |
| 5704 | return; |
| 5705 | } |
| 5706 | GenerateSuspendCheck(instruction, nullptr); |
| 5707 | } |
| 5708 | |
| 5709 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5710 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5711 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5712 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5713 | if (slow_path == nullptr) { |
| 5714 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5715 | instruction->SetSlowPath(slow_path); |
| 5716 | codegen_->AddSlowPath(slow_path); |
| 5717 | if (successor != nullptr) { |
| 5718 | DCHECK(successor->IsLoopHeader()); |
| 5719 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5720 | } |
| 5721 | } else { |
| 5722 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5723 | } |
| 5724 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5725 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5726 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5727 | if (successor == nullptr) { |
| 5728 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5729 | __ Bind(slow_path->GetReturnLabel()); |
| 5730 | } else { |
| 5731 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5732 | __ jmp(slow_path->GetEntryLabel()); |
| 5733 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5734 | } |
| 5735 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5736 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5737 | return codegen_->GetAssembler(); |
| 5738 | } |
| 5739 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5740 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5741 | ScratchRegisterScope ensure_scratch( |
| 5742 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5743 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5744 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5745 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5746 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5750 | ScratchRegisterScope ensure_scratch( |
| 5751 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5752 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5753 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5754 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5755 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5756 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5757 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5761 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5762 | Location source = move->GetSource(); |
| 5763 | Location destination = move->GetDestination(); |
| 5764 | |
| 5765 | if (source.IsRegister()) { |
| 5766 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5767 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5768 | } else if (destination.IsFpuRegister()) { |
| 5769 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5770 | } else { |
| 5771 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5772 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5773 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5774 | } else if (source.IsRegisterPair()) { |
| 5775 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5776 | // Create stack space for 2 elements. |
| 5777 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5778 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5779 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5780 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5781 | // And remove the temporary stack space we allocated. |
| 5782 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5783 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5784 | if (destination.IsRegister()) { |
| 5785 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5786 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5787 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5788 | } else if (destination.IsRegisterPair()) { |
| 5789 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5790 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5791 | __ psrlq(src_reg, Immediate(32)); |
| 5792 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5793 | } else if (destination.IsStackSlot()) { |
| 5794 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5795 | } else { |
| 5796 | DCHECK(destination.IsDoubleStackSlot()); |
| 5797 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5798 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5799 | } else if (source.IsStackSlot()) { |
| 5800 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5801 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5802 | } else if (destination.IsFpuRegister()) { |
| 5803 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5804 | } else { |
| 5805 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5806 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5807 | } |
| 5808 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5809 | if (destination.IsRegisterPair()) { |
| 5810 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5811 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5812 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5813 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5814 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5815 | } else { |
| 5816 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5817 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5818 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5819 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5820 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5821 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5822 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5823 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5824 | if (value == 0) { |
| 5825 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5826 | } else { |
| 5827 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5828 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5829 | } else { |
| 5830 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5831 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5832 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5833 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5834 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5835 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5836 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5837 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5838 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5839 | if (value == 0) { |
| 5840 | // Easy handling of 0.0. |
| 5841 | __ xorps(dest, dest); |
| 5842 | } else { |
| 5843 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5844 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5845 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5846 | __ movl(temp, Immediate(value)); |
| 5847 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5848 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5849 | } else { |
| 5850 | DCHECK(destination.IsStackSlot()) << destination; |
| 5851 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5852 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5853 | } else if (constant->IsLongConstant()) { |
| 5854 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5855 | int32_t low_value = Low32Bits(value); |
| 5856 | int32_t high_value = High32Bits(value); |
| 5857 | Immediate low(low_value); |
| 5858 | Immediate high(high_value); |
| 5859 | if (destination.IsDoubleStackSlot()) { |
| 5860 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5861 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5862 | } else { |
| 5863 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5864 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5865 | } |
| 5866 | } else { |
| 5867 | DCHECK(constant->IsDoubleConstant()); |
| 5868 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5869 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5870 | int32_t low_value = Low32Bits(value); |
| 5871 | int32_t high_value = High32Bits(value); |
| 5872 | Immediate low(low_value); |
| 5873 | Immediate high(high_value); |
| 5874 | if (destination.IsFpuRegister()) { |
| 5875 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5876 | if (value == 0) { |
| 5877 | // Easy handling of 0.0. |
| 5878 | __ xorpd(dest, dest); |
| 5879 | } else { |
| 5880 | __ pushl(high); |
| 5881 | __ pushl(low); |
| 5882 | __ movsd(dest, Address(ESP, 0)); |
| 5883 | __ addl(ESP, Immediate(8)); |
| 5884 | } |
| 5885 | } else { |
| 5886 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5887 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5888 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5889 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5890 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5891 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5892 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5893 | } |
| 5894 | } |
| 5895 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5896 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5897 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5898 | ScratchRegisterScope ensure_scratch( |
| 5899 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5900 | |
| 5901 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5902 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5903 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5904 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5905 | } |
| 5906 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5907 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5908 | ScratchRegisterScope ensure_scratch( |
| 5909 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5910 | |
| 5911 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5912 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5913 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5914 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5915 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5916 | } |
| 5917 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5918 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5919 | ScratchRegisterScope ensure_scratch1( |
| 5920 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5921 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5922 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5923 | ScratchRegisterScope ensure_scratch2( |
| 5924 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5925 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5926 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5927 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5928 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5929 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5930 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5931 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5935 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5936 | Location source = move->GetSource(); |
| 5937 | Location destination = move->GetDestination(); |
| 5938 | |
| 5939 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5940 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5941 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5942 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5943 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5944 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5945 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5946 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5947 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5948 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5949 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5950 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5951 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5952 | // Use XOR Swap algorithm to avoid a temporary. |
| 5953 | DCHECK_NE(source.reg(), destination.reg()); |
| 5954 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5955 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5956 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5957 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5958 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5959 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5960 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5961 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5962 | // Take advantage of the 16 bytes in the XMM register. |
| 5963 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5964 | Address stack(ESP, destination.GetStackIndex()); |
| 5965 | // Load the double into the high doubleword. |
| 5966 | __ movhpd(reg, stack); |
| 5967 | |
| 5968 | // Store the low double into the destination. |
| 5969 | __ movsd(stack, reg); |
| 5970 | |
| 5971 | // Move the high double to the low double. |
| 5972 | __ psrldq(reg, Immediate(8)); |
| 5973 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5974 | // Take advantage of the 16 bytes in the XMM register. |
| 5975 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5976 | Address stack(ESP, source.GetStackIndex()); |
| 5977 | // Load the double into the high doubleword. |
| 5978 | __ movhpd(reg, stack); |
| 5979 | |
| 5980 | // Store the low double into the destination. |
| 5981 | __ movsd(stack, reg); |
| 5982 | |
| 5983 | // Move the high double to the low double. |
| 5984 | __ psrldq(reg, Immediate(8)); |
| 5985 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5986 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5987 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5988 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5989 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5990 | } |
| 5991 | } |
| 5992 | |
| 5993 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5994 | __ pushl(static_cast<Register>(reg)); |
| 5995 | } |
| 5996 | |
| 5997 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5998 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5999 | } |
| 6000 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6001 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6002 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6003 | switch (desired_class_load_kind) { |
| 6004 | case HLoadClass::LoadKind::kReferrersClass: |
| 6005 | break; |
| 6006 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6007 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6008 | break; |
| 6009 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6010 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6011 | FALLTHROUGH_INTENDED; |
| 6012 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 6013 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
| 6014 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6015 | // is incompatible with it. |
| 6016 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6017 | // with irreducible loops. |
| 6018 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6019 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 6020 | } |
| 6021 | break; |
| 6022 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6023 | break; |
| 6024 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 6025 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6026 | break; |
| 6027 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6028 | break; |
| 6029 | } |
| 6030 | return desired_class_load_kind; |
| 6031 | } |
| 6032 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6033 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6034 | if (cls->NeedsAccessCheck()) { |
| 6035 | InvokeRuntimeCallingConvention calling_convention; |
| 6036 | CodeGenerator::CreateLoadClassLocationSummary( |
| 6037 | cls, |
| 6038 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 6039 | Location::RegisterLocation(EAX), |
| 6040 | /* code_generator_supports_read_barrier */ true); |
| 6041 | return; |
| 6042 | } |
| 6043 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6044 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6045 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6046 | ? LocationSummary::kCallOnSlowPath |
| 6047 | : LocationSummary::kNoCall; |
| 6048 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6049 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6050 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6051 | } |
| 6052 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6053 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6054 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 6055 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 6056 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 6057 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 6058 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6059 | } |
| 6060 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6064 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6065 | if (cls->NeedsAccessCheck()) { |
| 6066 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6067 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6068 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6069 | return; |
| 6070 | } |
| 6071 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6072 | Location out_loc = locations->Out(); |
| 6073 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6074 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6075 | bool generate_null_check = false; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6076 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6077 | switch (cls->GetLoadKind()) { |
| 6078 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6079 | DCHECK(!cls->CanCallRuntime()); |
| 6080 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6081 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6082 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6083 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6084 | cls, |
| 6085 | out_loc, |
| 6086 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6087 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6088 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6089 | break; |
| 6090 | } |
| 6091 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6092 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6093 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6094 | codegen_->RecordTypePatch(cls); |
| 6095 | break; |
| 6096 | } |
| 6097 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6098 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6099 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6100 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6101 | codegen_->RecordTypePatch(cls); |
| 6102 | break; |
| 6103 | } |
| 6104 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6105 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6106 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6107 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6108 | __ movl(out, Immediate(address)); |
| 6109 | codegen_->RecordSimplePatch(); |
| 6110 | break; |
| 6111 | } |
| 6112 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 6113 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6114 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6115 | // /* GcRoot<mirror::Class> */ out = *address |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6116 | GenerateGcRootFieldLoad(cls, |
| 6117 | out_loc, |
| 6118 | Address::Absolute(address), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6119 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6120 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6121 | generate_null_check = !cls->IsInDexCache(); |
| 6122 | break; |
| 6123 | } |
| 6124 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 6125 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6126 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 6127 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 6128 | // /* GcRoot<mirror::Class> */ out = *(base + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6129 | GenerateGcRootFieldLoad(cls, |
| 6130 | out_loc, |
| 6131 | Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), |
| 6132 | fixup_label, |
| 6133 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6134 | generate_null_check = !cls->IsInDexCache(); |
| 6135 | break; |
| 6136 | } |
| 6137 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 6138 | // /* GcRoot<mirror::Class>[] */ out = |
| 6139 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 6140 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6141 | __ movl(out, Address(current_method, |
| 6142 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 6143 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6144 | GenerateGcRootFieldLoad(cls, |
| 6145 | out_loc, |
| 6146 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6147 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6148 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6149 | generate_null_check = !cls->IsInDexCache(); |
| 6150 | break; |
| 6151 | } |
| 6152 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6153 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6154 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6155 | DCHECK(cls->CanCallRuntime()); |
| 6156 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6157 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6158 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6159 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6160 | if (generate_null_check) { |
| 6161 | __ testl(out, out); |
| 6162 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6163 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6164 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6165 | if (cls->MustGenerateClinitCheck()) { |
| 6166 | GenerateClassInitializationCheck(slow_path, out); |
| 6167 | } else { |
| 6168 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6169 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6170 | } |
| 6171 | } |
| 6172 | |
| 6173 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6174 | LocationSummary* locations = |
| 6175 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6176 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6177 | if (check->HasUses()) { |
| 6178 | locations->SetOut(Location::SameAsFirstInput()); |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6183 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6184 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6185 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6186 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6187 | GenerateClassInitializationCheck(slow_path, |
| 6188 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6189 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6190 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6191 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6192 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6193 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6194 | Immediate(mirror::Class::kStatusInitialized)); |
| 6195 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6196 | __ Bind(slow_path->GetExitLabel()); |
| 6197 | // No need for memory fence, thanks to the X86 memory model. |
| 6198 | } |
| 6199 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6200 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6201 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6202 | switch (desired_string_load_kind) { |
| 6203 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6204 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6205 | break; |
| 6206 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6207 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6208 | FALLTHROUGH_INTENDED; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6209 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6210 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6211 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6212 | // is incompatible with it. |
| 6213 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6214 | // with irreducible loops. |
| 6215 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6216 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6217 | } |
| 6218 | break; |
| 6219 | case HLoadString::LoadKind::kBootImageAddress: |
| 6220 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6221 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6222 | break; |
| 6223 | } |
| 6224 | return desired_string_load_kind; |
| 6225 | } |
| 6226 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6227 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6228 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6229 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 6230 | ? LocationSummary::kCallOnMainOnly |
| 6231 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6232 | : LocationSummary::kNoCall; |
| 6233 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6234 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6235 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6236 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6237 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6238 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6239 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 6240 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6241 | } else { |
| 6242 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6243 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6244 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6245 | // Rely on the pResolveString and/or marking to save everything. |
| 6246 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6247 | InvokeRuntimeCallingConvention calling_convention; |
| 6248 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6249 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6250 | } else { |
| 6251 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6252 | } |
| 6253 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6254 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6255 | } |
| 6256 | |
| 6257 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6258 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6259 | Location out_loc = locations->Out(); |
| 6260 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6261 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6262 | switch (load->GetLoadKind()) { |
| 6263 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6264 | __ movl(out, Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6265 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6266 | return; // No dex cache slow path. |
| 6267 | } |
| 6268 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6269 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6270 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6271 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6272 | return; // No dex cache slow path. |
| 6273 | } |
| 6274 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6275 | DCHECK_NE(load->GetAddress(), 0u); |
| 6276 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6277 | __ movl(out, Immediate(address)); |
| 6278 | codegen_->RecordSimplePatch(); |
| 6279 | return; // No dex cache slow path. |
| 6280 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6281 | case HLoadString::LoadKind::kBssEntry: { |
| 6282 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6283 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6284 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 07c919f | 2016-11-09 17:29:03 +0000 | [diff] [blame] | 6285 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6286 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kEmitCompilerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6287 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6288 | codegen_->AddSlowPath(slow_path); |
| 6289 | __ testl(out, out); |
| 6290 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6291 | __ Bind(slow_path->GetExitLabel()); |
| 6292 | return; |
| 6293 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6294 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6295 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6296 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6297 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6298 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6299 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6300 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6301 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex())); |
| 6302 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6303 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6304 | } |
| 6305 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6306 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6307 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6308 | } |
| 6309 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6310 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6311 | LocationSummary* locations = |
| 6312 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6313 | locations->SetOut(Location::RequiresRegister()); |
| 6314 | } |
| 6315 | |
| 6316 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6317 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6318 | } |
| 6319 | |
| 6320 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6321 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6322 | } |
| 6323 | |
| 6324 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6325 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6326 | } |
| 6327 | |
| 6328 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6329 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6330 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6331 | InvokeRuntimeCallingConvention calling_convention; |
| 6332 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6333 | } |
| 6334 | |
| 6335 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6336 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6337 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6338 | } |
| 6339 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6340 | // Temp is used for read barrier. |
| 6341 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6342 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6343 | !kUseBakerReadBarrier && |
| 6344 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6345 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6346 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6347 | return 1; |
| 6348 | } |
| 6349 | return 0; |
| 6350 | } |
| 6351 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6352 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6353 | // interface pointer, one for loading the current interface. |
| 6354 | // The other checks have one temp for loading the object's class. |
| 6355 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6356 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6357 | return 2; |
| 6358 | } |
| 6359 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6360 | } |
| 6361 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6362 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6363 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6364 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6365 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6366 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6367 | case TypeCheckKind::kExactCheck: |
| 6368 | case TypeCheckKind::kAbstractClassCheck: |
| 6369 | case TypeCheckKind::kClassHierarchyCheck: |
| 6370 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6371 | call_kind = |
| 6372 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6373 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6374 | break; |
| 6375 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6376 | case TypeCheckKind::kUnresolvedCheck: |
| 6377 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6378 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6379 | break; |
| 6380 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6381 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6382 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6383 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6384 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6385 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6386 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6387 | locations->SetInAt(1, Location::Any()); |
| 6388 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6389 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6390 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6391 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6392 | } |
| 6393 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6394 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6395 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6396 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6397 | Location obj_loc = locations->InAt(0); |
| 6398 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6399 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6400 | Location out_loc = locations->Out(); |
| 6401 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6402 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6403 | DCHECK_LE(num_temps, 1u); |
| 6404 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6405 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6406 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6407 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6408 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6409 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6410 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6411 | |
| 6412 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6413 | // Avoid null check if we know obj is not null. |
| 6414 | if (instruction->MustDoNullCheck()) { |
| 6415 | __ testl(obj, obj); |
| 6416 | __ j(kEqual, &zero); |
| 6417 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6418 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6419 | // /* HeapReference<Class> */ out = obj->klass_ |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6420 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6421 | out_loc, |
| 6422 | obj_loc, |
| 6423 | class_offset, |
| 6424 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6425 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6426 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6427 | case TypeCheckKind::kExactCheck: { |
| 6428 | if (cls.IsRegister()) { |
| 6429 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6430 | } else { |
| 6431 | DCHECK(cls.IsStackSlot()) << cls; |
| 6432 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6433 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6434 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6435 | // Classes must be equal for the instanceof to succeed. |
| 6436 | __ j(kNotEqual, &zero); |
| 6437 | __ movl(out, Immediate(1)); |
| 6438 | __ jmp(&done); |
| 6439 | break; |
| 6440 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6441 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6442 | case TypeCheckKind::kAbstractClassCheck: { |
| 6443 | // If the class is abstract, we eagerly fetch the super class of the |
| 6444 | // object to avoid doing a comparison we know will fail. |
| 6445 | NearLabel loop; |
| 6446 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6447 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6448 | GenerateReferenceLoadOneRegister(instruction, |
| 6449 | out_loc, |
| 6450 | super_offset, |
| 6451 | maybe_temp_loc, |
| 6452 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6453 | __ testl(out, out); |
| 6454 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6455 | __ j(kEqual, &done); |
| 6456 | if (cls.IsRegister()) { |
| 6457 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6458 | } else { |
| 6459 | DCHECK(cls.IsStackSlot()) << cls; |
| 6460 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6461 | } |
| 6462 | __ j(kNotEqual, &loop); |
| 6463 | __ movl(out, Immediate(1)); |
| 6464 | if (zero.IsLinked()) { |
| 6465 | __ jmp(&done); |
| 6466 | } |
| 6467 | break; |
| 6468 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6469 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6470 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6471 | // Walk over the class hierarchy to find a match. |
| 6472 | NearLabel loop, success; |
| 6473 | __ Bind(&loop); |
| 6474 | if (cls.IsRegister()) { |
| 6475 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6476 | } else { |
| 6477 | DCHECK(cls.IsStackSlot()) << cls; |
| 6478 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6479 | } |
| 6480 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6481 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6482 | GenerateReferenceLoadOneRegister(instruction, |
| 6483 | out_loc, |
| 6484 | super_offset, |
| 6485 | maybe_temp_loc, |
| 6486 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6487 | __ testl(out, out); |
| 6488 | __ j(kNotEqual, &loop); |
| 6489 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6490 | __ jmp(&done); |
| 6491 | __ Bind(&success); |
| 6492 | __ movl(out, Immediate(1)); |
| 6493 | if (zero.IsLinked()) { |
| 6494 | __ jmp(&done); |
| 6495 | } |
| 6496 | break; |
| 6497 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6498 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6499 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6500 | // Do an exact check. |
| 6501 | NearLabel exact_check; |
| 6502 | if (cls.IsRegister()) { |
| 6503 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6504 | } else { |
| 6505 | DCHECK(cls.IsStackSlot()) << cls; |
| 6506 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6507 | } |
| 6508 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6509 | // 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] | 6510 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6511 | GenerateReferenceLoadOneRegister(instruction, |
| 6512 | out_loc, |
| 6513 | component_offset, |
| 6514 | maybe_temp_loc, |
| 6515 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6516 | __ testl(out, out); |
| 6517 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6518 | __ j(kEqual, &done); |
| 6519 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6520 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6521 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6522 | __ movl(out, Immediate(1)); |
| 6523 | __ jmp(&done); |
| 6524 | break; |
| 6525 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6526 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6527 | case TypeCheckKind::kArrayCheck: { |
| 6528 | if (cls.IsRegister()) { |
| 6529 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6530 | } else { |
| 6531 | DCHECK(cls.IsStackSlot()) << cls; |
| 6532 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6533 | } |
| 6534 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6535 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6536 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6537 | codegen_->AddSlowPath(slow_path); |
| 6538 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6539 | __ movl(out, Immediate(1)); |
| 6540 | if (zero.IsLinked()) { |
| 6541 | __ jmp(&done); |
| 6542 | } |
| 6543 | break; |
| 6544 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6545 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6546 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6547 | case TypeCheckKind::kInterfaceCheck: { |
| 6548 | // 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] | 6549 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6550 | // cases. |
| 6551 | // |
| 6552 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6553 | // entry point without resorting to a type checking slow path |
| 6554 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6555 | // require to assign fixed registers for the inputs of this |
| 6556 | // HInstanceOf instruction (following the runtime calling |
| 6557 | // convention), which might be cluttered by the potential first |
| 6558 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6559 | // |
| 6560 | // TODO: Introduce a new runtime entry point taking the object |
| 6561 | // to test (instead of its class) as argument, and let it deal |
| 6562 | // with the read barrier issues. This will let us refactor this |
| 6563 | // case of the `switch` code as it was previously (with a direct |
| 6564 | // call to the runtime not using a type checking slow path). |
| 6565 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6566 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6567 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6568 | /* is_fatal */ false); |
| 6569 | codegen_->AddSlowPath(slow_path); |
| 6570 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6571 | if (zero.IsLinked()) { |
| 6572 | __ jmp(&done); |
| 6573 | } |
| 6574 | break; |
| 6575 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6576 | } |
| 6577 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6578 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6579 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6580 | __ xorl(out, out); |
| 6581 | } |
| 6582 | |
| 6583 | if (done.IsLinked()) { |
| 6584 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6585 | } |
| 6586 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6587 | if (slow_path != nullptr) { |
| 6588 | __ Bind(slow_path->GetExitLabel()); |
| 6589 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6590 | } |
| 6591 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6592 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6593 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6594 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6595 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6596 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6597 | case TypeCheckKind::kExactCheck: |
| 6598 | case TypeCheckKind::kAbstractClassCheck: |
| 6599 | case TypeCheckKind::kClassHierarchyCheck: |
| 6600 | case TypeCheckKind::kArrayObjectCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6601 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6602 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6603 | LocationSummary::kCallOnSlowPath : |
| 6604 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6605 | break; |
| 6606 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6607 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6608 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6609 | break; |
| 6610 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6611 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6612 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6613 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6614 | // Require a register for the interface check since there is a loop that compares the class to |
| 6615 | // a memory address. |
| 6616 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6617 | } else { |
| 6618 | locations->SetInAt(1, Location::Any()); |
| 6619 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6620 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6621 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6622 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6623 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6624 | } |
| 6625 | |
| 6626 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6627 | switch (type_check_kind) { |
| 6628 | case TypeCheckKind::kExactCheck: |
| 6629 | case TypeCheckKind::kAbstractClassCheck: |
| 6630 | case TypeCheckKind::kClassHierarchyCheck: |
| 6631 | case TypeCheckKind::kArrayObjectCheck: |
| 6632 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6633 | case TypeCheckKind::kInterfaceCheck: |
| 6634 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6635 | case TypeCheckKind::kArrayCheck: |
| 6636 | case TypeCheckKind::kUnresolvedCheck: |
| 6637 | return false; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6638 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6639 | LOG(FATAL) << "Unreachable"; |
| 6640 | UNREACHABLE(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6641 | } |
| 6642 | |
| 6643 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6644 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6645 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6646 | Location obj_loc = locations->InAt(0); |
| 6647 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6648 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6649 | Location temp_loc = locations->GetTemp(0); |
| 6650 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6651 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6652 | DCHECK_GE(num_temps, 1u); |
| 6653 | DCHECK_LE(num_temps, 2u); |
| 6654 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6655 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6656 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6657 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6658 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6659 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6660 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6661 | const uint32_t object_array_data_offset = |
| 6662 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6663 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6664 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6665 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6666 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6667 | SlowPathCode* type_check_slow_path = |
| 6668 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6669 | is_type_check_slow_path_fatal); |
| 6670 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6671 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6672 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6673 | // Avoid null check if we know obj is not null. |
| 6674 | if (instruction->MustDoNullCheck()) { |
| 6675 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6676 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6677 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6678 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6679 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6680 | case TypeCheckKind::kExactCheck: |
| 6681 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6682 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6683 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6684 | temp_loc, |
| 6685 | obj_loc, |
| 6686 | class_offset, |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6687 | /*emit_read_barrier*/ false); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6688 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6689 | if (cls.IsRegister()) { |
| 6690 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6691 | } else { |
| 6692 | DCHECK(cls.IsStackSlot()) << cls; |
| 6693 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6694 | } |
| 6695 | // Jump to slow path for throwing the exception or doing a |
| 6696 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6697 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6698 | break; |
| 6699 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6700 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6701 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6702 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6703 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6704 | temp_loc, |
| 6705 | obj_loc, |
| 6706 | class_offset, |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6707 | /*emit_read_barrier*/ false); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6708 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6709 | // If the class is abstract, we eagerly fetch the super class of the |
| 6710 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6711 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6712 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6713 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6714 | GenerateReferenceLoadOneRegister(instruction, |
| 6715 | temp_loc, |
| 6716 | super_offset, |
| 6717 | maybe_temp2_loc, |
| 6718 | /*emit_read_barrier*/ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6719 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6720 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6721 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6722 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6723 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6724 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6725 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6726 | if (cls.IsRegister()) { |
| 6727 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6728 | } else { |
| 6729 | DCHECK(cls.IsStackSlot()) << cls; |
| 6730 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6731 | } |
| 6732 | __ j(kNotEqual, &loop); |
| 6733 | break; |
| 6734 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6735 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6736 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6737 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6738 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6739 | temp_loc, |
| 6740 | obj_loc, |
| 6741 | class_offset, |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6742 | /*emit_read_barrier*/ false); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6743 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6744 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6745 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6746 | __ Bind(&loop); |
| 6747 | if (cls.IsRegister()) { |
| 6748 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6749 | } else { |
| 6750 | DCHECK(cls.IsStackSlot()) << cls; |
| 6751 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6752 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6753 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6754 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6755 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6756 | GenerateReferenceLoadOneRegister(instruction, |
| 6757 | temp_loc, |
| 6758 | super_offset, |
| 6759 | maybe_temp2_loc, |
| 6760 | /*emit_read_barrier*/ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6761 | |
| 6762 | // If the class reference currently in `temp` is not null, jump |
| 6763 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6764 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6765 | __ j(kNotZero, &loop); |
| 6766 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6767 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6768 | break; |
| 6769 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6770 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6771 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6772 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6773 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6774 | temp_loc, |
| 6775 | obj_loc, |
| 6776 | class_offset, |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6777 | /*emit_read_barrier*/ false); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6778 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6779 | // Do an exact check. |
| 6780 | if (cls.IsRegister()) { |
| 6781 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6782 | } else { |
| 6783 | DCHECK(cls.IsStackSlot()) << cls; |
| 6784 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6785 | } |
| 6786 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6787 | |
| 6788 | // 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] | 6789 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6790 | GenerateReferenceLoadOneRegister(instruction, |
| 6791 | temp_loc, |
| 6792 | component_offset, |
| 6793 | maybe_temp2_loc, |
| 6794 | /*emit_read_barrier*/ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6795 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6796 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6797 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6798 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6799 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6800 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6801 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6802 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6803 | break; |
| 6804 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6805 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6806 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6807 | // We always go into the type check slow path for the unresolved check case. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6808 | // We cannot directly call the CheckCast runtime entry point |
| 6809 | // without resorting to a type checking slow path here (i.e. by |
| 6810 | // calling InvokeRuntime directly), as it would require to |
| 6811 | // assign fixed registers for the inputs of this HInstanceOf |
| 6812 | // instruction (following the runtime calling convention), which |
| 6813 | // might be cluttered by the potential first read barrier |
| 6814 | // emission at the beginning of this method. |
| 6815 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6816 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6817 | |
| 6818 | case TypeCheckKind::kInterfaceCheck: { |
| 6819 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6820 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6821 | // conditional flags and cause the conditional jump to be incorrect. Therefore we just jump |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 6822 | // to the slow path if we are running under poisoning. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6823 | if (!kPoisonHeapReferences) { |
| 6824 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6825 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6826 | temp_loc, |
| 6827 | obj_loc, |
| 6828 | class_offset, |
| 6829 | /*emit_read_barrier*/ false); |
| 6830 | |
| 6831 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6832 | // doing this. |
| 6833 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6834 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6835 | temp_loc, |
| 6836 | obj_loc, |
| 6837 | class_offset, |
| 6838 | /*emit_read_barrier*/ false); |
| 6839 | |
| 6840 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6841 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6842 | temp_loc, |
| 6843 | temp_loc, |
| 6844 | iftable_offset, |
| 6845 | /*emit_read_barrier*/ false); |
| 6846 | NearLabel is_null; |
| 6847 | // Null iftable means it is empty. |
| 6848 | __ testl(temp, temp); |
| 6849 | __ j(kZero, &is_null); |
| 6850 | |
| 6851 | // Loop through the iftable and check if any class matches. |
| 6852 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 6853 | |
| 6854 | NearLabel start_loop; |
| 6855 | __ Bind(&start_loop); |
| 6856 | __ cmpl(cls.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 6857 | __ j(kEqual, &done); // Return if same class. |
| 6858 | // Go to next interface. |
| 6859 | __ addl(temp, Immediate(2 * kHeapReferenceSize)); |
| 6860 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 6861 | __ j(kNotZero, &start_loop); |
| 6862 | __ Bind(&is_null); |
| 6863 | } |
| 6864 | |
| 6865 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6866 | break; |
| 6867 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6868 | } |
| 6869 | __ Bind(&done); |
| 6870 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6871 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6872 | } |
| 6873 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6874 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6875 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6876 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6877 | InvokeRuntimeCallingConvention calling_convention; |
| 6878 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6879 | } |
| 6880 | |
| 6881 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6882 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6883 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6884 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6885 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6886 | if (instruction->IsEnter()) { |
| 6887 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6888 | } else { |
| 6889 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6890 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6891 | } |
| 6892 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6893 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6894 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6895 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6896 | |
| 6897 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6898 | LocationSummary* locations = |
| 6899 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6900 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6901 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6902 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6903 | locations->SetInAt(1, Location::Any()); |
| 6904 | locations->SetOut(Location::SameAsFirstInput()); |
| 6905 | } |
| 6906 | |
| 6907 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6908 | HandleBitwiseOperation(instruction); |
| 6909 | } |
| 6910 | |
| 6911 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6912 | HandleBitwiseOperation(instruction); |
| 6913 | } |
| 6914 | |
| 6915 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6916 | HandleBitwiseOperation(instruction); |
| 6917 | } |
| 6918 | |
| 6919 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6920 | LocationSummary* locations = instruction->GetLocations(); |
| 6921 | Location first = locations->InAt(0); |
| 6922 | Location second = locations->InAt(1); |
| 6923 | DCHECK(first.Equals(locations->Out())); |
| 6924 | |
| 6925 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6926 | if (second.IsRegister()) { |
| 6927 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6928 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6929 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6930 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6931 | } else { |
| 6932 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6933 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6934 | } |
| 6935 | } else if (second.IsConstant()) { |
| 6936 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6937 | __ andl(first.AsRegister<Register>(), |
| 6938 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6939 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6940 | __ orl(first.AsRegister<Register>(), |
| 6941 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6942 | } else { |
| 6943 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6944 | __ xorl(first.AsRegister<Register>(), |
| 6945 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6946 | } |
| 6947 | } else { |
| 6948 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6949 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6950 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6951 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6952 | } else { |
| 6953 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6954 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6955 | } |
| 6956 | } |
| 6957 | } else { |
| 6958 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6959 | if (second.IsRegisterPair()) { |
| 6960 | if (instruction->IsAnd()) { |
| 6961 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6962 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6963 | } else if (instruction->IsOr()) { |
| 6964 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6965 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6966 | } else { |
| 6967 | DCHECK(instruction->IsXor()); |
| 6968 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6969 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6970 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6971 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6972 | if (instruction->IsAnd()) { |
| 6973 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6974 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6975 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6976 | } else if (instruction->IsOr()) { |
| 6977 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6978 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6979 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6980 | } else { |
| 6981 | DCHECK(instruction->IsXor()); |
| 6982 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6983 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6984 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6985 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6986 | } else { |
| 6987 | DCHECK(second.IsConstant()) << second; |
| 6988 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6989 | int32_t low_value = Low32Bits(value); |
| 6990 | int32_t high_value = High32Bits(value); |
| 6991 | Immediate low(low_value); |
| 6992 | Immediate high(high_value); |
| 6993 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6994 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6995 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6996 | if (low_value == 0) { |
| 6997 | __ xorl(first_low, first_low); |
| 6998 | } else if (low_value != -1) { |
| 6999 | __ andl(first_low, low); |
| 7000 | } |
| 7001 | if (high_value == 0) { |
| 7002 | __ xorl(first_high, first_high); |
| 7003 | } else if (high_value != -1) { |
| 7004 | __ andl(first_high, high); |
| 7005 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7006 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7007 | if (low_value != 0) { |
| 7008 | __ orl(first_low, low); |
| 7009 | } |
| 7010 | if (high_value != 0) { |
| 7011 | __ orl(first_high, high); |
| 7012 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7013 | } else { |
| 7014 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7015 | if (low_value != 0) { |
| 7016 | __ xorl(first_low, low); |
| 7017 | } |
| 7018 | if (high_value != 0) { |
| 7019 | __ xorl(first_high, high); |
| 7020 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7021 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7022 | } |
| 7023 | } |
| 7024 | } |
| 7025 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7026 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 7027 | Location out, |
| 7028 | uint32_t offset, |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 7029 | Location maybe_temp, |
| 7030 | bool emit_read_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7031 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame^] | 7032 | if (emit_read_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7033 | if (kUseBakerReadBarrier) { |
| 7034 | // Load with fast path based Baker's read barrier. |
| 7035 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7036 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7037 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7038 | } else { |
| 7039 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7040 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7041 | // in the following move operation, as we will need it for the |
| 7042 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7043 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7044 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7045 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7046 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7047 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7048 | } |
| 7049 | } else { |
| 7050 | // Plain load with no read barrier. |
| 7051 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7052 | __ movl(out_reg, Address(out_reg, offset)); |
| 7053 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7054 | } |
| 7055 | } |
| 7056 | |
| 7057 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 7058 | Location out, |
| 7059 | Location obj, |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7060 | uint32_t offset, |
| 7061 | bool emit_read_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7062 | Register out_reg = out.AsRegister<Register>(); |
| 7063 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7064 | if (emit_read_barrier) { |
| 7065 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7066 | if (kUseBakerReadBarrier) { |
| 7067 | // Load with fast path based Baker's read barrier. |
| 7068 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7069 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7070 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7071 | } else { |
| 7072 | // Load with slow path based read barrier. |
| 7073 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7074 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7075 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7076 | } |
| 7077 | } else { |
| 7078 | // Plain load with no read barrier. |
| 7079 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7080 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7081 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7082 | } |
| 7083 | } |
| 7084 | |
| 7085 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 7086 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7087 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7088 | Label* fixup_label, |
| 7089 | bool requires_read_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7090 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7091 | if (requires_read_barrier) { |
| 7092 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7093 | if (kUseBakerReadBarrier) { |
| 7094 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7095 | // Baker's read barrier are used: |
| 7096 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7097 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7098 | // if (Thread::Current()->GetIsGcMarking()) { |
| 7099 | // root = ReadBarrier::Mark(root) |
| 7100 | // } |
| 7101 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7102 | // /* GcRoot<mirror::Object> */ root = *address |
| 7103 | __ movl(root_reg, address); |
| 7104 | if (fixup_label != nullptr) { |
| 7105 | __ Bind(fixup_label); |
| 7106 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7107 | static_assert( |
| 7108 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7109 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7110 | "have different sizes."); |
| 7111 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7112 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7113 | "have different sizes."); |
| 7114 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7115 | // Slow path marking the GC root `root`. |
| 7116 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7117 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7118 | codegen_->AddSlowPath(slow_path); |
| 7119 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7120 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7121 | Immediate(0)); |
| 7122 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7123 | __ Bind(slow_path->GetExitLabel()); |
| 7124 | } else { |
| 7125 | // GC root loaded through a slow path for read barriers other |
| 7126 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7127 | // /* GcRoot<mirror::Object>* */ root = address |
| 7128 | __ leal(root_reg, address); |
| 7129 | if (fixup_label != nullptr) { |
| 7130 | __ Bind(fixup_label); |
| 7131 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7132 | // /* mirror::Object* */ root = root->Read() |
| 7133 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7134 | } |
| 7135 | } else { |
| 7136 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7137 | // /* GcRoot<mirror::Object> */ root = *address |
| 7138 | __ movl(root_reg, address); |
| 7139 | if (fixup_label != nullptr) { |
| 7140 | __ Bind(fixup_label); |
| 7141 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7142 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7143 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7144 | } |
| 7145 | } |
| 7146 | |
| 7147 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7148 | Location ref, |
| 7149 | Register obj, |
| 7150 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7151 | bool needs_null_check) { |
| 7152 | DCHECK(kEmitCompilerReadBarrier); |
| 7153 | DCHECK(kUseBakerReadBarrier); |
| 7154 | |
| 7155 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7156 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7157 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7158 | } |
| 7159 | |
| 7160 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7161 | Location ref, |
| 7162 | Register obj, |
| 7163 | uint32_t data_offset, |
| 7164 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7165 | bool needs_null_check) { |
| 7166 | DCHECK(kEmitCompilerReadBarrier); |
| 7167 | DCHECK(kUseBakerReadBarrier); |
| 7168 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7169 | static_assert( |
| 7170 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7171 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7172 | // /* HeapReference<Object> */ ref = |
| 7173 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7174 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7175 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7176 | } |
| 7177 | |
| 7178 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7179 | Location ref, |
| 7180 | Register obj, |
| 7181 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7182 | bool needs_null_check, |
| 7183 | bool always_update_field, |
| 7184 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7185 | DCHECK(kEmitCompilerReadBarrier); |
| 7186 | DCHECK(kUseBakerReadBarrier); |
| 7187 | |
| 7188 | // In slow path based read barriers, the read barrier call is |
| 7189 | // inserted after the original load. However, in fast path based |
| 7190 | // Baker's read barriers, we need to perform the load of |
| 7191 | // mirror::Object::monitor_ *before* the original reference load. |
| 7192 | // This load-load ordering is required by the read barrier. |
| 7193 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7194 | // |
| 7195 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7196 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7197 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7198 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7199 | // if (is_gray) { |
| 7200 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7201 | // } |
| 7202 | // |
| 7203 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7204 | // slightly more complex as: |
| 7205 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7206 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7207 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7208 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7209 | // - it performs additional checks that we do not do here for |
| 7210 | // performance reasons. |
| 7211 | |
| 7212 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7213 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7214 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7215 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7216 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7217 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7218 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7219 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7220 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7221 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7222 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7223 | // ref = ReadBarrier::Mark(ref); |
| 7224 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7225 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7226 | if (needs_null_check) { |
| 7227 | MaybeRecordImplicitNullCheck(instruction); |
| 7228 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7229 | |
| 7230 | // Load fence to prevent load-load reordering. |
| 7231 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7232 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7233 | |
| 7234 | // The actual reference load. |
| 7235 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7236 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7237 | |
| 7238 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7239 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7240 | SlowPathCode* slow_path; |
| 7241 | if (always_update_field) { |
| 7242 | DCHECK(temp != nullptr); |
| 7243 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| 7244 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7245 | } else { |
| 7246 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 7247 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7248 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7249 | AddSlowPath(slow_path); |
| 7250 | |
| 7251 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7252 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7253 | |
| 7254 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7255 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7256 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7257 | __ Bind(slow_path->GetExitLabel()); |
| 7258 | } |
| 7259 | |
| 7260 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7261 | Location out, |
| 7262 | Location ref, |
| 7263 | Location obj, |
| 7264 | uint32_t offset, |
| 7265 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7266 | DCHECK(kEmitCompilerReadBarrier); |
| 7267 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7268 | // Insert a slow path based read barrier *after* the reference load. |
| 7269 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7270 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7271 | // reference will be carried out by the runtime within the slow |
| 7272 | // path. |
| 7273 | // |
| 7274 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7275 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7276 | // not used by the artReadBarrierSlow entry point. |
| 7277 | // |
| 7278 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7279 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7280 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7281 | AddSlowPath(slow_path); |
| 7282 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7283 | __ jmp(slow_path->GetEntryLabel()); |
| 7284 | __ Bind(slow_path->GetExitLabel()); |
| 7285 | } |
| 7286 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7287 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7288 | Location out, |
| 7289 | Location ref, |
| 7290 | Location obj, |
| 7291 | uint32_t offset, |
| 7292 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7293 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7294 | // Baker's read barriers shall be handled by the fast path |
| 7295 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7296 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7297 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7298 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7299 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7300 | } else if (kPoisonHeapReferences) { |
| 7301 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7302 | } |
| 7303 | } |
| 7304 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7305 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7306 | Location out, |
| 7307 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7308 | DCHECK(kEmitCompilerReadBarrier); |
| 7309 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7310 | // Insert a slow path based read barrier *after* the GC root load. |
| 7311 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7312 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7313 | // not need to do anything special for this here. |
| 7314 | SlowPathCode* slow_path = |
| 7315 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7316 | AddSlowPath(slow_path); |
| 7317 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7318 | __ jmp(slow_path->GetEntryLabel()); |
| 7319 | __ Bind(slow_path->GetExitLabel()); |
| 7320 | } |
| 7321 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7322 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7323 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7324 | LOG(FATAL) << "Unreachable"; |
| 7325 | } |
| 7326 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7327 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7328 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7329 | LOG(FATAL) << "Unreachable"; |
| 7330 | } |
| 7331 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7332 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7333 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7334 | LocationSummary* locations = |
| 7335 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7336 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7337 | } |
| 7338 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7339 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7340 | int32_t lower_bound, |
| 7341 | uint32_t num_entries, |
| 7342 | HBasicBlock* switch_block, |
| 7343 | HBasicBlock* default_block) { |
| 7344 | // Figure out the correct compare values and jump conditions. |
| 7345 | // Handle the first compare/branch as a special case because it might |
| 7346 | // jump to the default case. |
| 7347 | DCHECK_GT(num_entries, 2u); |
| 7348 | Condition first_condition; |
| 7349 | uint32_t index; |
| 7350 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7351 | if (lower_bound != 0) { |
| 7352 | first_condition = kLess; |
| 7353 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7354 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7355 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7356 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7357 | index = 1; |
| 7358 | } else { |
| 7359 | // Handle all the compare/jumps below. |
| 7360 | first_condition = kBelow; |
| 7361 | index = 0; |
| 7362 | } |
| 7363 | |
| 7364 | // Handle the rest of the compare/jumps. |
| 7365 | for (; index + 1 < num_entries; index += 2) { |
| 7366 | int32_t compare_to_value = lower_bound + index + 1; |
| 7367 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7368 | // Jump to successors[index] if value < case_value[index]. |
| 7369 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7370 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7371 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7372 | } |
| 7373 | |
| 7374 | if (index != num_entries) { |
| 7375 | // There are an odd number of entries. Handle the last one. |
| 7376 | DCHECK_EQ(index + 1, num_entries); |
| 7377 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7378 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7379 | } |
| 7380 | |
| 7381 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7382 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7383 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7384 | } |
| 7385 | } |
| 7386 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7387 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7388 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7389 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7390 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7391 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7392 | |
| 7393 | GenPackedSwitchWithCompares(value_reg, |
| 7394 | lower_bound, |
| 7395 | num_entries, |
| 7396 | switch_instr->GetBlock(), |
| 7397 | switch_instr->GetDefaultBlock()); |
| 7398 | } |
| 7399 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7400 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7401 | LocationSummary* locations = |
| 7402 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7404 | |
| 7405 | // Constant area pointer. |
| 7406 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7407 | |
| 7408 | // And the temporary we need. |
| 7409 | locations->AddTemp(Location::RequiresRegister()); |
| 7410 | } |
| 7411 | |
| 7412 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7413 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7414 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7415 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7416 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7417 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7418 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7419 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7420 | GenPackedSwitchWithCompares(value_reg, |
| 7421 | lower_bound, |
| 7422 | num_entries, |
| 7423 | switch_instr->GetBlock(), |
| 7424 | default_block); |
| 7425 | return; |
| 7426 | } |
| 7427 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7428 | // Optimizing has a jump area. |
| 7429 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7430 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7431 | |
| 7432 | // Remove the bias, if needed. |
| 7433 | if (lower_bound != 0) { |
| 7434 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7435 | value_reg = temp_reg; |
| 7436 | } |
| 7437 | |
| 7438 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7439 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7440 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7441 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7442 | |
| 7443 | // We are in the range of the table. |
| 7444 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7445 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7446 | |
| 7447 | // Compute the actual target address by adding in constant_area. |
| 7448 | __ addl(temp_reg, constant_area); |
| 7449 | |
| 7450 | // And jump. |
| 7451 | __ jmp(temp_reg); |
| 7452 | } |
| 7453 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7454 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7455 | HX86ComputeBaseMethodAddress* insn) { |
| 7456 | LocationSummary* locations = |
| 7457 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7458 | locations->SetOut(Location::RequiresRegister()); |
| 7459 | } |
| 7460 | |
| 7461 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7462 | HX86ComputeBaseMethodAddress* insn) { |
| 7463 | LocationSummary* locations = insn->GetLocations(); |
| 7464 | Register reg = locations->Out().AsRegister<Register>(); |
| 7465 | |
| 7466 | // Generate call to next instruction. |
| 7467 | Label next_instruction; |
| 7468 | __ call(&next_instruction); |
| 7469 | __ Bind(&next_instruction); |
| 7470 | |
| 7471 | // Remember this offset for later use with constant area. |
| 7472 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7473 | |
| 7474 | // Grab the return address off the stack. |
| 7475 | __ popl(reg); |
| 7476 | } |
| 7477 | |
| 7478 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7479 | HX86LoadFromConstantTable* insn) { |
| 7480 | LocationSummary* locations = |
| 7481 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7482 | |
| 7483 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7484 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7485 | |
| 7486 | // 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] | 7487 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7488 | return; |
| 7489 | } |
| 7490 | |
| 7491 | switch (insn->GetType()) { |
| 7492 | case Primitive::kPrimFloat: |
| 7493 | case Primitive::kPrimDouble: |
| 7494 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7495 | break; |
| 7496 | |
| 7497 | case Primitive::kPrimInt: |
| 7498 | locations->SetOut(Location::RequiresRegister()); |
| 7499 | break; |
| 7500 | |
| 7501 | default: |
| 7502 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7503 | } |
| 7504 | } |
| 7505 | |
| 7506 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7507 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7508 | return; |
| 7509 | } |
| 7510 | |
| 7511 | LocationSummary* locations = insn->GetLocations(); |
| 7512 | Location out = locations->Out(); |
| 7513 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7514 | HConstant *value = insn->GetConstant(); |
| 7515 | |
| 7516 | switch (insn->GetType()) { |
| 7517 | case Primitive::kPrimFloat: |
| 7518 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7519 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7520 | break; |
| 7521 | |
| 7522 | case Primitive::kPrimDouble: |
| 7523 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7524 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7525 | break; |
| 7526 | |
| 7527 | case Primitive::kPrimInt: |
| 7528 | __ movl(out.AsRegister<Register>(), |
| 7529 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7530 | break; |
| 7531 | |
| 7532 | default: |
| 7533 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7534 | } |
| 7535 | } |
| 7536 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7537 | /** |
| 7538 | * Class to handle late fixup of offsets into constant area. |
| 7539 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7540 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7541 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7542 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7543 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7544 | |
| 7545 | protected: |
| 7546 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7547 | |
| 7548 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7549 | |
| 7550 | private: |
| 7551 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7552 | // Patch the correct offset for the instruction. The place to patch is the |
| 7553 | // last 4 bytes of the instruction. |
| 7554 | // The value to patch is the distance from the offset in the constant area |
| 7555 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7556 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7557 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7558 | |
| 7559 | // Patch in the right value. |
| 7560 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7561 | } |
| 7562 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7563 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7564 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7565 | }; |
| 7566 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7567 | /** |
| 7568 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7569 | * constant area. |
| 7570 | */ |
| 7571 | class JumpTableRIPFixup : public RIPFixup { |
| 7572 | public: |
| 7573 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7574 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7575 | |
| 7576 | void CreateJumpTable() { |
| 7577 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7578 | |
| 7579 | // Ensure that the reference to the jump table has the correct offset. |
| 7580 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7581 | SetOffset(offset_in_constant_table); |
| 7582 | |
| 7583 | // The label values in the jump table are computed relative to the |
| 7584 | // instruction addressing the constant area. |
| 7585 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7586 | |
| 7587 | // Populate the jump table with the correct values for the jump table. |
| 7588 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7589 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7590 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7591 | // The value that we want is the target offset - the position of the table. |
| 7592 | for (int32_t i = 0; i < num_entries; i++) { |
| 7593 | HBasicBlock* b = successors[i]; |
| 7594 | Label* l = codegen_->GetLabelOf(b); |
| 7595 | DCHECK(l->IsBound()); |
| 7596 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7597 | assembler->AppendInt32(offset_to_block); |
| 7598 | } |
| 7599 | } |
| 7600 | |
| 7601 | private: |
| 7602 | const HX86PackedSwitch* switch_instr_; |
| 7603 | }; |
| 7604 | |
| 7605 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7606 | // Generate the constant area if needed. |
| 7607 | X86Assembler* assembler = GetAssembler(); |
| 7608 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7609 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7610 | // byte values. |
| 7611 | assembler->Align(4, 0); |
| 7612 | constant_area_start_ = assembler->CodeSize(); |
| 7613 | |
| 7614 | // Populate any jump tables. |
| 7615 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7616 | jump_table->CreateJumpTable(); |
| 7617 | } |
| 7618 | |
| 7619 | // And now add the constant area to the generated code. |
| 7620 | assembler->AddConstantArea(); |
| 7621 | } |
| 7622 | |
| 7623 | // And finish up. |
| 7624 | CodeGenerator::Finalize(allocator); |
| 7625 | } |
| 7626 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7627 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7628 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7629 | return Address(reg, kDummy32BitOffset, fixup); |
| 7630 | } |
| 7631 | |
| 7632 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7633 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7634 | return Address(reg, kDummy32BitOffset, fixup); |
| 7635 | } |
| 7636 | |
| 7637 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7638 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7639 | return Address(reg, kDummy32BitOffset, fixup); |
| 7640 | } |
| 7641 | |
| 7642 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7643 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7644 | return Address(reg, kDummy32BitOffset, fixup); |
| 7645 | } |
| 7646 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7647 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7648 | if (value == 0) { |
| 7649 | __ xorl(dest, dest); |
| 7650 | } else { |
| 7651 | __ movl(dest, Immediate(value)); |
| 7652 | } |
| 7653 | } |
| 7654 | |
| 7655 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7656 | if (value == 0) { |
| 7657 | __ testl(dest, dest); |
| 7658 | } else { |
| 7659 | __ cmpl(dest, Immediate(value)); |
| 7660 | } |
| 7661 | } |
| 7662 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7663 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7664 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7665 | GenerateIntCompare(lhs_reg, rhs); |
| 7666 | } |
| 7667 | |
| 7668 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7669 | if (rhs.IsConstant()) { |
| 7670 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7671 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7672 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7673 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7674 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7675 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7676 | } |
| 7677 | } |
| 7678 | |
| 7679 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7680 | Location index, |
| 7681 | ScaleFactor scale, |
| 7682 | uint32_t data_offset) { |
| 7683 | return index.IsConstant() ? |
| 7684 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7685 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7686 | } |
| 7687 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7688 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7689 | Register reg, |
| 7690 | Register value) { |
| 7691 | // Create a fixup to be used to create and address the jump table. |
| 7692 | JumpTableRIPFixup* table_fixup = |
| 7693 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7694 | |
| 7695 | // We have to populate the jump tables. |
| 7696 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7697 | |
| 7698 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7699 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7700 | } |
| 7701 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7702 | // TODO: target as memory. |
| 7703 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7704 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7705 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7706 | return; |
| 7707 | } |
| 7708 | |
| 7709 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7710 | |
| 7711 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7712 | if (target.Equals(return_loc)) { |
| 7713 | return; |
| 7714 | } |
| 7715 | |
| 7716 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7717 | // with the else branch. |
| 7718 | if (type == Primitive::kPrimLong) { |
| 7719 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7720 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7721 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7722 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7723 | } else { |
| 7724 | // Let the parallel move resolver take care of all of this. |
| 7725 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7726 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7727 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7728 | } |
| 7729 | } |
| 7730 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7731 | #undef __ |
| 7732 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7733 | } // namespace x86 |
| 7734 | } // namespace art |