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)), |
Nicolas Geoffray | 997d121 | 2016-11-09 10:36:29 +0000 | [diff] [blame] | 1023 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1024 | constant_area_start_(-1), |
| 1025 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1026 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1027 | // Use a fake return address register to mimic Quick. |
| 1028 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1029 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1030 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1031 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1032 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1033 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1034 | } |
| 1035 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1036 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1037 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1038 | assembler_(codegen->GetAssembler()), |
| 1039 | codegen_(codegen) {} |
| 1040 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1041 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1042 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1045 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1046 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1047 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1048 | bool skip_overflow_check = |
| 1049 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1050 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1051 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1052 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1053 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1054 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1057 | if (HasEmptyFrame()) { |
| 1058 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1059 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1060 | |
| 1061 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1062 | Register reg = kCoreCalleeSaves[i]; |
| 1063 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1064 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1065 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1066 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1070 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1071 | __ subl(ESP, Immediate(adjust)); |
| 1072 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1073 | // Save the current method if we need it. Note that we do not |
| 1074 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1075 | // in the SSA graph. |
| 1076 | if (RequiresCurrentMethod()) { |
| 1077 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1078 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1082 | __ cfi().RememberState(); |
| 1083 | if (!HasEmptyFrame()) { |
| 1084 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1085 | __ addl(ESP, Immediate(adjust)); |
| 1086 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1087 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1088 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1089 | Register reg = kCoreCalleeSaves[i]; |
| 1090 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1091 | __ popl(reg); |
| 1092 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1093 | __ cfi().Restore(DWARFReg(reg)); |
| 1094 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1095 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1096 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1097 | __ ret(); |
| 1098 | __ cfi().RestoreState(); |
| 1099 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1102 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1103 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1106 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 1107 | switch (type) { |
| 1108 | case Primitive::kPrimBoolean: |
| 1109 | case Primitive::kPrimByte: |
| 1110 | case Primitive::kPrimChar: |
| 1111 | case Primitive::kPrimShort: |
| 1112 | case Primitive::kPrimInt: |
| 1113 | case Primitive::kPrimNot: |
| 1114 | return Location::RegisterLocation(EAX); |
| 1115 | |
| 1116 | case Primitive::kPrimLong: |
| 1117 | return Location::RegisterPairLocation(EAX, EDX); |
| 1118 | |
| 1119 | case Primitive::kPrimVoid: |
| 1120 | return Location::NoLocation(); |
| 1121 | |
| 1122 | case Primitive::kPrimDouble: |
| 1123 | case Primitive::kPrimFloat: |
| 1124 | return Location::FpuRegisterLocation(XMM0); |
| 1125 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1126 | |
| 1127 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1131 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1132 | } |
| 1133 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1134 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1135 | switch (type) { |
| 1136 | case Primitive::kPrimBoolean: |
| 1137 | case Primitive::kPrimByte: |
| 1138 | case Primitive::kPrimChar: |
| 1139 | case Primitive::kPrimShort: |
| 1140 | case Primitive::kPrimInt: |
| 1141 | case Primitive::kPrimNot: { |
| 1142 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1143 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1144 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1145 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1146 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1147 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1148 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1149 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1150 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1151 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1152 | uint32_t index = gp_index_; |
| 1153 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1154 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1155 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1156 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1157 | calling_convention.GetRegisterPairAt(index)); |
| 1158 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1159 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1160 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1165 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1166 | stack_index_++; |
| 1167 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1168 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1169 | } else { |
| 1170 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1175 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1176 | stack_index_ += 2; |
| 1177 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1178 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1179 | } else { |
| 1180 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1184 | case Primitive::kPrimVoid: |
| 1185 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1186 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1187 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1188 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1189 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1190 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1191 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1192 | if (source.Equals(destination)) { |
| 1193 | return; |
| 1194 | } |
| 1195 | if (destination.IsRegister()) { |
| 1196 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1197 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1198 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1199 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1200 | } else { |
| 1201 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1202 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1203 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1204 | } else if (destination.IsFpuRegister()) { |
| 1205 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1206 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1207 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1208 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1209 | } else { |
| 1210 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1211 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1212 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1213 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1214 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1215 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1216 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1217 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1218 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1219 | } else if (source.IsConstant()) { |
| 1220 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1221 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1222 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1223 | } else { |
| 1224 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1225 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1226 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1232 | if (source.Equals(destination)) { |
| 1233 | return; |
| 1234 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1235 | if (destination.IsRegisterPair()) { |
| 1236 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1237 | EmitParallelMoves( |
| 1238 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1239 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1240 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1241 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1242 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1243 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1244 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1245 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1246 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1247 | __ psrlq(src_reg, Immediate(32)); |
| 1248 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1249 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1250 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1251 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1252 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1253 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1254 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1255 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1256 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1257 | if (source.IsFpuRegister()) { |
| 1258 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1259 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1260 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1261 | } else if (source.IsRegisterPair()) { |
| 1262 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1263 | // Create stack space for 2 elements. |
| 1264 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1265 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1266 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1267 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1268 | // And remove the temporary stack space we allocated. |
| 1269 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1270 | } else { |
| 1271 | LOG(FATAL) << "Unimplemented"; |
| 1272 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1273 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1274 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1275 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1276 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1277 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1278 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1279 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1280 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1281 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1282 | } else if (source.IsConstant()) { |
| 1283 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1284 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1285 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1286 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1287 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1288 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1289 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1290 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1291 | EmitParallelMoves( |
| 1292 | Location::StackSlot(source.GetStackIndex()), |
| 1293 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1294 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1295 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1296 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1297 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1298 | } |
| 1299 | } |
| 1300 | } |
| 1301 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1302 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1303 | DCHECK(location.IsRegister()); |
| 1304 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1305 | } |
| 1306 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1307 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1308 | HParallelMove move(GetGraph()->GetArena()); |
| 1309 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1310 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1311 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1312 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1313 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1314 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1315 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1319 | if (location.IsRegister()) { |
| 1320 | locations->AddTemp(location); |
| 1321 | } else if (location.IsRegisterPair()) { |
| 1322 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1323 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1324 | } else { |
| 1325 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1326 | } |
| 1327 | } |
| 1328 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1329 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1330 | DCHECK(!successor->IsExitBlock()); |
| 1331 | |
| 1332 | HBasicBlock* block = got->GetBlock(); |
| 1333 | HInstruction* previous = got->GetPrevious(); |
| 1334 | |
| 1335 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1336 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1337 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1338 | return; |
| 1339 | } |
| 1340 | |
| 1341 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1342 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1343 | } |
| 1344 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1345 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1346 | } |
| 1347 | } |
| 1348 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1349 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1350 | got->SetLocations(nullptr); |
| 1351 | } |
| 1352 | |
| 1353 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1354 | HandleGoto(got, got->GetSuccessor()); |
| 1355 | } |
| 1356 | |
| 1357 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1358 | try_boundary->SetLocations(nullptr); |
| 1359 | } |
| 1360 | |
| 1361 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1362 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1363 | if (!successor->IsExitBlock()) { |
| 1364 | HandleGoto(try_boundary, successor); |
| 1365 | } |
| 1366 | } |
| 1367 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1368 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1369 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1372 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1375 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1376 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1377 | LabelType* true_label, |
| 1378 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1379 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1380 | __ j(kUnordered, true_label); |
| 1381 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1382 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1383 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1384 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1385 | } |
| 1386 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1387 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1388 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1389 | LabelType* true_label, |
| 1390 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1391 | LocationSummary* locations = cond->GetLocations(); |
| 1392 | Location left = locations->InAt(0); |
| 1393 | Location right = locations->InAt(1); |
| 1394 | IfCondition if_cond = cond->GetCondition(); |
| 1395 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1396 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1397 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1398 | IfCondition true_high_cond = if_cond; |
| 1399 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1400 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1401 | |
| 1402 | // Set the conditions for the test, remembering that == needs to be |
| 1403 | // decided using the low words. |
| 1404 | switch (if_cond) { |
| 1405 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1406 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1407 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1408 | break; |
| 1409 | case kCondLT: |
| 1410 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1411 | break; |
| 1412 | case kCondLE: |
| 1413 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1414 | break; |
| 1415 | case kCondGT: |
| 1416 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1417 | break; |
| 1418 | case kCondGE: |
| 1419 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1420 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1421 | case kCondB: |
| 1422 | false_high_cond = kCondA; |
| 1423 | break; |
| 1424 | case kCondBE: |
| 1425 | true_high_cond = kCondB; |
| 1426 | break; |
| 1427 | case kCondA: |
| 1428 | false_high_cond = kCondB; |
| 1429 | break; |
| 1430 | case kCondAE: |
| 1431 | true_high_cond = kCondA; |
| 1432 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | if (right.IsConstant()) { |
| 1436 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1437 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1438 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1440 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1441 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1442 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1443 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1444 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1446 | __ j(X86Condition(true_high_cond), true_label); |
| 1447 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1448 | } |
| 1449 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1450 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1451 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1452 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1453 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1454 | |
| 1455 | __ cmpl(left_high, right_high); |
| 1456 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1457 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1458 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1459 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1460 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1461 | __ j(X86Condition(true_high_cond), true_label); |
| 1462 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1463 | } |
| 1464 | // Must be equal high, so compare the lows. |
| 1465 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1466 | } else { |
| 1467 | DCHECK(right.IsDoubleStackSlot()); |
| 1468 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1469 | if (if_cond == kCondNE) { |
| 1470 | __ j(X86Condition(true_high_cond), true_label); |
| 1471 | } else if (if_cond == kCondEQ) { |
| 1472 | __ j(X86Condition(false_high_cond), false_label); |
| 1473 | } else { |
| 1474 | __ j(X86Condition(true_high_cond), true_label); |
| 1475 | __ j(X86Condition(false_high_cond), false_label); |
| 1476 | } |
| 1477 | // Must be equal high, so compare the lows. |
| 1478 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1479 | } |
| 1480 | // The last comparison might be unsigned. |
| 1481 | __ j(final_condition, true_label); |
| 1482 | } |
| 1483 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1484 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1485 | Location rhs, |
| 1486 | HInstruction* insn, |
| 1487 | bool is_double) { |
| 1488 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1489 | if (is_double) { |
| 1490 | if (rhs.IsFpuRegister()) { |
| 1491 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1492 | } else if (const_area != nullptr) { |
| 1493 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1494 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1495 | codegen_->LiteralDoubleAddress( |
| 1496 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1497 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1498 | } else { |
| 1499 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1500 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1501 | } |
| 1502 | } else { |
| 1503 | if (rhs.IsFpuRegister()) { |
| 1504 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1505 | } else if (const_area != nullptr) { |
| 1506 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1507 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1508 | codegen_->LiteralFloatAddress( |
| 1509 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1510 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1511 | } else { |
| 1512 | DCHECK(rhs.IsStackSlot()); |
| 1513 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1514 | } |
| 1515 | } |
| 1516 | } |
| 1517 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1518 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1519 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1520 | LabelType* true_target_in, |
| 1521 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1522 | // Generated branching requires both targets to be explicit. If either of the |
| 1523 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1524 | LabelType fallthrough_target; |
| 1525 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1526 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1527 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1528 | LocationSummary* locations = condition->GetLocations(); |
| 1529 | Location left = locations->InAt(0); |
| 1530 | Location right = locations->InAt(1); |
| 1531 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1532 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1533 | switch (type) { |
| 1534 | case Primitive::kPrimLong: |
| 1535 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1536 | break; |
| 1537 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1538 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1539 | GenerateFPJumps(condition, true_target, false_target); |
| 1540 | break; |
| 1541 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1542 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1543 | GenerateFPJumps(condition, true_target, false_target); |
| 1544 | break; |
| 1545 | default: |
| 1546 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1547 | } |
| 1548 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1549 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1550 | __ jmp(false_target); |
| 1551 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1552 | |
| 1553 | if (fallthrough_target.IsLinked()) { |
| 1554 | __ Bind(&fallthrough_target); |
| 1555 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1556 | } |
| 1557 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1558 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1559 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1560 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1561 | // conditions if they are materialized due to the complex branching. |
| 1562 | return cond->IsCondition() && |
| 1563 | cond->GetNext() == branch && |
| 1564 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1565 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1566 | } |
| 1567 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1568 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1569 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1570 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1571 | LabelType* true_target, |
| 1572 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1573 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1574 | |
| 1575 | if (true_target == nullptr && false_target == nullptr) { |
| 1576 | // Nothing to do. The code always falls through. |
| 1577 | return; |
| 1578 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1579 | // Constant condition, statically compared against "true" (integer value 1). |
| 1580 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1581 | if (true_target != nullptr) { |
| 1582 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1583 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1584 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1585 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1586 | if (false_target != nullptr) { |
| 1587 | __ jmp(false_target); |
| 1588 | } |
| 1589 | } |
| 1590 | return; |
| 1591 | } |
| 1592 | |
| 1593 | // The following code generates these patterns: |
| 1594 | // (1) true_target == nullptr && false_target != nullptr |
| 1595 | // - opposite condition true => branch to false_target |
| 1596 | // (2) true_target != nullptr && false_target == nullptr |
| 1597 | // - condition true => branch to true_target |
| 1598 | // (3) true_target != nullptr && false_target != nullptr |
| 1599 | // - condition true => branch to true_target |
| 1600 | // - branch to false_target |
| 1601 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1602 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1603 | if (true_target == nullptr) { |
| 1604 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1605 | } else { |
| 1606 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1607 | } |
| 1608 | } else { |
| 1609 | // Materialized condition, compare against 0. |
| 1610 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1611 | if (lhs.IsRegister()) { |
| 1612 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1613 | } else { |
| 1614 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1615 | } |
| 1616 | if (true_target == nullptr) { |
| 1617 | __ j(kEqual, false_target); |
| 1618 | } else { |
| 1619 | __ j(kNotEqual, true_target); |
| 1620 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1621 | } |
| 1622 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1623 | // Condition has not been materialized, use its inputs as the comparison and |
| 1624 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1625 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1626 | |
| 1627 | // If this is a long or FP comparison that has been folded into |
| 1628 | // the HCondition, generate the comparison directly. |
| 1629 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1630 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1631 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1632 | return; |
| 1633 | } |
| 1634 | |
| 1635 | Location lhs = condition->GetLocations()->InAt(0); |
| 1636 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1637 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1638 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1639 | if (true_target == nullptr) { |
| 1640 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1641 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1642 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1643 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1644 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1645 | |
| 1646 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1647 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1648 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1649 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1650 | } |
| 1651 | } |
| 1652 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1653 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1654 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1655 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1656 | locations->SetInAt(0, Location::Any()); |
| 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1661 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1662 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1663 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1664 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1665 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1666 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1667 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1671 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1672 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1673 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1674 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1675 | locations->SetInAt(0, Location::Any()); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1680 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1681 | GenerateTestAndBranch<Label>(deoptimize, |
| 1682 | /* condition_input_index */ 0, |
| 1683 | slow_path->GetEntryLabel(), |
| 1684 | /* false_target */ nullptr); |
| 1685 | } |
| 1686 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1687 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1688 | // There are no conditional move instructions for XMMs. |
| 1689 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1690 | return false; |
| 1691 | } |
| 1692 | |
| 1693 | // A FP condition doesn't generate the single CC that we need. |
| 1694 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1695 | HInstruction* condition = select->GetCondition(); |
| 1696 | if (condition->IsCondition()) { |
| 1697 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1698 | if (compare_type == Primitive::kPrimLong || |
| 1699 | Primitive::IsFloatingPointType(compare_type)) { |
| 1700 | return false; |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | // We can generate a CMOV for this Select. |
| 1705 | return true; |
| 1706 | } |
| 1707 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1708 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1709 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1710 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1711 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1712 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1713 | } else { |
| 1714 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1715 | if (SelectCanUseCMOV(select)) { |
| 1716 | if (select->InputAt(1)->IsConstant()) { |
| 1717 | // Cmov can't handle a constant value. |
| 1718 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1719 | } else { |
| 1720 | locations->SetInAt(1, Location::Any()); |
| 1721 | } |
| 1722 | } else { |
| 1723 | locations->SetInAt(1, Location::Any()); |
| 1724 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1725 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1726 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1727 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1728 | } |
| 1729 | locations->SetOut(Location::SameAsFirstInput()); |
| 1730 | } |
| 1731 | |
| 1732 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1733 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1734 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1735 | if (SelectCanUseCMOV(select)) { |
| 1736 | // If both the condition and the source types are integer, we can generate |
| 1737 | // a CMOV to implement Select. |
| 1738 | |
| 1739 | HInstruction* select_condition = select->GetCondition(); |
| 1740 | Condition cond = kNotEqual; |
| 1741 | |
| 1742 | // Figure out how to test the 'condition'. |
| 1743 | if (select_condition->IsCondition()) { |
| 1744 | HCondition* condition = select_condition->AsCondition(); |
| 1745 | if (!condition->IsEmittedAtUseSite()) { |
| 1746 | // This was a previously materialized condition. |
| 1747 | // Can we use the existing condition code? |
| 1748 | if (AreEflagsSetFrom(condition, select)) { |
| 1749 | // Materialization was the previous instruction. Condition codes are right. |
| 1750 | cond = X86Condition(condition->GetCondition()); |
| 1751 | } else { |
| 1752 | // No, we have to recreate the condition code. |
| 1753 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1754 | __ testl(cond_reg, cond_reg); |
| 1755 | } |
| 1756 | } else { |
| 1757 | // We can't handle FP or long here. |
| 1758 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1759 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1760 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1761 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1762 | cond = X86Condition(condition->GetCondition()); |
| 1763 | } |
| 1764 | } else { |
| 1765 | // Must be a boolean condition, which needs to be compared to 0. |
| 1766 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1767 | __ testl(cond_reg, cond_reg); |
| 1768 | } |
| 1769 | |
| 1770 | // If the condition is true, overwrite the output, which already contains false. |
| 1771 | Location false_loc = locations->InAt(0); |
| 1772 | Location true_loc = locations->InAt(1); |
| 1773 | if (select->GetType() == Primitive::kPrimLong) { |
| 1774 | // 64 bit conditional move. |
| 1775 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1776 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1777 | if (true_loc.IsRegisterPair()) { |
| 1778 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1779 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1780 | } else { |
| 1781 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1782 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1783 | } |
| 1784 | } else { |
| 1785 | // 32 bit conditional move. |
| 1786 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1787 | if (true_loc.IsRegister()) { |
| 1788 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1789 | } else { |
| 1790 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1791 | } |
| 1792 | } |
| 1793 | } else { |
| 1794 | NearLabel false_target; |
| 1795 | GenerateTestAndBranch<NearLabel>( |
| 1796 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1797 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1798 | __ Bind(&false_target); |
| 1799 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1802 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1803 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1804 | } |
| 1805 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1806 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1807 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | void CodeGeneratorX86::GenerateNop() { |
| 1811 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1814 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1815 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1816 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1817 | // Handle the long/FP comparisons made in instruction simplification. |
| 1818 | switch (cond->InputAt(0)->GetType()) { |
| 1819 | case Primitive::kPrimLong: { |
| 1820 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1821 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1822 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1823 | locations->SetOut(Location::RequiresRegister()); |
| 1824 | } |
| 1825 | break; |
| 1826 | } |
| 1827 | case Primitive::kPrimFloat: |
| 1828 | case Primitive::kPrimDouble: { |
| 1829 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1830 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1831 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1832 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1833 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1834 | } else { |
| 1835 | locations->SetInAt(1, Location::Any()); |
| 1836 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1837 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1838 | locations->SetOut(Location::RequiresRegister()); |
| 1839 | } |
| 1840 | break; |
| 1841 | } |
| 1842 | default: |
| 1843 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1844 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1845 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1846 | // We need a byte register. |
| 1847 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1848 | } |
| 1849 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1850 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1853 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1854 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1855 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1856 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1857 | |
| 1858 | LocationSummary* locations = cond->GetLocations(); |
| 1859 | Location lhs = locations->InAt(0); |
| 1860 | Location rhs = locations->InAt(1); |
| 1861 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1862 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1863 | |
| 1864 | switch (cond->InputAt(0)->GetType()) { |
| 1865 | default: { |
| 1866 | // Integer case. |
| 1867 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1868 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1869 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1870 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1871 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1872 | return; |
| 1873 | } |
| 1874 | case Primitive::kPrimLong: |
| 1875 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1876 | break; |
| 1877 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1878 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1879 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1880 | break; |
| 1881 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1882 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1883 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1884 | break; |
| 1885 | } |
| 1886 | |
| 1887 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1888 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1889 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1890 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1891 | __ Bind(&false_label); |
| 1892 | __ xorl(reg, reg); |
| 1893 | __ jmp(&done_label); |
| 1894 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1895 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1896 | __ Bind(&true_label); |
| 1897 | __ movl(reg, Immediate(1)); |
| 1898 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1902 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1906 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1910 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1914 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1918 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1922 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1926 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1930 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1934 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1938 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1942 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1946 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1949 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1950 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1954 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1958 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1962 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1966 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1970 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1974 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1978 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1981 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1982 | LocationSummary* locations = |
| 1983 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1984 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1987 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1988 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1991 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1992 | LocationSummary* locations = |
| 1993 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1994 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1995 | } |
| 1996 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1997 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1998 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2001 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2002 | LocationSummary* locations = |
| 2003 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2004 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2005 | } |
| 2006 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2007 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2008 | // Will be generated at use site. |
| 2009 | } |
| 2010 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2011 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2012 | LocationSummary* locations = |
| 2013 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2014 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2015 | } |
| 2016 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2017 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2018 | // Will be generated at use site. |
| 2019 | } |
| 2020 | |
| 2021 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2022 | LocationSummary* locations = |
| 2023 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2024 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2025 | } |
| 2026 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2027 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2028 | // Will be generated at use site. |
| 2029 | } |
| 2030 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2031 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2032 | memory_barrier->SetLocations(nullptr); |
| 2033 | } |
| 2034 | |
| 2035 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2036 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2037 | } |
| 2038 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2039 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2040 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2043 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2044 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2047 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2048 | LocationSummary* locations = |
| 2049 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2050 | switch (ret->InputAt(0)->GetType()) { |
| 2051 | case Primitive::kPrimBoolean: |
| 2052 | case Primitive::kPrimByte: |
| 2053 | case Primitive::kPrimChar: |
| 2054 | case Primitive::kPrimShort: |
| 2055 | case Primitive::kPrimInt: |
| 2056 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2057 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2058 | break; |
| 2059 | |
| 2060 | case Primitive::kPrimLong: |
| 2061 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2062 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2063 | break; |
| 2064 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2065 | case Primitive::kPrimFloat: |
| 2066 | case Primitive::kPrimDouble: |
| 2067 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2068 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2069 | break; |
| 2070 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2071 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2072 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2073 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2076 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2077 | if (kIsDebugBuild) { |
| 2078 | switch (ret->InputAt(0)->GetType()) { |
| 2079 | case Primitive::kPrimBoolean: |
| 2080 | case Primitive::kPrimByte: |
| 2081 | case Primitive::kPrimChar: |
| 2082 | case Primitive::kPrimShort: |
| 2083 | case Primitive::kPrimInt: |
| 2084 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2085 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2086 | break; |
| 2087 | |
| 2088 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2089 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2090 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2091 | break; |
| 2092 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2093 | case Primitive::kPrimFloat: |
| 2094 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2095 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2096 | break; |
| 2097 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2098 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2099 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2100 | } |
| 2101 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2102 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2105 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2106 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2107 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2108 | // the method_idx. |
| 2109 | HandleInvoke(invoke); |
| 2110 | } |
| 2111 | |
| 2112 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2113 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2114 | } |
| 2115 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2116 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2117 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2118 | // art::PrepareForRegisterAllocation. |
| 2119 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2120 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2121 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2122 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2123 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2124 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2125 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2126 | return; |
| 2127 | } |
| 2128 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2129 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2130 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2131 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2132 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2133 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2134 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2135 | } |
| 2136 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2137 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2138 | if (invoke->GetLocations()->Intrinsified()) { |
| 2139 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2140 | intrinsic.Dispatch(invoke); |
| 2141 | return true; |
| 2142 | } |
| 2143 | return false; |
| 2144 | } |
| 2145 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2146 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2147 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2148 | // art::PrepareForRegisterAllocation. |
| 2149 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2150 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2151 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2152 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2153 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2154 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2155 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2156 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2157 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2158 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2162 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2163 | if (intrinsic.TryDispatch(invoke)) { |
| 2164 | return; |
| 2165 | } |
| 2166 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2167 | HandleInvoke(invoke); |
| 2168 | } |
| 2169 | |
| 2170 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2171 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2172 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2175 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2176 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2177 | return; |
| 2178 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2179 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2180 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2181 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2182 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2185 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2186 | // This call to HandleInvoke allocates a temporary (core) register |
| 2187 | // which is also used to transfer the hidden argument from FP to |
| 2188 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2189 | HandleInvoke(invoke); |
| 2190 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2191 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2195 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2196 | LocationSummary* locations = invoke->GetLocations(); |
| 2197 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2198 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2199 | Location receiver = locations->InAt(0); |
| 2200 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2201 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2202 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2203 | // won't be modified thereafter, before the `call` instruction. |
| 2204 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2205 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2206 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2207 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2208 | if (receiver.IsStackSlot()) { |
| 2209 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2210 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2211 | __ movl(temp, Address(temp, class_offset)); |
| 2212 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2213 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2214 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2215 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2216 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2217 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2218 | // emit a read barrier for the previous class reference load. |
| 2219 | // However this is not required in practice, as this is an |
| 2220 | // intermediate/temporary reference and because the current |
| 2221 | // concurrent copying collector keeps the from-space memory |
| 2222 | // intact/accessible until the end of the marking phase (the |
| 2223 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2224 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2225 | // temp = temp->GetAddressOfIMT() |
| 2226 | __ movl(temp, |
| 2227 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2228 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2229 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2230 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2231 | __ movl(temp, Address(temp, method_offset)); |
| 2232 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2233 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2234 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2235 | |
| 2236 | DCHECK(!codegen_->IsLeafMethod()); |
| 2237 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2238 | } |
| 2239 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2240 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2241 | LocationSummary* locations = |
| 2242 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2243 | switch (neg->GetResultType()) { |
| 2244 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2245 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2246 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2247 | locations->SetOut(Location::SameAsFirstInput()); |
| 2248 | break; |
| 2249 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2250 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2251 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2252 | locations->SetOut(Location::SameAsFirstInput()); |
| 2253 | locations->AddTemp(Location::RequiresRegister()); |
| 2254 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2255 | break; |
| 2256 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2257 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2258 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2259 | locations->SetOut(Location::SameAsFirstInput()); |
| 2260 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2261 | break; |
| 2262 | |
| 2263 | default: |
| 2264 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2269 | LocationSummary* locations = neg->GetLocations(); |
| 2270 | Location out = locations->Out(); |
| 2271 | Location in = locations->InAt(0); |
| 2272 | switch (neg->GetResultType()) { |
| 2273 | case Primitive::kPrimInt: |
| 2274 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2275 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2276 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2277 | break; |
| 2278 | |
| 2279 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2280 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2281 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2282 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2283 | // Negation is similar to subtraction from zero. The least |
| 2284 | // significant byte triggers a borrow when it is different from |
| 2285 | // zero; to take it into account, add 1 to the most significant |
| 2286 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2287 | // operation. |
| 2288 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2289 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2290 | break; |
| 2291 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2292 | case Primitive::kPrimFloat: { |
| 2293 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2294 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2295 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2296 | // Implement float negation with an exclusive or with value |
| 2297 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2298 | // single-precision floating-point number). |
| 2299 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2300 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2301 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2302 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2303 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2304 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2305 | case Primitive::kPrimDouble: { |
| 2306 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2307 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2308 | // Implement double negation with an exclusive or with value |
| 2309 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2310 | // a double-precision floating-point number). |
| 2311 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2312 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2313 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2314 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2315 | |
| 2316 | default: |
| 2317 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2318 | } |
| 2319 | } |
| 2320 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2321 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2322 | LocationSummary* locations = |
| 2323 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2324 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2325 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2326 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2327 | locations->SetOut(Location::SameAsFirstInput()); |
| 2328 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2329 | } |
| 2330 | |
| 2331 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2332 | LocationSummary* locations = neg->GetLocations(); |
| 2333 | Location out = locations->Out(); |
| 2334 | DCHECK(locations->InAt(0).Equals(out)); |
| 2335 | |
| 2336 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2337 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2338 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2339 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2340 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2341 | } else { |
| 2342 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2343 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2344 | } |
| 2345 | } |
| 2346 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2347 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2348 | Primitive::Type result_type = conversion->GetResultType(); |
| 2349 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2350 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2351 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2352 | // The float-to-long and double-to-long type conversions rely on a |
| 2353 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2354 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2355 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2356 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2357 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2358 | : LocationSummary::kNoCall; |
| 2359 | LocationSummary* locations = |
| 2360 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2361 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2362 | // The Java language does not allow treating boolean as an integral type but |
| 2363 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2364 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2365 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2366 | case Primitive::kPrimByte: |
| 2367 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2368 | case Primitive::kPrimLong: { |
| 2369 | // Type conversion from long to byte is a result of code transformations. |
| 2370 | HInstruction* input = conversion->InputAt(0); |
| 2371 | Location input_location = input->IsConstant() |
| 2372 | ? Location::ConstantLocation(input->AsConstant()) |
| 2373 | : Location::RegisterPairLocation(EAX, EDX); |
| 2374 | locations->SetInAt(0, input_location); |
| 2375 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2376 | // the validation of the linear scan implementation |
| 2377 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2378 | break; |
| 2379 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2380 | case Primitive::kPrimBoolean: |
| 2381 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2382 | case Primitive::kPrimShort: |
| 2383 | case Primitive::kPrimInt: |
| 2384 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2385 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2386 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2387 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2388 | // the validation of the linear scan implementation |
| 2389 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2390 | break; |
| 2391 | |
| 2392 | default: |
| 2393 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2394 | << " to " << result_type; |
| 2395 | } |
| 2396 | break; |
| 2397 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2398 | case Primitive::kPrimShort: |
| 2399 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2400 | case Primitive::kPrimLong: |
| 2401 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2402 | case Primitive::kPrimBoolean: |
| 2403 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2404 | case Primitive::kPrimByte: |
| 2405 | case Primitive::kPrimInt: |
| 2406 | case Primitive::kPrimChar: |
| 2407 | // Processing a Dex `int-to-short' instruction. |
| 2408 | locations->SetInAt(0, Location::Any()); |
| 2409 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2410 | break; |
| 2411 | |
| 2412 | default: |
| 2413 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2414 | << " to " << result_type; |
| 2415 | } |
| 2416 | break; |
| 2417 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2418 | case Primitive::kPrimInt: |
| 2419 | switch (input_type) { |
| 2420 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2421 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2422 | locations->SetInAt(0, Location::Any()); |
| 2423 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2424 | break; |
| 2425 | |
| 2426 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2427 | // Processing a Dex `float-to-int' instruction. |
| 2428 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2429 | locations->SetOut(Location::RequiresRegister()); |
| 2430 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2431 | break; |
| 2432 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2434 | // Processing a Dex `double-to-int' instruction. |
| 2435 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2436 | locations->SetOut(Location::RequiresRegister()); |
| 2437 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2438 | break; |
| 2439 | |
| 2440 | default: |
| 2441 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2442 | << " to " << result_type; |
| 2443 | } |
| 2444 | break; |
| 2445 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimLong: |
| 2447 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2448 | case Primitive::kPrimBoolean: |
| 2449 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2450 | case Primitive::kPrimByte: |
| 2451 | case Primitive::kPrimShort: |
| 2452 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2453 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2454 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2455 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2456 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2457 | break; |
| 2458 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2459 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2461 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2462 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2463 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2464 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2465 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2466 | // The runtime helper puts the result in EAX, EDX. |
| 2467 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2468 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2469 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2470 | |
| 2471 | default: |
| 2472 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2473 | << " to " << result_type; |
| 2474 | } |
| 2475 | break; |
| 2476 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2477 | case Primitive::kPrimChar: |
| 2478 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2479 | case Primitive::kPrimLong: |
| 2480 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2481 | case Primitive::kPrimBoolean: |
| 2482 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2483 | case Primitive::kPrimByte: |
| 2484 | case Primitive::kPrimShort: |
| 2485 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2486 | // Processing a Dex `int-to-char' instruction. |
| 2487 | locations->SetInAt(0, Location::Any()); |
| 2488 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2489 | break; |
| 2490 | |
| 2491 | default: |
| 2492 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2493 | << " to " << result_type; |
| 2494 | } |
| 2495 | break; |
| 2496 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2497 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2498 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimBoolean: |
| 2500 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2501 | case Primitive::kPrimByte: |
| 2502 | case Primitive::kPrimShort: |
| 2503 | case Primitive::kPrimInt: |
| 2504 | case Primitive::kPrimChar: |
| 2505 | // Processing a Dex `int-to-float' instruction. |
| 2506 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2507 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2508 | break; |
| 2509 | |
| 2510 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2511 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2512 | locations->SetInAt(0, Location::Any()); |
| 2513 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2514 | break; |
| 2515 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2517 | // Processing a Dex `double-to-float' instruction. |
| 2518 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2519 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2520 | break; |
| 2521 | |
| 2522 | default: |
| 2523 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2524 | << " to " << result_type; |
| 2525 | }; |
| 2526 | break; |
| 2527 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2528 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2529 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2530 | case Primitive::kPrimBoolean: |
| 2531 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2532 | case Primitive::kPrimByte: |
| 2533 | case Primitive::kPrimShort: |
| 2534 | case Primitive::kPrimInt: |
| 2535 | case Primitive::kPrimChar: |
| 2536 | // Processing a Dex `int-to-double' instruction. |
| 2537 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2538 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2539 | break; |
| 2540 | |
| 2541 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2542 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2543 | locations->SetInAt(0, Location::Any()); |
| 2544 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2545 | break; |
| 2546 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2547 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2548 | // Processing a Dex `float-to-double' instruction. |
| 2549 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2550 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2551 | break; |
| 2552 | |
| 2553 | default: |
| 2554 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2555 | << " to " << result_type; |
| 2556 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2557 | break; |
| 2558 | |
| 2559 | default: |
| 2560 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2561 | << " to " << result_type; |
| 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2566 | LocationSummary* locations = conversion->GetLocations(); |
| 2567 | Location out = locations->Out(); |
| 2568 | Location in = locations->InAt(0); |
| 2569 | Primitive::Type result_type = conversion->GetResultType(); |
| 2570 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2571 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2572 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2573 | case Primitive::kPrimByte: |
| 2574 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2575 | case Primitive::kPrimLong: |
| 2576 | // Type conversion from long to byte is a result of code transformations. |
| 2577 | if (in.IsRegisterPair()) { |
| 2578 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2579 | } else { |
| 2580 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2581 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2582 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2583 | } |
| 2584 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2585 | case Primitive::kPrimBoolean: |
| 2586 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2587 | case Primitive::kPrimShort: |
| 2588 | case Primitive::kPrimInt: |
| 2589 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2590 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2591 | if (in.IsRegister()) { |
| 2592 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2593 | } else { |
| 2594 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2595 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2596 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2597 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2598 | break; |
| 2599 | |
| 2600 | default: |
| 2601 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2602 | << " to " << result_type; |
| 2603 | } |
| 2604 | break; |
| 2605 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2606 | case Primitive::kPrimShort: |
| 2607 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2608 | case Primitive::kPrimLong: |
| 2609 | // Type conversion from long to short is a result of code transformations. |
| 2610 | if (in.IsRegisterPair()) { |
| 2611 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2612 | } else if (in.IsDoubleStackSlot()) { |
| 2613 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2614 | } else { |
| 2615 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2616 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2617 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2618 | } |
| 2619 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2620 | case Primitive::kPrimBoolean: |
| 2621 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimByte: |
| 2623 | case Primitive::kPrimInt: |
| 2624 | case Primitive::kPrimChar: |
| 2625 | // Processing a Dex `int-to-short' instruction. |
| 2626 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2627 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2628 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2629 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2630 | } else { |
| 2631 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2632 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2633 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2634 | } |
| 2635 | break; |
| 2636 | |
| 2637 | default: |
| 2638 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2639 | << " to " << result_type; |
| 2640 | } |
| 2641 | break; |
| 2642 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2643 | case Primitive::kPrimInt: |
| 2644 | switch (input_type) { |
| 2645 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2646 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2647 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2648 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2649 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2650 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2651 | } else { |
| 2652 | DCHECK(in.IsConstant()); |
| 2653 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2654 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2655 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2656 | } |
| 2657 | break; |
| 2658 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2659 | case Primitive::kPrimFloat: { |
| 2660 | // Processing a Dex `float-to-int' instruction. |
| 2661 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2662 | Register output = out.AsRegister<Register>(); |
| 2663 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2664 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2665 | |
| 2666 | __ movl(output, Immediate(kPrimIntMax)); |
| 2667 | // temp = int-to-float(output) |
| 2668 | __ cvtsi2ss(temp, output); |
| 2669 | // if input >= temp goto done |
| 2670 | __ comiss(input, temp); |
| 2671 | __ j(kAboveEqual, &done); |
| 2672 | // if input == NaN goto nan |
| 2673 | __ j(kUnordered, &nan); |
| 2674 | // output = float-to-int-truncate(input) |
| 2675 | __ cvttss2si(output, input); |
| 2676 | __ jmp(&done); |
| 2677 | __ Bind(&nan); |
| 2678 | // output = 0 |
| 2679 | __ xorl(output, output); |
| 2680 | __ Bind(&done); |
| 2681 | break; |
| 2682 | } |
| 2683 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2684 | case Primitive::kPrimDouble: { |
| 2685 | // Processing a Dex `double-to-int' instruction. |
| 2686 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2687 | Register output = out.AsRegister<Register>(); |
| 2688 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2689 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2690 | |
| 2691 | __ movl(output, Immediate(kPrimIntMax)); |
| 2692 | // temp = int-to-double(output) |
| 2693 | __ cvtsi2sd(temp, output); |
| 2694 | // if input >= temp goto done |
| 2695 | __ comisd(input, temp); |
| 2696 | __ j(kAboveEqual, &done); |
| 2697 | // if input == NaN goto nan |
| 2698 | __ j(kUnordered, &nan); |
| 2699 | // output = double-to-int-truncate(input) |
| 2700 | __ cvttsd2si(output, input); |
| 2701 | __ jmp(&done); |
| 2702 | __ Bind(&nan); |
| 2703 | // output = 0 |
| 2704 | __ xorl(output, output); |
| 2705 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2706 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2707 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2708 | |
| 2709 | default: |
| 2710 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2711 | << " to " << result_type; |
| 2712 | } |
| 2713 | break; |
| 2714 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2715 | case Primitive::kPrimLong: |
| 2716 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2717 | case Primitive::kPrimBoolean: |
| 2718 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2719 | case Primitive::kPrimByte: |
| 2720 | case Primitive::kPrimShort: |
| 2721 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2722 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2723 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2724 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2725 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2726 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2727 | __ cdq(); |
| 2728 | break; |
| 2729 | |
| 2730 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2731 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2732 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2733 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2734 | break; |
| 2735 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2736 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2737 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2738 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2739 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2740 | break; |
| 2741 | |
| 2742 | default: |
| 2743 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2744 | << " to " << result_type; |
| 2745 | } |
| 2746 | break; |
| 2747 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2748 | case Primitive::kPrimChar: |
| 2749 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2750 | case Primitive::kPrimLong: |
| 2751 | // Type conversion from long to short is a result of code transformations. |
| 2752 | if (in.IsRegisterPair()) { |
| 2753 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2754 | } else if (in.IsDoubleStackSlot()) { |
| 2755 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2756 | } else { |
| 2757 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2758 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2759 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2760 | } |
| 2761 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2762 | case Primitive::kPrimBoolean: |
| 2763 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2764 | case Primitive::kPrimByte: |
| 2765 | case Primitive::kPrimShort: |
| 2766 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2767 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2768 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2769 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2770 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2771 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2772 | } else { |
| 2773 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2774 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2775 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2776 | } |
| 2777 | break; |
| 2778 | |
| 2779 | default: |
| 2780 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2781 | << " to " << result_type; |
| 2782 | } |
| 2783 | break; |
| 2784 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2785 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2786 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2787 | case Primitive::kPrimBoolean: |
| 2788 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2789 | case Primitive::kPrimByte: |
| 2790 | case Primitive::kPrimShort: |
| 2791 | case Primitive::kPrimInt: |
| 2792 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2793 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2794 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2795 | break; |
| 2796 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2797 | case Primitive::kPrimLong: { |
| 2798 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2799 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2800 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2801 | // Create stack space for the call to |
| 2802 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2803 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2804 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2805 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2806 | __ subl(ESP, Immediate(adjustment)); |
| 2807 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2808 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2809 | // Load the value to the FP stack, using temporaries if needed. |
| 2810 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2811 | |
| 2812 | if (out.IsStackSlot()) { |
| 2813 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2814 | } else { |
| 2815 | __ fstps(Address(ESP, 0)); |
| 2816 | Location stack_temp = Location::StackSlot(0); |
| 2817 | codegen_->Move32(out, stack_temp); |
| 2818 | } |
| 2819 | |
| 2820 | // Remove the temporary stack space we allocated. |
| 2821 | if (adjustment != 0) { |
| 2822 | __ addl(ESP, Immediate(adjustment)); |
| 2823 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2824 | break; |
| 2825 | } |
| 2826 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2827 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2828 | // Processing a Dex `double-to-float' instruction. |
| 2829 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2830 | break; |
| 2831 | |
| 2832 | default: |
| 2833 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2834 | << " to " << result_type; |
| 2835 | }; |
| 2836 | break; |
| 2837 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2838 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2839 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2840 | case Primitive::kPrimBoolean: |
| 2841 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2842 | case Primitive::kPrimByte: |
| 2843 | case Primitive::kPrimShort: |
| 2844 | case Primitive::kPrimInt: |
| 2845 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2846 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2847 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2848 | break; |
| 2849 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2850 | case Primitive::kPrimLong: { |
| 2851 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2852 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2853 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2854 | // Create stack space for the call to |
| 2855 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2856 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2857 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2858 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2859 | __ subl(ESP, Immediate(adjustment)); |
| 2860 | } |
| 2861 | |
| 2862 | // Load the value to the FP stack, using temporaries if needed. |
| 2863 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2864 | |
| 2865 | if (out.IsDoubleStackSlot()) { |
| 2866 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2867 | } else { |
| 2868 | __ fstpl(Address(ESP, 0)); |
| 2869 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2870 | codegen_->Move64(out, stack_temp); |
| 2871 | } |
| 2872 | |
| 2873 | // Remove the temporary stack space we allocated. |
| 2874 | if (adjustment != 0) { |
| 2875 | __ addl(ESP, Immediate(adjustment)); |
| 2876 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2877 | break; |
| 2878 | } |
| 2879 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2880 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2881 | // Processing a Dex `float-to-double' instruction. |
| 2882 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2883 | break; |
| 2884 | |
| 2885 | default: |
| 2886 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2887 | << " to " << result_type; |
| 2888 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2889 | break; |
| 2890 | |
| 2891 | default: |
| 2892 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2893 | << " to " << result_type; |
| 2894 | } |
| 2895 | } |
| 2896 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2897 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2898 | LocationSummary* locations = |
| 2899 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2900 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2901 | case Primitive::kPrimInt: { |
| 2902 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2903 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2904 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2905 | break; |
| 2906 | } |
| 2907 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2908 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2909 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2910 | locations->SetInAt(1, Location::Any()); |
| 2911 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2912 | break; |
| 2913 | } |
| 2914 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2915 | case Primitive::kPrimFloat: |
| 2916 | case Primitive::kPrimDouble: { |
| 2917 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2918 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2919 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2920 | } else if (add->InputAt(1)->IsConstant()) { |
| 2921 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2922 | } else { |
| 2923 | locations->SetInAt(1, Location::Any()); |
| 2924 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2925 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2926 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2927 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2928 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2929 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2930 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2931 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2932 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2936 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2937 | Location first = locations->InAt(0); |
| 2938 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2939 | Location out = locations->Out(); |
| 2940 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2941 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2942 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2943 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2944 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2945 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2946 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2947 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2948 | } else { |
| 2949 | __ leal(out.AsRegister<Register>(), Address( |
| 2950 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2951 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2952 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2953 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2954 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2955 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2956 | } else { |
| 2957 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2958 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2959 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2960 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2961 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2962 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2963 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2967 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2968 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2969 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2970 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2971 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2972 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2973 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2974 | } else { |
| 2975 | DCHECK(second.IsConstant()) << second; |
| 2976 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2977 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2978 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2979 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2980 | break; |
| 2981 | } |
| 2982 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2983 | case Primitive::kPrimFloat: { |
| 2984 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2985 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2986 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2987 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2988 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2989 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2990 | codegen_->LiteralFloatAddress( |
| 2991 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2992 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2993 | } else { |
| 2994 | DCHECK(second.IsStackSlot()); |
| 2995 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2996 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2997 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | case Primitive::kPrimDouble: { |
| 3001 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3002 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3003 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3004 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3005 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3006 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3007 | codegen_->LiteralDoubleAddress( |
| 3008 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3009 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3010 | } else { |
| 3011 | DCHECK(second.IsDoubleStackSlot()); |
| 3012 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3013 | } |
| 3014 | break; |
| 3015 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3016 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3017 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3018 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3019 | } |
| 3020 | } |
| 3021 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3022 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3023 | LocationSummary* locations = |
| 3024 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3025 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3026 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3027 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3028 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3029 | locations->SetInAt(1, Location::Any()); |
| 3030 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3031 | break; |
| 3032 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3033 | case Primitive::kPrimFloat: |
| 3034 | case Primitive::kPrimDouble: { |
| 3035 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3036 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3037 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3038 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3039 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3040 | } else { |
| 3041 | locations->SetInAt(1, Location::Any()); |
| 3042 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3043 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3044 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3045 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3046 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3047 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3048 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3049 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3053 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3054 | Location first = locations->InAt(0); |
| 3055 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3056 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3057 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3058 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3059 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3060 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3061 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3062 | __ subl(first.AsRegister<Register>(), |
| 3063 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3064 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3065 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3066 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3067 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3071 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3072 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3073 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3074 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3075 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3076 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3077 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3078 | } else { |
| 3079 | DCHECK(second.IsConstant()) << second; |
| 3080 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3081 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3082 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3083 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3084 | break; |
| 3085 | } |
| 3086 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3087 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3088 | if (second.IsFpuRegister()) { |
| 3089 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3090 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3091 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3092 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3093 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3094 | codegen_->LiteralFloatAddress( |
| 3095 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3096 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3097 | } else { |
| 3098 | DCHECK(second.IsStackSlot()); |
| 3099 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3100 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3101 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3105 | if (second.IsFpuRegister()) { |
| 3106 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3107 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3108 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3109 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3110 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3111 | codegen_->LiteralDoubleAddress( |
| 3112 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3113 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3114 | } else { |
| 3115 | DCHECK(second.IsDoubleStackSlot()); |
| 3116 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3117 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3118 | break; |
| 3119 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3120 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3121 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3122 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3126 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3127 | LocationSummary* locations = |
| 3128 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3129 | switch (mul->GetResultType()) { |
| 3130 | case Primitive::kPrimInt: |
| 3131 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3132 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3133 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3134 | // Can use 3 operand multiply. |
| 3135 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3136 | } else { |
| 3137 | locations->SetOut(Location::SameAsFirstInput()); |
| 3138 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3139 | break; |
| 3140 | case Primitive::kPrimLong: { |
| 3141 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3142 | locations->SetInAt(1, Location::Any()); |
| 3143 | locations->SetOut(Location::SameAsFirstInput()); |
| 3144 | // Needed for imul on 32bits with 64bits output. |
| 3145 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3146 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3147 | break; |
| 3148 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3149 | case Primitive::kPrimFloat: |
| 3150 | case Primitive::kPrimDouble: { |
| 3151 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3152 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3153 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3154 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3155 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3156 | } else { |
| 3157 | locations->SetInAt(1, Location::Any()); |
| 3158 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3159 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3160 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3161 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3162 | |
| 3163 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3164 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3165 | } |
| 3166 | } |
| 3167 | |
| 3168 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3169 | LocationSummary* locations = mul->GetLocations(); |
| 3170 | Location first = locations->InAt(0); |
| 3171 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3172 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3173 | |
| 3174 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3175 | case Primitive::kPrimInt: |
| 3176 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3177 | // problems where the output may not be the same as the first operand. |
| 3178 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3179 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3180 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3181 | } else if (second.IsRegister()) { |
| 3182 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3183 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3184 | } else { |
| 3185 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3186 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3187 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3188 | } |
| 3189 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3190 | |
| 3191 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3192 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3193 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3194 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3195 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3196 | |
| 3197 | DCHECK_EQ(EAX, eax); |
| 3198 | DCHECK_EQ(EDX, edx); |
| 3199 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3200 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3201 | // output: in1 |
| 3202 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3203 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3204 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3205 | if (second.IsConstant()) { |
| 3206 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3207 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3208 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3209 | int32_t low_value = Low32Bits(value); |
| 3210 | int32_t high_value = High32Bits(value); |
| 3211 | Immediate low(low_value); |
| 3212 | Immediate high(high_value); |
| 3213 | |
| 3214 | __ movl(eax, high); |
| 3215 | // eax <- in1.lo * in2.hi |
| 3216 | __ imull(eax, in1_lo); |
| 3217 | // in1.hi <- in1.hi * in2.lo |
| 3218 | __ imull(in1_hi, low); |
| 3219 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3220 | __ addl(in1_hi, eax); |
| 3221 | // move in2_lo to eax to prepare for double precision |
| 3222 | __ movl(eax, low); |
| 3223 | // edx:eax <- in1.lo * in2.lo |
| 3224 | __ mull(in1_lo); |
| 3225 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3226 | __ addl(in1_hi, edx); |
| 3227 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3228 | __ movl(in1_lo, eax); |
| 3229 | } else if (second.IsRegisterPair()) { |
| 3230 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3231 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3232 | |
| 3233 | __ movl(eax, in2_hi); |
| 3234 | // eax <- in1.lo * in2.hi |
| 3235 | __ imull(eax, in1_lo); |
| 3236 | // in1.hi <- in1.hi * in2.lo |
| 3237 | __ imull(in1_hi, in2_lo); |
| 3238 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3239 | __ addl(in1_hi, eax); |
| 3240 | // move in1_lo to eax to prepare for double precision |
| 3241 | __ movl(eax, in1_lo); |
| 3242 | // edx:eax <- in1.lo * in2.lo |
| 3243 | __ mull(in2_lo); |
| 3244 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3245 | __ addl(in1_hi, edx); |
| 3246 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3247 | __ movl(in1_lo, eax); |
| 3248 | } else { |
| 3249 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3250 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3251 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3252 | |
| 3253 | __ movl(eax, in2_hi); |
| 3254 | // eax <- in1.lo * in2.hi |
| 3255 | __ imull(eax, in1_lo); |
| 3256 | // in1.hi <- in1.hi * in2.lo |
| 3257 | __ imull(in1_hi, in2_lo); |
| 3258 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3259 | __ addl(in1_hi, eax); |
| 3260 | // move in1_lo to eax to prepare for double precision |
| 3261 | __ movl(eax, in1_lo); |
| 3262 | // edx:eax <- in1.lo * in2.lo |
| 3263 | __ mull(in2_lo); |
| 3264 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3265 | __ addl(in1_hi, edx); |
| 3266 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3267 | __ movl(in1_lo, eax); |
| 3268 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3269 | |
| 3270 | break; |
| 3271 | } |
| 3272 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3273 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3274 | DCHECK(first.Equals(locations->Out())); |
| 3275 | if (second.IsFpuRegister()) { |
| 3276 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3277 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3278 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3279 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3280 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3281 | codegen_->LiteralFloatAddress( |
| 3282 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3283 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3284 | } else { |
| 3285 | DCHECK(second.IsStackSlot()); |
| 3286 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3287 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3288 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3292 | DCHECK(first.Equals(locations->Out())); |
| 3293 | if (second.IsFpuRegister()) { |
| 3294 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3295 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3296 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3297 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3298 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3299 | codegen_->LiteralDoubleAddress( |
| 3300 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3301 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3302 | } else { |
| 3303 | DCHECK(second.IsDoubleStackSlot()); |
| 3304 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3305 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3306 | break; |
| 3307 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3308 | |
| 3309 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3310 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3311 | } |
| 3312 | } |
| 3313 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3314 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3315 | uint32_t temp_offset, |
| 3316 | uint32_t stack_adjustment, |
| 3317 | bool is_fp, |
| 3318 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3319 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3320 | DCHECK(!is_wide); |
| 3321 | if (is_fp) { |
| 3322 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3323 | } else { |
| 3324 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3325 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3326 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3327 | DCHECK(is_wide); |
| 3328 | if (is_fp) { |
| 3329 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3330 | } else { |
| 3331 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3332 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3333 | } else { |
| 3334 | // 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] | 3335 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3336 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3337 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3338 | if (is_fp) { |
| 3339 | __ flds(Address(ESP, temp_offset)); |
| 3340 | } else { |
| 3341 | __ filds(Address(ESP, temp_offset)); |
| 3342 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3343 | } else { |
| 3344 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3345 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3346 | if (is_fp) { |
| 3347 | __ fldl(Address(ESP, temp_offset)); |
| 3348 | } else { |
| 3349 | __ fildl(Address(ESP, temp_offset)); |
| 3350 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3351 | } |
| 3352 | } |
| 3353 | } |
| 3354 | |
| 3355 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3356 | Primitive::Type type = rem->GetResultType(); |
| 3357 | bool is_float = type == Primitive::kPrimFloat; |
| 3358 | size_t elem_size = Primitive::ComponentSize(type); |
| 3359 | LocationSummary* locations = rem->GetLocations(); |
| 3360 | Location first = locations->InAt(0); |
| 3361 | Location second = locations->InAt(1); |
| 3362 | Location out = locations->Out(); |
| 3363 | |
| 3364 | // Create stack space for 2 elements. |
| 3365 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3366 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3367 | |
| 3368 | // 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] | 3369 | const bool is_wide = !is_float; |
| 3370 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3371 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3372 | |
| 3373 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3374 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3375 | __ Bind(&retry); |
| 3376 | __ fprem(); |
| 3377 | |
| 3378 | // Move FP status to AX. |
| 3379 | __ fstsw(); |
| 3380 | |
| 3381 | // And see if the argument reduction is complete. This is signaled by the |
| 3382 | // C2 FPU flag bit set to 0. |
| 3383 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3384 | __ j(kNotEqual, &retry); |
| 3385 | |
| 3386 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3387 | // Store FP top of stack to real stack. |
| 3388 | if (is_float) { |
| 3389 | __ fsts(Address(ESP, 0)); |
| 3390 | } else { |
| 3391 | __ fstl(Address(ESP, 0)); |
| 3392 | } |
| 3393 | |
| 3394 | // Pop the 2 items from the FP stack. |
| 3395 | __ fucompp(); |
| 3396 | |
| 3397 | // Load the value from the stack into an XMM register. |
| 3398 | DCHECK(out.IsFpuRegister()) << out; |
| 3399 | if (is_float) { |
| 3400 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3401 | } else { |
| 3402 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3403 | } |
| 3404 | |
| 3405 | // And remove the temporary stack space we allocated. |
| 3406 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3407 | } |
| 3408 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3409 | |
| 3410 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3411 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3412 | |
| 3413 | LocationSummary* locations = instruction->GetLocations(); |
| 3414 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3415 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3416 | |
| 3417 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3418 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3419 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3420 | |
| 3421 | DCHECK(imm == 1 || imm == -1); |
| 3422 | |
| 3423 | if (instruction->IsRem()) { |
| 3424 | __ xorl(out_register, out_register); |
| 3425 | } else { |
| 3426 | __ movl(out_register, input_register); |
| 3427 | if (imm == -1) { |
| 3428 | __ negl(out_register); |
| 3429 | } |
| 3430 | } |
| 3431 | } |
| 3432 | |
| 3433 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3434 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3435 | LocationSummary* locations = instruction->GetLocations(); |
| 3436 | |
| 3437 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3438 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3439 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3440 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3441 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3442 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3443 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3444 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3445 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3446 | __ testl(input_register, input_register); |
| 3447 | __ cmovl(kGreaterEqual, num, input_register); |
| 3448 | int shift = CTZ(imm); |
| 3449 | __ sarl(num, Immediate(shift)); |
| 3450 | |
| 3451 | if (imm < 0) { |
| 3452 | __ negl(num); |
| 3453 | } |
| 3454 | |
| 3455 | __ movl(out_register, num); |
| 3456 | } |
| 3457 | |
| 3458 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3459 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3460 | |
| 3461 | LocationSummary* locations = instruction->GetLocations(); |
| 3462 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3463 | |
| 3464 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3465 | Register out = locations->Out().AsRegister<Register>(); |
| 3466 | Register num; |
| 3467 | Register edx; |
| 3468 | |
| 3469 | if (instruction->IsDiv()) { |
| 3470 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3471 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3472 | } else { |
| 3473 | edx = locations->Out().AsRegister<Register>(); |
| 3474 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3475 | } |
| 3476 | |
| 3477 | DCHECK_EQ(EAX, eax); |
| 3478 | DCHECK_EQ(EDX, edx); |
| 3479 | if (instruction->IsDiv()) { |
| 3480 | DCHECK_EQ(EAX, out); |
| 3481 | } else { |
| 3482 | DCHECK_EQ(EDX, out); |
| 3483 | } |
| 3484 | |
| 3485 | int64_t magic; |
| 3486 | int shift; |
| 3487 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3488 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3489 | // Save the numerator. |
| 3490 | __ movl(num, eax); |
| 3491 | |
| 3492 | // EAX = magic |
| 3493 | __ movl(eax, Immediate(magic)); |
| 3494 | |
| 3495 | // EDX:EAX = magic * numerator |
| 3496 | __ imull(num); |
| 3497 | |
| 3498 | if (imm > 0 && magic < 0) { |
| 3499 | // EDX += num |
| 3500 | __ addl(edx, num); |
| 3501 | } else if (imm < 0 && magic > 0) { |
| 3502 | __ subl(edx, num); |
| 3503 | } |
| 3504 | |
| 3505 | // Shift if needed. |
| 3506 | if (shift != 0) { |
| 3507 | __ sarl(edx, Immediate(shift)); |
| 3508 | } |
| 3509 | |
| 3510 | // EDX += 1 if EDX < 0 |
| 3511 | __ movl(eax, edx); |
| 3512 | __ shrl(edx, Immediate(31)); |
| 3513 | __ addl(edx, eax); |
| 3514 | |
| 3515 | if (instruction->IsRem()) { |
| 3516 | __ movl(eax, num); |
| 3517 | __ imull(edx, Immediate(imm)); |
| 3518 | __ subl(eax, edx); |
| 3519 | __ movl(edx, eax); |
| 3520 | } else { |
| 3521 | __ movl(eax, edx); |
| 3522 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3523 | } |
| 3524 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3525 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3526 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3527 | |
| 3528 | LocationSummary* locations = instruction->GetLocations(); |
| 3529 | Location out = locations->Out(); |
| 3530 | Location first = locations->InAt(0); |
| 3531 | Location second = locations->InAt(1); |
| 3532 | bool is_div = instruction->IsDiv(); |
| 3533 | |
| 3534 | switch (instruction->GetResultType()) { |
| 3535 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3536 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3537 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3538 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3539 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3540 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3541 | |
| 3542 | if (imm == 0) { |
| 3543 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3544 | } else if (imm == 1 || imm == -1) { |
| 3545 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3546 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3547 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3548 | } else { |
| 3549 | DCHECK(imm <= -2 || imm >= 2); |
| 3550 | GenerateDivRemWithAnyConstant(instruction); |
| 3551 | } |
| 3552 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3553 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3554 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3555 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3556 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3557 | Register second_reg = second.AsRegister<Register>(); |
| 3558 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3559 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3560 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3561 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3562 | __ cmpl(second_reg, Immediate(-1)); |
| 3563 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3564 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3565 | // edx:eax <- sign-extended of eax |
| 3566 | __ cdq(); |
| 3567 | // eax = quotient, edx = remainder |
| 3568 | __ idivl(second_reg); |
| 3569 | __ Bind(slow_path->GetExitLabel()); |
| 3570 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3571 | break; |
| 3572 | } |
| 3573 | |
| 3574 | case Primitive::kPrimLong: { |
| 3575 | InvokeRuntimeCallingConvention calling_convention; |
| 3576 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3577 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3578 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3579 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3580 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3581 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3582 | |
| 3583 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3584 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3585 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3586 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3587 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3588 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3589 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3590 | break; |
| 3591 | } |
| 3592 | |
| 3593 | default: |
| 3594 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3595 | } |
| 3596 | } |
| 3597 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3598 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3599 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3600 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3601 | : LocationSummary::kNoCall; |
| 3602 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3603 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3604 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3605 | case Primitive::kPrimInt: { |
| 3606 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3607 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3608 | locations->SetOut(Location::SameAsFirstInput()); |
| 3609 | // Intel uses edx:eax as the dividend. |
| 3610 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3611 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3612 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3613 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3614 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3615 | locations->AddTemp(Location::RequiresRegister()); |
| 3616 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3617 | break; |
| 3618 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3619 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3620 | InvokeRuntimeCallingConvention calling_convention; |
| 3621 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3622 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3623 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3624 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3625 | // Runtime helper puts the result in EAX, EDX. |
| 3626 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3627 | break; |
| 3628 | } |
| 3629 | case Primitive::kPrimFloat: |
| 3630 | case Primitive::kPrimDouble: { |
| 3631 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3632 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3633 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3634 | } else if (div->InputAt(1)->IsConstant()) { |
| 3635 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3636 | } else { |
| 3637 | locations->SetInAt(1, Location::Any()); |
| 3638 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3639 | locations->SetOut(Location::SameAsFirstInput()); |
| 3640 | break; |
| 3641 | } |
| 3642 | |
| 3643 | default: |
| 3644 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3645 | } |
| 3646 | } |
| 3647 | |
| 3648 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3649 | LocationSummary* locations = div->GetLocations(); |
| 3650 | Location first = locations->InAt(0); |
| 3651 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3652 | |
| 3653 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3654 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3655 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3656 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3657 | break; |
| 3658 | } |
| 3659 | |
| 3660 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3661 | if (second.IsFpuRegister()) { |
| 3662 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3663 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3664 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3665 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3666 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3667 | codegen_->LiteralFloatAddress( |
| 3668 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3669 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3670 | } else { |
| 3671 | DCHECK(second.IsStackSlot()); |
| 3672 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3673 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3674 | break; |
| 3675 | } |
| 3676 | |
| 3677 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3678 | if (second.IsFpuRegister()) { |
| 3679 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3680 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3681 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3682 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3683 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3684 | codegen_->LiteralDoubleAddress( |
| 3685 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3686 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3687 | } else { |
| 3688 | DCHECK(second.IsDoubleStackSlot()); |
| 3689 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3690 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3691 | break; |
| 3692 | } |
| 3693 | |
| 3694 | default: |
| 3695 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3696 | } |
| 3697 | } |
| 3698 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3699 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3700 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3701 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3702 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3703 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3704 | : LocationSummary::kNoCall; |
| 3705 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3706 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3707 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3708 | case Primitive::kPrimInt: { |
| 3709 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3710 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3711 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3712 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3713 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3714 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3715 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3716 | locations->AddTemp(Location::RequiresRegister()); |
| 3717 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3718 | break; |
| 3719 | } |
| 3720 | case Primitive::kPrimLong: { |
| 3721 | InvokeRuntimeCallingConvention calling_convention; |
| 3722 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3723 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3724 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3725 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3726 | // Runtime helper puts the result in EAX, EDX. |
| 3727 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3728 | break; |
| 3729 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3730 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3731 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3732 | locations->SetInAt(0, Location::Any()); |
| 3733 | locations->SetInAt(1, Location::Any()); |
| 3734 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3735 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3736 | break; |
| 3737 | } |
| 3738 | |
| 3739 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3740 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3745 | Primitive::Type type = rem->GetResultType(); |
| 3746 | switch (type) { |
| 3747 | case Primitive::kPrimInt: |
| 3748 | case Primitive::kPrimLong: { |
| 3749 | GenerateDivRemIntegral(rem); |
| 3750 | break; |
| 3751 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3752 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3753 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3754 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3755 | break; |
| 3756 | } |
| 3757 | default: |
| 3758 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3759 | } |
| 3760 | } |
| 3761 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3762 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3763 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3764 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3765 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3766 | case Primitive::kPrimByte: |
| 3767 | case Primitive::kPrimChar: |
| 3768 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3769 | case Primitive::kPrimInt: { |
| 3770 | locations->SetInAt(0, Location::Any()); |
| 3771 | break; |
| 3772 | } |
| 3773 | case Primitive::kPrimLong: { |
| 3774 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3775 | if (!instruction->IsConstant()) { |
| 3776 | locations->AddTemp(Location::RequiresRegister()); |
| 3777 | } |
| 3778 | break; |
| 3779 | } |
| 3780 | default: |
| 3781 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3782 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3786 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3787 | codegen_->AddSlowPath(slow_path); |
| 3788 | |
| 3789 | LocationSummary* locations = instruction->GetLocations(); |
| 3790 | Location value = locations->InAt(0); |
| 3791 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3792 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3793 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3794 | case Primitive::kPrimByte: |
| 3795 | case Primitive::kPrimChar: |
| 3796 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3797 | case Primitive::kPrimInt: { |
| 3798 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3799 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3800 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3801 | } else if (value.IsStackSlot()) { |
| 3802 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3803 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3804 | } else { |
| 3805 | DCHECK(value.IsConstant()) << value; |
| 3806 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3807 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3808 | } |
| 3809 | } |
| 3810 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3811 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3812 | case Primitive::kPrimLong: { |
| 3813 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3814 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3815 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3816 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3817 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3818 | } else { |
| 3819 | DCHECK(value.IsConstant()) << value; |
| 3820 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3821 | __ jmp(slow_path->GetEntryLabel()); |
| 3822 | } |
| 3823 | } |
| 3824 | break; |
| 3825 | } |
| 3826 | default: |
| 3827 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3828 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3829 | } |
| 3830 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3831 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3832 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3833 | |
| 3834 | LocationSummary* locations = |
| 3835 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3836 | |
| 3837 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3838 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3839 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3840 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3841 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3842 | // The shift count needs to be in CL or a constant. |
| 3843 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3844 | locations->SetOut(Location::SameAsFirstInput()); |
| 3845 | break; |
| 3846 | } |
| 3847 | default: |
| 3848 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3849 | } |
| 3850 | } |
| 3851 | |
| 3852 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3853 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3854 | |
| 3855 | LocationSummary* locations = op->GetLocations(); |
| 3856 | Location first = locations->InAt(0); |
| 3857 | Location second = locations->InAt(1); |
| 3858 | DCHECK(first.Equals(locations->Out())); |
| 3859 | |
| 3860 | switch (op->GetResultType()) { |
| 3861 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3862 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3863 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3864 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3865 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3866 | DCHECK_EQ(ECX, second_reg); |
| 3867 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3868 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3869 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3870 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3871 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3872 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3873 | } |
| 3874 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3875 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3876 | if (shift == 0) { |
| 3877 | return; |
| 3878 | } |
| 3879 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3880 | if (op->IsShl()) { |
| 3881 | __ shll(first_reg, imm); |
| 3882 | } else if (op->IsShr()) { |
| 3883 | __ sarl(first_reg, imm); |
| 3884 | } else { |
| 3885 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3886 | } |
| 3887 | } |
| 3888 | break; |
| 3889 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3890 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3891 | if (second.IsRegister()) { |
| 3892 | Register second_reg = second.AsRegister<Register>(); |
| 3893 | DCHECK_EQ(ECX, second_reg); |
| 3894 | if (op->IsShl()) { |
| 3895 | GenerateShlLong(first, second_reg); |
| 3896 | } else if (op->IsShr()) { |
| 3897 | GenerateShrLong(first, second_reg); |
| 3898 | } else { |
| 3899 | GenerateUShrLong(first, second_reg); |
| 3900 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3901 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3902 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3903 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3904 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3905 | if (shift != 0) { |
| 3906 | if (op->IsShl()) { |
| 3907 | GenerateShlLong(first, shift); |
| 3908 | } else if (op->IsShr()) { |
| 3909 | GenerateShrLong(first, shift); |
| 3910 | } else { |
| 3911 | GenerateUShrLong(first, shift); |
| 3912 | } |
| 3913 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3914 | } |
| 3915 | break; |
| 3916 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3917 | default: |
| 3918 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3919 | } |
| 3920 | } |
| 3921 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3922 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3923 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3924 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3925 | if (shift == 1) { |
| 3926 | // This is just an addition. |
| 3927 | __ addl(low, low); |
| 3928 | __ adcl(high, high); |
| 3929 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3930 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3931 | codegen_->EmitParallelMoves( |
| 3932 | loc.ToLow(), |
| 3933 | loc.ToHigh(), |
| 3934 | Primitive::kPrimInt, |
| 3935 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3936 | loc.ToLow(), |
| 3937 | Primitive::kPrimInt); |
| 3938 | } else if (shift > 32) { |
| 3939 | // Low part becomes 0. High part is low part << (shift-32). |
| 3940 | __ movl(high, low); |
| 3941 | __ shll(high, Immediate(shift - 32)); |
| 3942 | __ xorl(low, low); |
| 3943 | } else { |
| 3944 | // Between 1 and 31. |
| 3945 | __ shld(high, low, Immediate(shift)); |
| 3946 | __ shll(low, Immediate(shift)); |
| 3947 | } |
| 3948 | } |
| 3949 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3950 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3951 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3952 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3953 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3954 | __ testl(shifter, Immediate(32)); |
| 3955 | __ j(kEqual, &done); |
| 3956 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3957 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3958 | __ Bind(&done); |
| 3959 | } |
| 3960 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3961 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3962 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3963 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3964 | if (shift == 32) { |
| 3965 | // Need to copy the sign. |
| 3966 | DCHECK_NE(low, high); |
| 3967 | __ movl(low, high); |
| 3968 | __ sarl(high, Immediate(31)); |
| 3969 | } else if (shift > 32) { |
| 3970 | DCHECK_NE(low, high); |
| 3971 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3972 | __ movl(low, high); |
| 3973 | __ sarl(high, Immediate(31)); |
| 3974 | __ sarl(low, Immediate(shift - 32)); |
| 3975 | } else { |
| 3976 | // Between 1 and 31. |
| 3977 | __ shrd(low, high, Immediate(shift)); |
| 3978 | __ sarl(high, Immediate(shift)); |
| 3979 | } |
| 3980 | } |
| 3981 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3982 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3983 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3984 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3985 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3986 | __ testl(shifter, Immediate(32)); |
| 3987 | __ j(kEqual, &done); |
| 3988 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3989 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3990 | __ Bind(&done); |
| 3991 | } |
| 3992 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3993 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3994 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3995 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3996 | if (shift == 32) { |
| 3997 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3998 | codegen_->EmitParallelMoves( |
| 3999 | loc.ToHigh(), |
| 4000 | loc.ToLow(), |
| 4001 | Primitive::kPrimInt, |
| 4002 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4003 | loc.ToHigh(), |
| 4004 | Primitive::kPrimInt); |
| 4005 | } else if (shift > 32) { |
| 4006 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4007 | __ movl(low, high); |
| 4008 | __ shrl(low, Immediate(shift - 32)); |
| 4009 | __ xorl(high, high); |
| 4010 | } else { |
| 4011 | // Between 1 and 31. |
| 4012 | __ shrd(low, high, Immediate(shift)); |
| 4013 | __ shrl(high, Immediate(shift)); |
| 4014 | } |
| 4015 | } |
| 4016 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4017 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4018 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4019 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4020 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4021 | __ testl(shifter, Immediate(32)); |
| 4022 | __ j(kEqual, &done); |
| 4023 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4024 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4025 | __ Bind(&done); |
| 4026 | } |
| 4027 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4028 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4029 | LocationSummary* locations = |
| 4030 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4031 | |
| 4032 | switch (ror->GetResultType()) { |
| 4033 | case Primitive::kPrimLong: |
| 4034 | // Add the temporary needed. |
| 4035 | locations->AddTemp(Location::RequiresRegister()); |
| 4036 | FALLTHROUGH_INTENDED; |
| 4037 | case Primitive::kPrimInt: |
| 4038 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4039 | // The shift count needs to be in CL (unless it is a constant). |
| 4040 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4041 | locations->SetOut(Location::SameAsFirstInput()); |
| 4042 | break; |
| 4043 | default: |
| 4044 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4045 | UNREACHABLE(); |
| 4046 | } |
| 4047 | } |
| 4048 | |
| 4049 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4050 | LocationSummary* locations = ror->GetLocations(); |
| 4051 | Location first = locations->InAt(0); |
| 4052 | Location second = locations->InAt(1); |
| 4053 | |
| 4054 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 4055 | Register first_reg = first.AsRegister<Register>(); |
| 4056 | if (second.IsRegister()) { |
| 4057 | Register second_reg = second.AsRegister<Register>(); |
| 4058 | __ rorl(first_reg, second_reg); |
| 4059 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4060 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4061 | __ rorl(first_reg, imm); |
| 4062 | } |
| 4063 | return; |
| 4064 | } |
| 4065 | |
| 4066 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 4067 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4068 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4069 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4070 | if (second.IsRegister()) { |
| 4071 | Register second_reg = second.AsRegister<Register>(); |
| 4072 | DCHECK_EQ(second_reg, ECX); |
| 4073 | __ movl(temp_reg, first_reg_hi); |
| 4074 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4075 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4076 | __ movl(temp_reg, first_reg_hi); |
| 4077 | __ testl(second_reg, Immediate(32)); |
| 4078 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4079 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4080 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4081 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4082 | if (shift_amt == 0) { |
| 4083 | // Already fine. |
| 4084 | return; |
| 4085 | } |
| 4086 | if (shift_amt == 32) { |
| 4087 | // Just swap. |
| 4088 | __ movl(temp_reg, first_reg_lo); |
| 4089 | __ movl(first_reg_lo, first_reg_hi); |
| 4090 | __ movl(first_reg_hi, temp_reg); |
| 4091 | return; |
| 4092 | } |
| 4093 | |
| 4094 | Immediate imm(shift_amt); |
| 4095 | // Save the constents of the low value. |
| 4096 | __ movl(temp_reg, first_reg_lo); |
| 4097 | |
| 4098 | // Shift right into low, feeding bits from high. |
| 4099 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4100 | |
| 4101 | // Shift right into high, feeding bits from the original low. |
| 4102 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4103 | |
| 4104 | // Swap if needed. |
| 4105 | if (shift_amt > 32) { |
| 4106 | __ movl(temp_reg, first_reg_lo); |
| 4107 | __ movl(first_reg_lo, first_reg_hi); |
| 4108 | __ movl(first_reg_hi, temp_reg); |
| 4109 | } |
| 4110 | } |
| 4111 | } |
| 4112 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4113 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4114 | HandleShift(shl); |
| 4115 | } |
| 4116 | |
| 4117 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4118 | HandleShift(shl); |
| 4119 | } |
| 4120 | |
| 4121 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4122 | HandleShift(shr); |
| 4123 | } |
| 4124 | |
| 4125 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4126 | HandleShift(shr); |
| 4127 | } |
| 4128 | |
| 4129 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4130 | HandleShift(ushr); |
| 4131 | } |
| 4132 | |
| 4133 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4134 | HandleShift(ushr); |
| 4135 | } |
| 4136 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4137 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4138 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4139 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4140 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4141 | if (instruction->IsStringAlloc()) { |
| 4142 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4143 | } else { |
| 4144 | InvokeRuntimeCallingConvention calling_convention; |
| 4145 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4146 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4147 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4151 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4152 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4153 | if (instruction->IsStringAlloc()) { |
| 4154 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4155 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4156 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4157 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4158 | __ call(Address(temp, code_offset.Int32Value())); |
| 4159 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4160 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4161 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4162 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4163 | DCHECK(!codegen_->IsLeafMethod()); |
| 4164 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4165 | } |
| 4166 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4167 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4168 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4169 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4170 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4171 | InvokeRuntimeCallingConvention calling_convention; |
| 4172 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4173 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4174 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4178 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4179 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4180 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4181 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4182 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4183 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4184 | DCHECK(!codegen_->IsLeafMethod()); |
| 4185 | } |
| 4186 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4187 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4188 | LocationSummary* locations = |
| 4189 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4190 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4191 | if (location.IsStackSlot()) { |
| 4192 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4193 | } else if (location.IsDoubleStackSlot()) { |
| 4194 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4195 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4196 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4197 | } |
| 4198 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4199 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4200 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4201 | } |
| 4202 | |
| 4203 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4204 | LocationSummary* locations = |
| 4205 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4206 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4207 | } |
| 4208 | |
| 4209 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4210 | } |
| 4211 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4212 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4213 | LocationSummary* locations = |
| 4214 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4215 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4216 | locations->SetOut(Location::RequiresRegister()); |
| 4217 | } |
| 4218 | |
| 4219 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4220 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4221 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4222 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4223 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4224 | __ movl(locations->Out().AsRegister<Register>(), |
| 4225 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4226 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4227 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4228 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4229 | __ movl(locations->Out().AsRegister<Register>(), |
| 4230 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4231 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4232 | // temp = temp->GetImtEntryAt(method_offset); |
| 4233 | __ movl(locations->Out().AsRegister<Register>(), |
| 4234 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4235 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4236 | } |
| 4237 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4238 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4239 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4240 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4241 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4242 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4243 | } |
| 4244 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4245 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4246 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4247 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4248 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4249 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4250 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4251 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4252 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4253 | break; |
| 4254 | |
| 4255 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4256 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4257 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4258 | break; |
| 4259 | |
| 4260 | default: |
| 4261 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4262 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4263 | } |
| 4264 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4265 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4266 | LocationSummary* locations = |
| 4267 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4268 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4269 | locations->SetOut(Location::SameAsFirstInput()); |
| 4270 | } |
| 4271 | |
| 4272 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4273 | LocationSummary* locations = bool_not->GetLocations(); |
| 4274 | Location in = locations->InAt(0); |
| 4275 | Location out = locations->Out(); |
| 4276 | DCHECK(in.Equals(out)); |
| 4277 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4278 | } |
| 4279 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4280 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4281 | LocationSummary* locations = |
| 4282 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4283 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4284 | case Primitive::kPrimBoolean: |
| 4285 | case Primitive::kPrimByte: |
| 4286 | case Primitive::kPrimShort: |
| 4287 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4288 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4289 | case Primitive::kPrimLong: { |
| 4290 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4291 | locations->SetInAt(1, Location::Any()); |
| 4292 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4293 | break; |
| 4294 | } |
| 4295 | case Primitive::kPrimFloat: |
| 4296 | case Primitive::kPrimDouble: { |
| 4297 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4298 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4299 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4300 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4301 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4302 | } else { |
| 4303 | locations->SetInAt(1, Location::Any()); |
| 4304 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4305 | locations->SetOut(Location::RequiresRegister()); |
| 4306 | break; |
| 4307 | } |
| 4308 | default: |
| 4309 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4310 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4311 | } |
| 4312 | |
| 4313 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4314 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4315 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4316 | Location left = locations->InAt(0); |
| 4317 | Location right = locations->InAt(1); |
| 4318 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4319 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4320 | Condition less_cond = kLess; |
| 4321 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4322 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4323 | case Primitive::kPrimBoolean: |
| 4324 | case Primitive::kPrimByte: |
| 4325 | case Primitive::kPrimShort: |
| 4326 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4327 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4328 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4329 | break; |
| 4330 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4331 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4332 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4333 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4334 | int32_t val_low = 0; |
| 4335 | int32_t val_high = 0; |
| 4336 | bool right_is_const = false; |
| 4337 | |
| 4338 | if (right.IsConstant()) { |
| 4339 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4340 | right_is_const = true; |
| 4341 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4342 | val_low = Low32Bits(val); |
| 4343 | val_high = High32Bits(val); |
| 4344 | } |
| 4345 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4346 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4347 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4348 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4349 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4350 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4351 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4352 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4353 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4354 | __ j(kLess, &less); // Signed compare. |
| 4355 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4356 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4357 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4358 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4359 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4360 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4361 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4362 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4363 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4364 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4365 | break; |
| 4366 | } |
| 4367 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4368 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4369 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4370 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4371 | break; |
| 4372 | } |
| 4373 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4374 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4375 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4376 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4377 | break; |
| 4378 | } |
| 4379 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4380 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4381 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4382 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4383 | __ movl(out, Immediate(0)); |
| 4384 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4385 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4386 | |
| 4387 | __ Bind(&greater); |
| 4388 | __ movl(out, Immediate(1)); |
| 4389 | __ jmp(&done); |
| 4390 | |
| 4391 | __ Bind(&less); |
| 4392 | __ movl(out, Immediate(-1)); |
| 4393 | |
| 4394 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4395 | } |
| 4396 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4397 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4398 | LocationSummary* locations = |
| 4399 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4400 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4401 | locations->SetInAt(i, Location::Any()); |
| 4402 | } |
| 4403 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4404 | } |
| 4405 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4406 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4407 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4408 | } |
| 4409 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4410 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4411 | /* |
| 4412 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4413 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4414 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4415 | */ |
| 4416 | switch (kind) { |
| 4417 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4418 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4419 | break; |
| 4420 | } |
| 4421 | case MemBarrierKind::kAnyStore: |
| 4422 | case MemBarrierKind::kLoadAny: |
| 4423 | case MemBarrierKind::kStoreStore: { |
| 4424 | // nop |
| 4425 | break; |
| 4426 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4427 | case MemBarrierKind::kNTStoreStore: |
| 4428 | // Non-Temporal Store/Store needs an explicit fence. |
| 4429 | MemoryFence(/* non-temporal */ true); |
| 4430 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4431 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4432 | } |
| 4433 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4434 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4435 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4436 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4437 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4438 | |
| 4439 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4440 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4441 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4442 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4443 | if (GetGraph()->HasIrreducibleLoops() && |
| 4444 | (dispatch_info.method_load_kind == |
| 4445 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4446 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4447 | } |
| 4448 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4449 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4450 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4451 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4452 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4453 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4454 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4455 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4456 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4457 | 0u |
| 4458 | }; |
| 4459 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4460 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4461 | } |
| 4462 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4463 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4464 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4465 | Register temp) { |
| 4466 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4467 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4468 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4469 | return location.AsRegister<Register>(); |
| 4470 | } |
| 4471 | // For intrinsics we allow any location, so it may be on the stack. |
| 4472 | if (!location.IsRegister()) { |
| 4473 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4474 | return temp; |
| 4475 | } |
| 4476 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4477 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4478 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4479 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4480 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4481 | if (slow_path != nullptr) { |
| 4482 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4483 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4484 | __ movl(temp, Address(ESP, stack_offset)); |
| 4485 | return temp; |
| 4486 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4487 | } |
| 4488 | return location.AsRegister<Register>(); |
| 4489 | } |
| 4490 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4491 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4492 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4493 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4494 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4495 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4496 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4497 | uint32_t offset = |
| 4498 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4499 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4500 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4501 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4502 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4503 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4504 | break; |
| 4505 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4506 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4507 | break; |
| 4508 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4509 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4510 | method_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 4511 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4512 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4513 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4514 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4515 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4516 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4517 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4518 | // Bind a new fixup label at the end of the "movl" insn. |
| 4519 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4520 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4521 | break; |
| 4522 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4523 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4524 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4525 | Register method_reg; |
| 4526 | Register reg = temp.AsRegister<Register>(); |
| 4527 | if (current_method.IsRegister()) { |
| 4528 | method_reg = current_method.AsRegister<Register>(); |
| 4529 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4530 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4531 | DCHECK(!current_method.IsValid()); |
| 4532 | method_reg = reg; |
| 4533 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4534 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4535 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4536 | __ movl(reg, Address(method_reg, |
| 4537 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4538 | // temp = temp[index_in_cache]; |
| 4539 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4540 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4541 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4542 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4543 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4544 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4545 | return callee_method; |
| 4546 | } |
| 4547 | |
| 4548 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4549 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4550 | |
| 4551 | switch (invoke->GetCodePtrLocation()) { |
| 4552 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4553 | __ call(GetFrameEntryLabel()); |
| 4554 | break; |
| 4555 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4556 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 4557 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4558 | Label* label = &relative_call_patches_.back().label; |
| 4559 | __ call(label); // Bind to the patch label, override at link time. |
| 4560 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4561 | break; |
| 4562 | } |
| 4563 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4564 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4565 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4566 | LOG(FATAL) << "Unsupported"; |
| 4567 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4568 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4569 | // (callee_method + offset_of_quick_compiled_code)() |
| 4570 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4571 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4572 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4573 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4577 | } |
| 4578 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4579 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4580 | Register temp = temp_in.AsRegister<Register>(); |
| 4581 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4582 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4583 | |
| 4584 | // Use the calling convention instead of the location of the receiver, as |
| 4585 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4586 | // slow path, the arguments have been moved to the right place, so here we are |
| 4587 | // guaranteed that the receiver is the first register of the calling convention. |
| 4588 | InvokeDexCallingConvention calling_convention; |
| 4589 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4590 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4591 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4592 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4593 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4594 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4595 | // emit a read barrier for the previous class reference load. |
| 4596 | // However this is not required in practice, as this is an |
| 4597 | // intermediate/temporary reference and because the current |
| 4598 | // concurrent copying collector keeps the from-space memory |
| 4599 | // intact/accessible until the end of the marking phase (the |
| 4600 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4601 | __ MaybeUnpoisonHeapReference(temp); |
| 4602 | // temp = temp->GetMethodAt(method_offset); |
| 4603 | __ movl(temp, Address(temp, method_offset)); |
| 4604 | // call temp->GetEntryPoint(); |
| 4605 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4606 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4607 | } |
| 4608 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4609 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4610 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4611 | simple_patches_.emplace_back(); |
| 4612 | __ Bind(&simple_patches_.back()); |
| 4613 | } |
| 4614 | } |
| 4615 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4616 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
| 4617 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4618 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4619 | __ Bind(&string_patches_.back().label); |
| 4620 | } |
| 4621 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4622 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
| 4623 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 4624 | __ Bind(&type_patches_.back().label); |
| 4625 | } |
| 4626 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4627 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4628 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| 4629 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4630 | return &string_patches_.back().label; |
| 4631 | } |
| 4632 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4633 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4634 | uint32_t element_offset) { |
| 4635 | // Add the patch entry and bind its label at the end of the instruction. |
| 4636 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4637 | return &pc_relative_dex_cache_patches_.back().label; |
| 4638 | } |
| 4639 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4640 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4641 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4642 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4643 | |
| 4644 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4645 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| 4646 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 4647 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4648 | for (const PatchInfo<Label>& info : infos) { |
| 4649 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4650 | linker_patches->push_back( |
| 4651 | Factory(literal_offset, &info.dex_file, GetMethodAddressOffset(), info.index)); |
| 4652 | } |
| 4653 | } |
| 4654 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4655 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4656 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4657 | size_t size = |
| 4658 | method_patches_.size() + |
| 4659 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4660 | pc_relative_dex_cache_patches_.size() + |
| 4661 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4662 | string_patches_.size() + |
| 4663 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4664 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4665 | for (const PatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4666 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4667 | 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] | 4668 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4669 | for (const PatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4670 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4671 | linker_patches->push_back( |
| 4672 | LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4673 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4674 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 4675 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4676 | for (const Label& label : simple_patches_) { |
| 4677 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4678 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4679 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4680 | if (!GetCompilerOptions().IsBootImage()) { |
| 4681 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 4682 | } else if (GetCompilerOptions().GetCompilePic()) { |
| 4683 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4684 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4685 | for (const PatchInfo<Label>& info : string_patches_) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4686 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4687 | linker_patches->push_back( |
| 4688 | LinkerPatch::StringPatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4689 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4690 | } |
| 4691 | if (GetCompilerOptions().GetCompilePic()) { |
| 4692 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(type_patches_, linker_patches); |
| 4693 | } else { |
| 4694 | for (const PatchInfo<Label>& info : type_patches_) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4695 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4696 | 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] | 4697 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4698 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4699 | } |
| 4700 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4701 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4702 | Register card, |
| 4703 | Register object, |
| 4704 | Register value, |
| 4705 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4706 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4707 | if (value_can_be_null) { |
| 4708 | __ testl(value, value); |
| 4709 | __ j(kEqual, &is_null); |
| 4710 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4711 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4712 | __ movl(temp, object); |
| 4713 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4714 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4715 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4716 | if (value_can_be_null) { |
| 4717 | __ Bind(&is_null); |
| 4718 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4719 | } |
| 4720 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4721 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4722 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4723 | |
| 4724 | bool object_field_get_with_read_barrier = |
| 4725 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4726 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4727 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4728 | kEmitCompilerReadBarrier ? |
| 4729 | LocationSummary::kCallOnSlowPath : |
| 4730 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4731 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4732 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4733 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4734 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4735 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4736 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4737 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4738 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4739 | // The output overlaps in case of long: we don't want the low move |
| 4740 | // to overwrite the object's location. Likewise, in the case of |
| 4741 | // an object field get with read barriers enabled, we do not want |
| 4742 | // the move to overwrite the object's location, as we need it to emit |
| 4743 | // the read barrier. |
| 4744 | locations->SetOut( |
| 4745 | Location::RequiresRegister(), |
| 4746 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4747 | Location::kOutputOverlap : |
| 4748 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4749 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4750 | |
| 4751 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4752 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4753 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4754 | // load the temp into the XMM and then copy the XMM into the |
| 4755 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4756 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4757 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4758 | } |
| 4759 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4760 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4761 | const FieldInfo& field_info) { |
| 4762 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4763 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4764 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4765 | Location base_loc = locations->InAt(0); |
| 4766 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4767 | Location out = locations->Out(); |
| 4768 | bool is_volatile = field_info.IsVolatile(); |
| 4769 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4770 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4771 | |
| 4772 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4773 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4774 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4775 | break; |
| 4776 | } |
| 4777 | |
| 4778 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4779 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4780 | break; |
| 4781 | } |
| 4782 | |
| 4783 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4784 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4785 | break; |
| 4786 | } |
| 4787 | |
| 4788 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4789 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4790 | break; |
| 4791 | } |
| 4792 | |
| 4793 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4794 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4795 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4796 | |
| 4797 | case Primitive::kPrimNot: { |
| 4798 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4799 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4800 | // Note that a potential implicit null check is handled in this |
| 4801 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4802 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4803 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4804 | if (is_volatile) { |
| 4805 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4806 | } |
| 4807 | } else { |
| 4808 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4809 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4810 | if (is_volatile) { |
| 4811 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4812 | } |
| 4813 | // If read barriers are enabled, emit read barriers other than |
| 4814 | // Baker's using a slow path (and also unpoison the loaded |
| 4815 | // reference, if heap poisoning is enabled). |
| 4816 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4817 | } |
| 4818 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4822 | if (is_volatile) { |
| 4823 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4824 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4825 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4826 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4827 | __ psrlq(temp, Immediate(32)); |
| 4828 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4829 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4830 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4831 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4832 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4833 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4834 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4835 | break; |
| 4836 | } |
| 4837 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4838 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4839 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4840 | break; |
| 4841 | } |
| 4842 | |
| 4843 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4844 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4845 | break; |
| 4846 | } |
| 4847 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4848 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4849 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4850 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4851 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4852 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4853 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4854 | // Potential implicit null checks, in the case of reference or |
| 4855 | // long fields, are handled in the previous switch statement. |
| 4856 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4857 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4858 | } |
| 4859 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4860 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4861 | if (field_type == Primitive::kPrimNot) { |
| 4862 | // Memory barriers, in the case of references, are also handled |
| 4863 | // in the previous switch statement. |
| 4864 | } else { |
| 4865 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4866 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4867 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4871 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4872 | |
| 4873 | LocationSummary* locations = |
| 4874 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4875 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4876 | bool is_volatile = field_info.IsVolatile(); |
| 4877 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4878 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4879 | || (field_type == Primitive::kPrimByte); |
| 4880 | |
| 4881 | // The register allocator does not support multiple |
| 4882 | // inputs that die at entry with one in a specific register. |
| 4883 | if (is_byte_type) { |
| 4884 | // Ensure the value is in a byte register. |
| 4885 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4886 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4887 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4888 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4889 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4890 | } else { |
| 4891 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4892 | } |
| 4893 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4894 | // 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] | 4895 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4896 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4897 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4898 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4899 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4900 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4901 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4902 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4903 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4904 | } else { |
| 4905 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4906 | |
| 4907 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4908 | // Temporary registers for the write barrier. |
| 4909 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4910 | // Ensure the card is in a byte register. |
| 4911 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4912 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4913 | } |
| 4914 | } |
| 4915 | |
| 4916 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4917 | const FieldInfo& field_info, |
| 4918 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4919 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4920 | |
| 4921 | LocationSummary* locations = instruction->GetLocations(); |
| 4922 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4923 | Location value = locations->InAt(1); |
| 4924 | bool is_volatile = field_info.IsVolatile(); |
| 4925 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4926 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4927 | bool needs_write_barrier = |
| 4928 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4929 | |
| 4930 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4931 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4932 | } |
| 4933 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4934 | bool maybe_record_implicit_null_check_done = false; |
| 4935 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4936 | switch (field_type) { |
| 4937 | case Primitive::kPrimBoolean: |
| 4938 | case Primitive::kPrimByte: { |
| 4939 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4940 | break; |
| 4941 | } |
| 4942 | |
| 4943 | case Primitive::kPrimShort: |
| 4944 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4945 | if (value.IsConstant()) { |
| 4946 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4947 | __ movw(Address(base, offset), Immediate(v)); |
| 4948 | } else { |
| 4949 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4950 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4951 | break; |
| 4952 | } |
| 4953 | |
| 4954 | case Primitive::kPrimInt: |
| 4955 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4956 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4957 | // Note that in the case where `value` is a null reference, |
| 4958 | // we do not enter this block, as the reference does not |
| 4959 | // need poisoning. |
| 4960 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4961 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4962 | __ movl(temp, value.AsRegister<Register>()); |
| 4963 | __ PoisonHeapReference(temp); |
| 4964 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4965 | } else if (value.IsConstant()) { |
| 4966 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4967 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4968 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4969 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4970 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4971 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4972 | break; |
| 4973 | } |
| 4974 | |
| 4975 | case Primitive::kPrimLong: { |
| 4976 | if (is_volatile) { |
| 4977 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4978 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4979 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4980 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4981 | __ punpckldq(temp1, temp2); |
| 4982 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4983 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4984 | } else if (value.IsConstant()) { |
| 4985 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4986 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4987 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4988 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4989 | } else { |
| 4990 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4991 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4992 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4993 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4994 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4995 | break; |
| 4996 | } |
| 4997 | |
| 4998 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4999 | if (value.IsConstant()) { |
| 5000 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5001 | __ movl(Address(base, offset), Immediate(v)); |
| 5002 | } else { |
| 5003 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5004 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5005 | break; |
| 5006 | } |
| 5007 | |
| 5008 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5009 | if (value.IsConstant()) { |
| 5010 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5011 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5012 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5013 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5014 | maybe_record_implicit_null_check_done = true; |
| 5015 | } else { |
| 5016 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5017 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5018 | break; |
| 5019 | } |
| 5020 | |
| 5021 | case Primitive::kPrimVoid: |
| 5022 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5023 | UNREACHABLE(); |
| 5024 | } |
| 5025 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5026 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5027 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5028 | } |
| 5029 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5030 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5031 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5032 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5033 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5034 | } |
| 5035 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5036 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5037 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5038 | } |
| 5039 | } |
| 5040 | |
| 5041 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5042 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5043 | } |
| 5044 | |
| 5045 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5046 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5047 | } |
| 5048 | |
| 5049 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5050 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5051 | } |
| 5052 | |
| 5053 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5054 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5058 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5059 | } |
| 5060 | |
| 5061 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5062 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5066 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5067 | } |
| 5068 | |
| 5069 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5070 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5071 | } |
| 5072 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5073 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5074 | HUnresolvedInstanceFieldGet* instruction) { |
| 5075 | FieldAccessCallingConventionX86 calling_convention; |
| 5076 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5077 | instruction, instruction->GetFieldType(), calling_convention); |
| 5078 | } |
| 5079 | |
| 5080 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5081 | HUnresolvedInstanceFieldGet* instruction) { |
| 5082 | FieldAccessCallingConventionX86 calling_convention; |
| 5083 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5084 | instruction->GetFieldType(), |
| 5085 | instruction->GetFieldIndex(), |
| 5086 | instruction->GetDexPc(), |
| 5087 | calling_convention); |
| 5088 | } |
| 5089 | |
| 5090 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5091 | HUnresolvedInstanceFieldSet* instruction) { |
| 5092 | FieldAccessCallingConventionX86 calling_convention; |
| 5093 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5094 | instruction, instruction->GetFieldType(), calling_convention); |
| 5095 | } |
| 5096 | |
| 5097 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5098 | HUnresolvedInstanceFieldSet* instruction) { |
| 5099 | FieldAccessCallingConventionX86 calling_convention; |
| 5100 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5101 | instruction->GetFieldType(), |
| 5102 | instruction->GetFieldIndex(), |
| 5103 | instruction->GetDexPc(), |
| 5104 | calling_convention); |
| 5105 | } |
| 5106 | |
| 5107 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5108 | HUnresolvedStaticFieldGet* instruction) { |
| 5109 | FieldAccessCallingConventionX86 calling_convention; |
| 5110 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5111 | instruction, instruction->GetFieldType(), calling_convention); |
| 5112 | } |
| 5113 | |
| 5114 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5115 | HUnresolvedStaticFieldGet* instruction) { |
| 5116 | FieldAccessCallingConventionX86 calling_convention; |
| 5117 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5118 | instruction->GetFieldType(), |
| 5119 | instruction->GetFieldIndex(), |
| 5120 | instruction->GetDexPc(), |
| 5121 | calling_convention); |
| 5122 | } |
| 5123 | |
| 5124 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5125 | HUnresolvedStaticFieldSet* instruction) { |
| 5126 | FieldAccessCallingConventionX86 calling_convention; |
| 5127 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5128 | instruction, instruction->GetFieldType(), calling_convention); |
| 5129 | } |
| 5130 | |
| 5131 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5132 | HUnresolvedStaticFieldSet* instruction) { |
| 5133 | FieldAccessCallingConventionX86 calling_convention; |
| 5134 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5135 | instruction->GetFieldType(), |
| 5136 | instruction->GetFieldIndex(), |
| 5137 | instruction->GetDexPc(), |
| 5138 | calling_convention); |
| 5139 | } |
| 5140 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5141 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5142 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5143 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5144 | ? Location::RequiresRegister() |
| 5145 | : Location::Any(); |
| 5146 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5147 | } |
| 5148 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5149 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5150 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5151 | return; |
| 5152 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5153 | LocationSummary* locations = instruction->GetLocations(); |
| 5154 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5155 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5156 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5157 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5158 | } |
| 5159 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5160 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5161 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5162 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5163 | |
| 5164 | LocationSummary* locations = instruction->GetLocations(); |
| 5165 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5166 | |
| 5167 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5168 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5169 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5170 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5171 | } else { |
| 5172 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5173 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5174 | __ jmp(slow_path->GetEntryLabel()); |
| 5175 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5176 | } |
| 5177 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5178 | } |
| 5179 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5180 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5181 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5182 | } |
| 5183 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5184 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5185 | bool object_array_get_with_read_barrier = |
| 5186 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5187 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5188 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5189 | object_array_get_with_read_barrier ? |
| 5190 | LocationSummary::kCallOnSlowPath : |
| 5191 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5192 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5193 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5194 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5195 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5196 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5197 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5198 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5199 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5200 | // The output overlaps in case of long: we don't want the low move |
| 5201 | // to overwrite the array's location. Likewise, in the case of an |
| 5202 | // object array get with read barriers enabled, we do not want the |
| 5203 | // move to overwrite the array's location, as we need it to emit |
| 5204 | // the read barrier. |
| 5205 | locations->SetOut( |
| 5206 | Location::RequiresRegister(), |
| 5207 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5208 | Location::kOutputOverlap : |
| 5209 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5210 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5214 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5215 | Location obj_loc = locations->InAt(0); |
| 5216 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5217 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5218 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5219 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5220 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5221 | Primitive::Type type = instruction->GetType(); |
| 5222 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5223 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5224 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5225 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5226 | break; |
| 5227 | } |
| 5228 | |
| 5229 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5230 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5231 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5232 | break; |
| 5233 | } |
| 5234 | |
| 5235 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5236 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5237 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5238 | break; |
| 5239 | } |
| 5240 | |
| 5241 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5242 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5243 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5244 | // Branch cases into compressed and uncompressed for each index's type. |
| 5245 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5246 | NearLabel done, not_compressed; |
| 5247 | __ cmpl(Address(obj, count_offset), Immediate(0)); |
| 5248 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5249 | __ j(kGreaterEqual, ¬_compressed); |
| 5250 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5251 | __ jmp(&done); |
| 5252 | __ Bind(¬_compressed); |
| 5253 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5254 | __ Bind(&done); |
| 5255 | } else { |
| 5256 | // Common case for charAt of array of char or when string compression's |
| 5257 | // feature is turned off. |
| 5258 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5259 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5260 | break; |
| 5261 | } |
| 5262 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5263 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5264 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5265 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5266 | break; |
| 5267 | } |
| 5268 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5269 | case Primitive::kPrimNot: { |
| 5270 | static_assert( |
| 5271 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5272 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5273 | // /* HeapReference<Object> */ out = |
| 5274 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5275 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5276 | // Note that a potential implicit null check is handled in this |
| 5277 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5278 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5279 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5280 | } else { |
| 5281 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5282 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5283 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5284 | // If read barriers are enabled, emit read barriers other than |
| 5285 | // Baker's using a slow path (and also unpoison the loaded |
| 5286 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5287 | if (index.IsConstant()) { |
| 5288 | uint32_t offset = |
| 5289 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5290 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5291 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5292 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5293 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5294 | } |
| 5295 | } |
| 5296 | break; |
| 5297 | } |
| 5298 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5299 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5300 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5301 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5302 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5303 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5304 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5305 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5306 | break; |
| 5307 | } |
| 5308 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5309 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5310 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5311 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5312 | break; |
| 5313 | } |
| 5314 | |
| 5315 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5316 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5317 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5318 | break; |
| 5319 | } |
| 5320 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5321 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5322 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5323 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5324 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5325 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5326 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5327 | // Potential implicit null checks, in the case of reference or |
| 5328 | // long arrays, are handled in the previous switch statement. |
| 5329 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5330 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5331 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5335 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5336 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5337 | bool needs_write_barrier = |
| 5338 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5339 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5340 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5341 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5342 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5343 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5344 | LocationSummary::kCallOnSlowPath : |
| 5345 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5346 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5347 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5348 | || (value_type == Primitive::kPrimByte); |
| 5349 | // We need the inputs to be different than the output in case of long operation. |
| 5350 | // In case of a byte operation, the register allocator does not support multiple |
| 5351 | // inputs that die at entry with one in a specific register. |
| 5352 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5353 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5354 | if (is_byte_type) { |
| 5355 | // Ensure the value is in a byte register. |
| 5356 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5357 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5358 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5359 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5360 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5361 | } |
| 5362 | if (needs_write_barrier) { |
| 5363 | // Temporary registers for the write barrier. |
| 5364 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5365 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5366 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5367 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5371 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5372 | Location array_loc = locations->InAt(0); |
| 5373 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5374 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5375 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5376 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5377 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5378 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5379 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5380 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5381 | bool needs_write_barrier = |
| 5382 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5383 | |
| 5384 | switch (value_type) { |
| 5385 | case Primitive::kPrimBoolean: |
| 5386 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5387 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5388 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5389 | if (value.IsRegister()) { |
| 5390 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5391 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5392 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5393 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5394 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5395 | break; |
| 5396 | } |
| 5397 | |
| 5398 | case Primitive::kPrimShort: |
| 5399 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5400 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5401 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5402 | if (value.IsRegister()) { |
| 5403 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5404 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5405 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5406 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5407 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5408 | break; |
| 5409 | } |
| 5410 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5411 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5412 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5413 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5414 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5415 | if (!value.IsRegister()) { |
| 5416 | // Just setting null. |
| 5417 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5418 | DCHECK(value.IsConstant()) << value; |
| 5419 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5420 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5421 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5422 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5423 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5424 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5425 | |
| 5426 | DCHECK(needs_write_barrier); |
| 5427 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5428 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5429 | // short when Baker read barriers are enabled. |
| 5430 | Label done; |
| 5431 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5432 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5433 | Location temp_loc = locations->GetTemp(0); |
| 5434 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5435 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5436 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5437 | codegen_->AddSlowPath(slow_path); |
| 5438 | if (instruction->GetValueCanBeNull()) { |
| 5439 | __ testl(register_value, register_value); |
| 5440 | __ j(kNotEqual, ¬_null); |
| 5441 | __ movl(address, Immediate(0)); |
| 5442 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5443 | __ jmp(&done); |
| 5444 | __ Bind(¬_null); |
| 5445 | } |
| 5446 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5447 | // Note that when Baker read barriers are enabled, the type |
| 5448 | // checks are performed without read barriers. This is fine, |
| 5449 | // even in the case where a class object is in the from-space |
| 5450 | // after the flip, as a comparison involving such a type would |
| 5451 | // not produce a false positive; it may of course produce a |
| 5452 | // false negative, in which case we would take the ArraySet |
| 5453 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5454 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5455 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5456 | __ movl(temp, Address(array, class_offset)); |
| 5457 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5458 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5459 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5460 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5461 | __ movl(temp, Address(temp, component_offset)); |
| 5462 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5463 | // nor the object reference in `register_value->klass`, as |
| 5464 | // we are comparing two poisoned references. |
| 5465 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5466 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5467 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5468 | __ j(kEqual, &do_put); |
| 5469 | // If heap poisoning is enabled, the `temp` reference has |
| 5470 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5471 | __ MaybeUnpoisonHeapReference(temp); |
| 5472 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5473 | // If heap poisoning is enabled, no need to unpoison the |
| 5474 | // heap reference loaded below, as it is only used for a |
| 5475 | // comparison with null. |
| 5476 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5477 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5478 | __ Bind(&do_put); |
| 5479 | } else { |
| 5480 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5481 | } |
| 5482 | } |
| 5483 | |
| 5484 | if (kPoisonHeapReferences) { |
| 5485 | __ movl(temp, register_value); |
| 5486 | __ PoisonHeapReference(temp); |
| 5487 | __ movl(address, temp); |
| 5488 | } else { |
| 5489 | __ movl(address, register_value); |
| 5490 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5491 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5492 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5493 | } |
| 5494 | |
| 5495 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5496 | codegen_->MarkGCCard( |
| 5497 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5498 | __ Bind(&done); |
| 5499 | |
| 5500 | if (slow_path != nullptr) { |
| 5501 | __ Bind(slow_path->GetExitLabel()); |
| 5502 | } |
| 5503 | |
| 5504 | break; |
| 5505 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5506 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5507 | case Primitive::kPrimInt: { |
| 5508 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5509 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5510 | if (value.IsRegister()) { |
| 5511 | __ movl(address, value.AsRegister<Register>()); |
| 5512 | } else { |
| 5513 | DCHECK(value.IsConstant()) << value; |
| 5514 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5515 | __ movl(address, Immediate(v)); |
| 5516 | } |
| 5517 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5518 | break; |
| 5519 | } |
| 5520 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5521 | case Primitive::kPrimLong: { |
| 5522 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5523 | if (value.IsRegisterPair()) { |
| 5524 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5525 | value.AsRegisterPairLow<Register>()); |
| 5526 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5527 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5528 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5529 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5530 | DCHECK(value.IsConstant()); |
| 5531 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5532 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5533 | Immediate(Low32Bits(val))); |
| 5534 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5535 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5536 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5537 | } |
| 5538 | break; |
| 5539 | } |
| 5540 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5541 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5542 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5543 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5544 | if (value.IsFpuRegister()) { |
| 5545 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5546 | } else { |
| 5547 | DCHECK(value.IsConstant()); |
| 5548 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5549 | __ movl(address, Immediate(v)); |
| 5550 | } |
| 5551 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5552 | break; |
| 5553 | } |
| 5554 | |
| 5555 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5556 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5557 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5558 | if (value.IsFpuRegister()) { |
| 5559 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5560 | } else { |
| 5561 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5562 | Address address_hi = |
| 5563 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5564 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5565 | __ movl(address, Immediate(Low32Bits(v))); |
| 5566 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5567 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5568 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5569 | break; |
| 5570 | } |
| 5571 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5572 | case Primitive::kPrimVoid: |
| 5573 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5574 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5575 | } |
| 5576 | } |
| 5577 | |
| 5578 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5579 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5580 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5581 | if (!instruction->IsEmittedAtUseSite()) { |
| 5582 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5583 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5587 | if (instruction->IsEmittedAtUseSite()) { |
| 5588 | return; |
| 5589 | } |
| 5590 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5591 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5592 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5593 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5594 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5595 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5596 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5597 | // Mask out most significant bit in case the array is String's array of char. |
| 5598 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 5599 | __ andl(out, Immediate(INT32_MAX)); |
| 5600 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5604 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5605 | InvokeRuntimeCallingConvention calling_convention; |
| 5606 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5607 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5608 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5609 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5610 | HInstruction* length = instruction->InputAt(1); |
| 5611 | if (!length->IsEmittedAtUseSite()) { |
| 5612 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5613 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5614 | // Need register to see array's length. |
| 5615 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5616 | locations->AddTemp(Location::RequiresRegister()); |
| 5617 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5621 | const bool is_string_compressed_char_at = |
| 5622 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5623 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5624 | Location index_loc = locations->InAt(0); |
| 5625 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5626 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5627 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5628 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5629 | if (length_loc.IsConstant()) { |
| 5630 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5631 | if (index_loc.IsConstant()) { |
| 5632 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5633 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5634 | if (index < 0 || index >= length) { |
| 5635 | codegen_->AddSlowPath(slow_path); |
| 5636 | __ jmp(slow_path->GetEntryLabel()); |
| 5637 | } else { |
| 5638 | // Some optimization after BCE may have generated this, and we should not |
| 5639 | // generate a bounds check if it is a valid range. |
| 5640 | } |
| 5641 | return; |
| 5642 | } |
| 5643 | |
| 5644 | // We have to reverse the jump condition because the length is the constant. |
| 5645 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5646 | __ cmpl(index_reg, Immediate(length)); |
| 5647 | codegen_->AddSlowPath(slow_path); |
| 5648 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5649 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5650 | HInstruction* array_length = instruction->InputAt(1); |
| 5651 | if (array_length->IsEmittedAtUseSite()) { |
| 5652 | // Address the length field in the array. |
| 5653 | DCHECK(array_length->IsArrayLength()); |
| 5654 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5655 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5656 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5657 | if (is_string_compressed_char_at) { |
| 5658 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5659 | __ movl(length_reg, array_len); |
| 5660 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| 5661 | __ andl(length_reg, Immediate(INT32_MAX)); |
| 5662 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5663 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5664 | // Checking bounds for general case: |
| 5665 | // Array of char or string's array with feature compression off. |
| 5666 | if (index_loc.IsConstant()) { |
| 5667 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5668 | __ cmpl(array_len, Immediate(value)); |
| 5669 | } else { |
| 5670 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5671 | } |
| 5672 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5673 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5674 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5675 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5676 | } |
| 5677 | codegen_->AddSlowPath(slow_path); |
| 5678 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5679 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5680 | } |
| 5681 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5682 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5683 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5687 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5688 | } |
| 5689 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5690 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5691 | LocationSummary* locations = |
| 5692 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5693 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5697 | HBasicBlock* block = instruction->GetBlock(); |
| 5698 | if (block->GetLoopInformation() != nullptr) { |
| 5699 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5700 | // The back edge will generate the suspend check. |
| 5701 | return; |
| 5702 | } |
| 5703 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5704 | // The goto will generate the suspend check. |
| 5705 | return; |
| 5706 | } |
| 5707 | GenerateSuspendCheck(instruction, nullptr); |
| 5708 | } |
| 5709 | |
| 5710 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5711 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5712 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5713 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5714 | if (slow_path == nullptr) { |
| 5715 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5716 | instruction->SetSlowPath(slow_path); |
| 5717 | codegen_->AddSlowPath(slow_path); |
| 5718 | if (successor != nullptr) { |
| 5719 | DCHECK(successor->IsLoopHeader()); |
| 5720 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5721 | } |
| 5722 | } else { |
| 5723 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5724 | } |
| 5725 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5726 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5727 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5728 | if (successor == nullptr) { |
| 5729 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5730 | __ Bind(slow_path->GetReturnLabel()); |
| 5731 | } else { |
| 5732 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5733 | __ jmp(slow_path->GetEntryLabel()); |
| 5734 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5735 | } |
| 5736 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5737 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5738 | return codegen_->GetAssembler(); |
| 5739 | } |
| 5740 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5741 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5742 | ScratchRegisterScope ensure_scratch( |
| 5743 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5744 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5745 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5746 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5747 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5748 | } |
| 5749 | |
| 5750 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5751 | ScratchRegisterScope ensure_scratch( |
| 5752 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5753 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5754 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5755 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5756 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5757 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5758 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5762 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5763 | Location source = move->GetSource(); |
| 5764 | Location destination = move->GetDestination(); |
| 5765 | |
| 5766 | if (source.IsRegister()) { |
| 5767 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5768 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5769 | } else if (destination.IsFpuRegister()) { |
| 5770 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5771 | } else { |
| 5772 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5773 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5774 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5775 | } else if (source.IsRegisterPair()) { |
| 5776 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5777 | // Create stack space for 2 elements. |
| 5778 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5779 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5780 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5781 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5782 | // And remove the temporary stack space we allocated. |
| 5783 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5784 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5785 | if (destination.IsRegister()) { |
| 5786 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5787 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5788 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5789 | } else if (destination.IsRegisterPair()) { |
| 5790 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5791 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5792 | __ psrlq(src_reg, Immediate(32)); |
| 5793 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5794 | } else if (destination.IsStackSlot()) { |
| 5795 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5796 | } else { |
| 5797 | DCHECK(destination.IsDoubleStackSlot()); |
| 5798 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5799 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5800 | } else if (source.IsStackSlot()) { |
| 5801 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5802 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5803 | } else if (destination.IsFpuRegister()) { |
| 5804 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5805 | } else { |
| 5806 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5807 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5808 | } |
| 5809 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5810 | if (destination.IsRegisterPair()) { |
| 5811 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5812 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5813 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5814 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5815 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5816 | } else { |
| 5817 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5818 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5819 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5820 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5821 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5822 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5823 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5824 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5825 | if (value == 0) { |
| 5826 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5827 | } else { |
| 5828 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5829 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5830 | } else { |
| 5831 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5832 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5833 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5834 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5835 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5836 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5837 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5838 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5839 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5840 | if (value == 0) { |
| 5841 | // Easy handling of 0.0. |
| 5842 | __ xorps(dest, dest); |
| 5843 | } else { |
| 5844 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5845 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5846 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5847 | __ movl(temp, Immediate(value)); |
| 5848 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5849 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5850 | } else { |
| 5851 | DCHECK(destination.IsStackSlot()) << destination; |
| 5852 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5853 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5854 | } else if (constant->IsLongConstant()) { |
| 5855 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5856 | int32_t low_value = Low32Bits(value); |
| 5857 | int32_t high_value = High32Bits(value); |
| 5858 | Immediate low(low_value); |
| 5859 | Immediate high(high_value); |
| 5860 | if (destination.IsDoubleStackSlot()) { |
| 5861 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5862 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5863 | } else { |
| 5864 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5865 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5866 | } |
| 5867 | } else { |
| 5868 | DCHECK(constant->IsDoubleConstant()); |
| 5869 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5870 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5871 | int32_t low_value = Low32Bits(value); |
| 5872 | int32_t high_value = High32Bits(value); |
| 5873 | Immediate low(low_value); |
| 5874 | Immediate high(high_value); |
| 5875 | if (destination.IsFpuRegister()) { |
| 5876 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5877 | if (value == 0) { |
| 5878 | // Easy handling of 0.0. |
| 5879 | __ xorpd(dest, dest); |
| 5880 | } else { |
| 5881 | __ pushl(high); |
| 5882 | __ pushl(low); |
| 5883 | __ movsd(dest, Address(ESP, 0)); |
| 5884 | __ addl(ESP, Immediate(8)); |
| 5885 | } |
| 5886 | } else { |
| 5887 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5888 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5889 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5890 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5891 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5892 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5893 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5894 | } |
| 5895 | } |
| 5896 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5897 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5898 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5899 | ScratchRegisterScope ensure_scratch( |
| 5900 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5901 | |
| 5902 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5903 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5904 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5905 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5906 | } |
| 5907 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5908 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5909 | ScratchRegisterScope ensure_scratch( |
| 5910 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5911 | |
| 5912 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5913 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5914 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5915 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5916 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5917 | } |
| 5918 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5919 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5920 | ScratchRegisterScope ensure_scratch1( |
| 5921 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5922 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5923 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5924 | ScratchRegisterScope ensure_scratch2( |
| 5925 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5926 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5927 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5928 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5929 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5930 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5931 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5932 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5933 | } |
| 5934 | |
| 5935 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5936 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5937 | Location source = move->GetSource(); |
| 5938 | Location destination = move->GetDestination(); |
| 5939 | |
| 5940 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5941 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5942 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5943 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5944 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5945 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5946 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5947 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5948 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5949 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5950 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5951 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5952 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5953 | // Use XOR Swap algorithm to avoid a temporary. |
| 5954 | DCHECK_NE(source.reg(), destination.reg()); |
| 5955 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5956 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5957 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5958 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5959 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5960 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5961 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5962 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5963 | // Take advantage of the 16 bytes in the XMM register. |
| 5964 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5965 | Address stack(ESP, destination.GetStackIndex()); |
| 5966 | // Load the double into the high doubleword. |
| 5967 | __ movhpd(reg, stack); |
| 5968 | |
| 5969 | // Store the low double into the destination. |
| 5970 | __ movsd(stack, reg); |
| 5971 | |
| 5972 | // Move the high double to the low double. |
| 5973 | __ psrldq(reg, Immediate(8)); |
| 5974 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5975 | // Take advantage of the 16 bytes in the XMM register. |
| 5976 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5977 | Address stack(ESP, source.GetStackIndex()); |
| 5978 | // Load the double into the high doubleword. |
| 5979 | __ movhpd(reg, stack); |
| 5980 | |
| 5981 | // Store the low double into the destination. |
| 5982 | __ movsd(stack, reg); |
| 5983 | |
| 5984 | // Move the high double to the low double. |
| 5985 | __ psrldq(reg, Immediate(8)); |
| 5986 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5987 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5988 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5989 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5990 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5991 | } |
| 5992 | } |
| 5993 | |
| 5994 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5995 | __ pushl(static_cast<Register>(reg)); |
| 5996 | } |
| 5997 | |
| 5998 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5999 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6000 | } |
| 6001 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6002 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6003 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6004 | switch (desired_class_load_kind) { |
| 6005 | case HLoadClass::LoadKind::kReferrersClass: |
| 6006 | break; |
| 6007 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6008 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6009 | break; |
| 6010 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6011 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6012 | FALLTHROUGH_INTENDED; |
| 6013 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 6014 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
| 6015 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6016 | // is incompatible with it. |
| 6017 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6018 | // with irreducible loops. |
| 6019 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6020 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 6021 | } |
| 6022 | break; |
| 6023 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6024 | break; |
| 6025 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 6026 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6027 | break; |
| 6028 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6029 | break; |
| 6030 | } |
| 6031 | return desired_class_load_kind; |
| 6032 | } |
| 6033 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6034 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6035 | if (cls->NeedsAccessCheck()) { |
| 6036 | InvokeRuntimeCallingConvention calling_convention; |
| 6037 | CodeGenerator::CreateLoadClassLocationSummary( |
| 6038 | cls, |
| 6039 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 6040 | Location::RegisterLocation(EAX), |
| 6041 | /* code_generator_supports_read_barrier */ true); |
| 6042 | return; |
| 6043 | } |
| 6044 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6045 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6046 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6047 | ? LocationSummary::kCallOnSlowPath |
| 6048 | : LocationSummary::kNoCall; |
| 6049 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6050 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6051 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6052 | } |
| 6053 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6054 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6055 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 6056 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 6057 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 6058 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 6059 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6060 | } |
| 6061 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6065 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6066 | if (cls->NeedsAccessCheck()) { |
| 6067 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6068 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6069 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6070 | return; |
| 6071 | } |
| 6072 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6073 | Location out_loc = locations->Out(); |
| 6074 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6075 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6076 | bool generate_null_check = false; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6077 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6078 | switch (cls->GetLoadKind()) { |
| 6079 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6080 | DCHECK(!cls->CanCallRuntime()); |
| 6081 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6082 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6083 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6084 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6085 | cls, |
| 6086 | out_loc, |
| 6087 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6088 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6089 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6090 | break; |
| 6091 | } |
| 6092 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6093 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6094 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6095 | codegen_->RecordTypePatch(cls); |
| 6096 | break; |
| 6097 | } |
| 6098 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6099 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6100 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6101 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6102 | codegen_->RecordTypePatch(cls); |
| 6103 | break; |
| 6104 | } |
| 6105 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6106 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6107 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6108 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6109 | __ movl(out, Immediate(address)); |
| 6110 | codegen_->RecordSimplePatch(); |
| 6111 | break; |
| 6112 | } |
| 6113 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 6114 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6115 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6116 | // /* GcRoot<mirror::Class> */ out = *address |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6117 | GenerateGcRootFieldLoad(cls, |
| 6118 | out_loc, |
| 6119 | Address::Absolute(address), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6120 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6121 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6122 | generate_null_check = !cls->IsInDexCache(); |
| 6123 | break; |
| 6124 | } |
| 6125 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 6126 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6127 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 6128 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 6129 | // /* GcRoot<mirror::Class> */ out = *(base + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6130 | GenerateGcRootFieldLoad(cls, |
| 6131 | out_loc, |
| 6132 | Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), |
| 6133 | fixup_label, |
| 6134 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6135 | generate_null_check = !cls->IsInDexCache(); |
| 6136 | break; |
| 6137 | } |
| 6138 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 6139 | // /* GcRoot<mirror::Class>[] */ out = |
| 6140 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 6141 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6142 | __ movl(out, Address(current_method, |
| 6143 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 6144 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6145 | GenerateGcRootFieldLoad(cls, |
| 6146 | out_loc, |
| 6147 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6148 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6149 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6150 | generate_null_check = !cls->IsInDexCache(); |
| 6151 | break; |
| 6152 | } |
| 6153 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6154 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6155 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6156 | DCHECK(cls->CanCallRuntime()); |
| 6157 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6158 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6159 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6160 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6161 | if (generate_null_check) { |
| 6162 | __ testl(out, out); |
| 6163 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6164 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6165 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6166 | if (cls->MustGenerateClinitCheck()) { |
| 6167 | GenerateClassInitializationCheck(slow_path, out); |
| 6168 | } else { |
| 6169 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6170 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6171 | } |
| 6172 | } |
| 6173 | |
| 6174 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6175 | LocationSummary* locations = |
| 6176 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6177 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6178 | if (check->HasUses()) { |
| 6179 | locations->SetOut(Location::SameAsFirstInput()); |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6184 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6185 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6186 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6187 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6188 | GenerateClassInitializationCheck(slow_path, |
| 6189 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6190 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6191 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6192 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6193 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6194 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6195 | Immediate(mirror::Class::kStatusInitialized)); |
| 6196 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6197 | __ Bind(slow_path->GetExitLabel()); |
| 6198 | // No need for memory fence, thanks to the X86 memory model. |
| 6199 | } |
| 6200 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6201 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6202 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6203 | switch (desired_string_load_kind) { |
| 6204 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6205 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6206 | break; |
| 6207 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6208 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6209 | FALLTHROUGH_INTENDED; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6210 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6211 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6212 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6213 | // is incompatible with it. |
| 6214 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6215 | // with irreducible loops. |
| 6216 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6217 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6218 | } |
| 6219 | break; |
| 6220 | case HLoadString::LoadKind::kBootImageAddress: |
| 6221 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6222 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6223 | break; |
Nicolas Geoffray | ac3ebc3 | 2016-10-05 13:13:50 +0100 | [diff] [blame] | 6224 | case HLoadString::LoadKind::kJitTableAddress: |
| 6225 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Nicolas Geoffray | 997d121 | 2016-11-09 10:36:29 +0000 | [diff] [blame] | 6226 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6227 | } |
| 6228 | return desired_string_load_kind; |
| 6229 | } |
| 6230 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6231 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6232 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6233 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 6234 | ? LocationSummary::kCallOnMainOnly |
| 6235 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6236 | : LocationSummary::kNoCall; |
| 6237 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6238 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6239 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6240 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6241 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6242 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6243 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 6244 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6245 | } else { |
| 6246 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6247 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6248 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6249 | // Rely on the pResolveString and/or marking to save everything. |
| 6250 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6251 | InvokeRuntimeCallingConvention calling_convention; |
| 6252 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6253 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6254 | } else { |
| 6255 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6256 | } |
| 6257 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6258 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6259 | } |
| 6260 | |
Nicolas Geoffray | 997d121 | 2016-11-09 10:36:29 +0000 | [diff] [blame] | 6261 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, uint32_t dex_index) { |
| 6262 | jit_string_roots_.Overwrite(StringReference(&dex_file, dex_index), /* placeholder */ 0u); |
| 6263 | // Add a patch entry and return the label. |
| 6264 | jit_string_patches_.emplace_back(dex_file, dex_index); |
| 6265 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6266 | return &info->label; |
| 6267 | } |
| 6268 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6269 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6270 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6271 | Location out_loc = locations->Out(); |
| 6272 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6273 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6274 | switch (load->GetLoadKind()) { |
| 6275 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6276 | __ movl(out, Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6277 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6278 | return; // No dex cache slow path. |
| 6279 | } |
| 6280 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6281 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6282 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6283 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6284 | return; // No dex cache slow path. |
| 6285 | } |
| 6286 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6287 | DCHECK_NE(load->GetAddress(), 0u); |
| 6288 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6289 | __ movl(out, Immediate(address)); |
| 6290 | codegen_->RecordSimplePatch(); |
| 6291 | return; // No dex cache slow path. |
| 6292 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6293 | case HLoadString::LoadKind::kBssEntry: { |
| 6294 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6295 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6296 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 997d121 | 2016-11-09 10:36:29 +0000 | [diff] [blame] | 6297 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6298 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kEmitCompilerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6299 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6300 | codegen_->AddSlowPath(slow_path); |
| 6301 | __ testl(out, out); |
| 6302 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6303 | __ Bind(slow_path->GetExitLabel()); |
| 6304 | return; |
| 6305 | } |
Nicolas Geoffray | 997d121 | 2016-11-09 10:36:29 +0000 | [diff] [blame] | 6306 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6307 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6308 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 6309 | load->GetDexFile(), load->GetStringIndex()); |
| 6310 | // /* GcRoot<mirror::String> */ out = *address |
| 6311 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kEmitCompilerReadBarrier); |
| 6312 | return; |
| 6313 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6314 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6315 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6316 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6317 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6318 | // 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] | 6319 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6320 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6321 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex())); |
| 6322 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6323 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6324 | } |
| 6325 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6326 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6327 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6328 | } |
| 6329 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6330 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6331 | LocationSummary* locations = |
| 6332 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6333 | locations->SetOut(Location::RequiresRegister()); |
| 6334 | } |
| 6335 | |
| 6336 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6337 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6338 | } |
| 6339 | |
| 6340 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6341 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6342 | } |
| 6343 | |
| 6344 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6345 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6349 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6350 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6351 | InvokeRuntimeCallingConvention calling_convention; |
| 6352 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6353 | } |
| 6354 | |
| 6355 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6356 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6357 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6358 | } |
| 6359 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6360 | // Temp is used for read barrier. |
| 6361 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6362 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6363 | !kUseBakerReadBarrier && |
| 6364 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6365 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6366 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6367 | return 1; |
| 6368 | } |
| 6369 | return 0; |
| 6370 | } |
| 6371 | |
| 6372 | // InteraceCheck has 3 temps, one for holding the number of interfaces, one for the current |
| 6373 | // interface pointer, one for loading the current interface. |
| 6374 | // The other checks have one temp for loading the object's class. |
| 6375 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6376 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6377 | return 2; |
| 6378 | } |
| 6379 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6382 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6383 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6384 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6385 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6386 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6387 | case TypeCheckKind::kExactCheck: |
| 6388 | case TypeCheckKind::kAbstractClassCheck: |
| 6389 | case TypeCheckKind::kClassHierarchyCheck: |
| 6390 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6391 | call_kind = |
| 6392 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6393 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6394 | break; |
| 6395 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6396 | case TypeCheckKind::kUnresolvedCheck: |
| 6397 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6398 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6399 | break; |
| 6400 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6401 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6402 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6403 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6404 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6405 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6406 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6407 | locations->SetInAt(1, Location::Any()); |
| 6408 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6409 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6410 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6411 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6412 | } |
| 6413 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6414 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6415 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6416 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6417 | Location obj_loc = locations->InAt(0); |
| 6418 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6419 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6420 | Location out_loc = locations->Out(); |
| 6421 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6422 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6423 | DCHECK_LE(num_temps, 1u); |
| 6424 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6425 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6426 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6427 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6428 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6429 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6430 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6431 | |
| 6432 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6433 | // Avoid null check if we know obj is not null. |
| 6434 | if (instruction->MustDoNullCheck()) { |
| 6435 | __ testl(obj, obj); |
| 6436 | __ j(kEqual, &zero); |
| 6437 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6438 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6439 | // /* HeapReference<Class> */ out = obj->klass_ |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6440 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6441 | out_loc, |
| 6442 | obj_loc, |
| 6443 | class_offset, |
| 6444 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6445 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6446 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6447 | case TypeCheckKind::kExactCheck: { |
| 6448 | if (cls.IsRegister()) { |
| 6449 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6450 | } else { |
| 6451 | DCHECK(cls.IsStackSlot()) << cls; |
| 6452 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6453 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6454 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6455 | // Classes must be equal for the instanceof to succeed. |
| 6456 | __ j(kNotEqual, &zero); |
| 6457 | __ movl(out, Immediate(1)); |
| 6458 | __ jmp(&done); |
| 6459 | break; |
| 6460 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6461 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6462 | case TypeCheckKind::kAbstractClassCheck: { |
| 6463 | // If the class is abstract, we eagerly fetch the super class of the |
| 6464 | // object to avoid doing a comparison we know will fail. |
| 6465 | NearLabel loop; |
| 6466 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6467 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6468 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6469 | __ testl(out, out); |
| 6470 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6471 | __ j(kEqual, &done); |
| 6472 | if (cls.IsRegister()) { |
| 6473 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6474 | } else { |
| 6475 | DCHECK(cls.IsStackSlot()) << cls; |
| 6476 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6477 | } |
| 6478 | __ j(kNotEqual, &loop); |
| 6479 | __ movl(out, Immediate(1)); |
| 6480 | if (zero.IsLinked()) { |
| 6481 | __ jmp(&done); |
| 6482 | } |
| 6483 | break; |
| 6484 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6485 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6486 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6487 | // Walk over the class hierarchy to find a match. |
| 6488 | NearLabel loop, success; |
| 6489 | __ Bind(&loop); |
| 6490 | if (cls.IsRegister()) { |
| 6491 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6492 | } else { |
| 6493 | DCHECK(cls.IsStackSlot()) << cls; |
| 6494 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6495 | } |
| 6496 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6497 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6498 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6499 | __ testl(out, out); |
| 6500 | __ j(kNotEqual, &loop); |
| 6501 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6502 | __ jmp(&done); |
| 6503 | __ Bind(&success); |
| 6504 | __ movl(out, Immediate(1)); |
| 6505 | if (zero.IsLinked()) { |
| 6506 | __ jmp(&done); |
| 6507 | } |
| 6508 | break; |
| 6509 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6510 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6511 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6512 | // Do an exact check. |
| 6513 | NearLabel exact_check; |
| 6514 | if (cls.IsRegister()) { |
| 6515 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6516 | } else { |
| 6517 | DCHECK(cls.IsStackSlot()) << cls; |
| 6518 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6519 | } |
| 6520 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6521 | // 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] | 6522 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6523 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6524 | __ testl(out, out); |
| 6525 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6526 | __ j(kEqual, &done); |
| 6527 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6528 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6529 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6530 | __ movl(out, Immediate(1)); |
| 6531 | __ jmp(&done); |
| 6532 | break; |
| 6533 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6534 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6535 | case TypeCheckKind::kArrayCheck: { |
| 6536 | if (cls.IsRegister()) { |
| 6537 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6538 | } else { |
| 6539 | DCHECK(cls.IsStackSlot()) << cls; |
| 6540 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6541 | } |
| 6542 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6543 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6544 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6545 | codegen_->AddSlowPath(slow_path); |
| 6546 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6547 | __ movl(out, Immediate(1)); |
| 6548 | if (zero.IsLinked()) { |
| 6549 | __ jmp(&done); |
| 6550 | } |
| 6551 | break; |
| 6552 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6553 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6554 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6555 | case TypeCheckKind::kInterfaceCheck: { |
| 6556 | // 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] | 6557 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6558 | // cases. |
| 6559 | // |
| 6560 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6561 | // entry point without resorting to a type checking slow path |
| 6562 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6563 | // require to assign fixed registers for the inputs of this |
| 6564 | // HInstanceOf instruction (following the runtime calling |
| 6565 | // convention), which might be cluttered by the potential first |
| 6566 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6567 | // |
| 6568 | // TODO: Introduce a new runtime entry point taking the object |
| 6569 | // to test (instead of its class) as argument, and let it deal |
| 6570 | // with the read barrier issues. This will let us refactor this |
| 6571 | // case of the `switch` code as it was previously (with a direct |
| 6572 | // call to the runtime not using a type checking slow path). |
| 6573 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6574 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6575 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6576 | /* is_fatal */ false); |
| 6577 | codegen_->AddSlowPath(slow_path); |
| 6578 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6579 | if (zero.IsLinked()) { |
| 6580 | __ jmp(&done); |
| 6581 | } |
| 6582 | break; |
| 6583 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6584 | } |
| 6585 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6586 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6587 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6588 | __ xorl(out, out); |
| 6589 | } |
| 6590 | |
| 6591 | if (done.IsLinked()) { |
| 6592 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6593 | } |
| 6594 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6595 | if (slow_path != nullptr) { |
| 6596 | __ Bind(slow_path->GetExitLabel()); |
| 6597 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6598 | } |
| 6599 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6600 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6601 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6602 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6603 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6604 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6605 | case TypeCheckKind::kExactCheck: |
| 6606 | case TypeCheckKind::kAbstractClassCheck: |
| 6607 | case TypeCheckKind::kClassHierarchyCheck: |
| 6608 | case TypeCheckKind::kArrayObjectCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6609 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6610 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6611 | LocationSummary::kCallOnSlowPath : |
| 6612 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6613 | break; |
| 6614 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6615 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6616 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6617 | break; |
| 6618 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6619 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6620 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6621 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6622 | // Require a register for the interface check since there is a loop that compares the class to |
| 6623 | // a memory address. |
| 6624 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6625 | } else { |
| 6626 | locations->SetInAt(1, Location::Any()); |
| 6627 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6628 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6629 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6630 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6631 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6632 | } |
| 6633 | |
| 6634 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6635 | switch (type_check_kind) { |
| 6636 | case TypeCheckKind::kExactCheck: |
| 6637 | case TypeCheckKind::kAbstractClassCheck: |
| 6638 | case TypeCheckKind::kClassHierarchyCheck: |
| 6639 | case TypeCheckKind::kArrayObjectCheck: |
| 6640 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6641 | case TypeCheckKind::kInterfaceCheck: |
| 6642 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6643 | case TypeCheckKind::kArrayCheck: |
| 6644 | case TypeCheckKind::kUnresolvedCheck: |
| 6645 | return false; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6646 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6647 | LOG(FATAL) << "Unreachable"; |
| 6648 | UNREACHABLE(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6649 | } |
| 6650 | |
| 6651 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6652 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6653 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6654 | Location obj_loc = locations->InAt(0); |
| 6655 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6656 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6657 | Location temp_loc = locations->GetTemp(0); |
| 6658 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6659 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6660 | DCHECK_GE(num_temps, 1u); |
| 6661 | DCHECK_LE(num_temps, 2u); |
| 6662 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6663 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6664 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6665 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6666 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6667 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6668 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6669 | const uint32_t object_array_data_offset = |
| 6670 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
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 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6673 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6674 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6675 | SlowPathCode* type_check_slow_path = |
| 6676 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6677 | is_type_check_slow_path_fatal); |
| 6678 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6679 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6680 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6681 | // Avoid null check if we know obj is not null. |
| 6682 | if (instruction->MustDoNullCheck()) { |
| 6683 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6684 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6685 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6686 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6687 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6688 | case TypeCheckKind::kExactCheck: |
| 6689 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6690 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6691 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6692 | temp_loc, |
| 6693 | obj_loc, |
| 6694 | class_offset, |
| 6695 | kEmitCompilerReadBarrier); |
| 6696 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6697 | if (cls.IsRegister()) { |
| 6698 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6699 | } else { |
| 6700 | DCHECK(cls.IsStackSlot()) << cls; |
| 6701 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6702 | } |
| 6703 | // Jump to slow path for throwing the exception or doing a |
| 6704 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6706 | break; |
| 6707 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6708 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6709 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6710 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6711 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6712 | temp_loc, |
| 6713 | obj_loc, |
| 6714 | class_offset, |
| 6715 | kEmitCompilerReadBarrier); |
| 6716 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6717 | // If the class is abstract, we eagerly fetch the super class of the |
| 6718 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6719 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6720 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6721 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6722 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6723 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6724 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6725 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6726 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6727 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6728 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6729 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6730 | if (cls.IsRegister()) { |
| 6731 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6732 | } else { |
| 6733 | DCHECK(cls.IsStackSlot()) << cls; |
| 6734 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6735 | } |
| 6736 | __ j(kNotEqual, &loop); |
| 6737 | break; |
| 6738 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6739 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6740 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6741 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6742 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6743 | temp_loc, |
| 6744 | obj_loc, |
| 6745 | class_offset, |
| 6746 | kEmitCompilerReadBarrier); |
| 6747 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6748 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6749 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6750 | __ Bind(&loop); |
| 6751 | if (cls.IsRegister()) { |
| 6752 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6753 | } else { |
| 6754 | DCHECK(cls.IsStackSlot()) << cls; |
| 6755 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6756 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6757 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6758 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6759 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6760 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
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, |
| 6777 | kEmitCompilerReadBarrier); |
| 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_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6790 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6791 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6792 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6793 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6794 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6795 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6796 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6797 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6798 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6799 | break; |
| 6800 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6801 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6802 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6803 | // 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] | 6804 | // We cannot directly call the CheckCast runtime entry point |
| 6805 | // without resorting to a type checking slow path here (i.e. by |
| 6806 | // calling InvokeRuntime directly), as it would require to |
| 6807 | // assign fixed registers for the inputs of this HInstanceOf |
| 6808 | // instruction (following the runtime calling convention), which |
| 6809 | // might be cluttered by the potential first read barrier |
| 6810 | // emission at the beginning of this method. |
| 6811 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6812 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6813 | |
| 6814 | case TypeCheckKind::kInterfaceCheck: { |
| 6815 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6816 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6817 | // conditional flags and cause the conditional jump to be incorrect. Therefore we just jump |
| 6818 | // to the slow path if we are running under poisoning |
| 6819 | if (!kPoisonHeapReferences) { |
| 6820 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6821 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6822 | temp_loc, |
| 6823 | obj_loc, |
| 6824 | class_offset, |
| 6825 | /*emit_read_barrier*/ false); |
| 6826 | |
| 6827 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6828 | // doing this. |
| 6829 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6830 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6831 | temp_loc, |
| 6832 | obj_loc, |
| 6833 | class_offset, |
| 6834 | /*emit_read_barrier*/ false); |
| 6835 | |
| 6836 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6837 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6838 | temp_loc, |
| 6839 | temp_loc, |
| 6840 | iftable_offset, |
| 6841 | /*emit_read_barrier*/ false); |
| 6842 | NearLabel is_null; |
| 6843 | // Null iftable means it is empty. |
| 6844 | __ testl(temp, temp); |
| 6845 | __ j(kZero, &is_null); |
| 6846 | |
| 6847 | // Loop through the iftable and check if any class matches. |
| 6848 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 6849 | |
| 6850 | NearLabel start_loop; |
| 6851 | __ Bind(&start_loop); |
| 6852 | __ cmpl(cls.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 6853 | __ j(kEqual, &done); // Return if same class. |
| 6854 | // Go to next interface. |
| 6855 | __ addl(temp, Immediate(2 * kHeapReferenceSize)); |
| 6856 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 6857 | __ j(kNotZero, &start_loop); |
| 6858 | __ Bind(&is_null); |
| 6859 | } |
| 6860 | |
| 6861 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6862 | break; |
| 6863 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6864 | } |
| 6865 | __ Bind(&done); |
| 6866 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6867 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6868 | } |
| 6869 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6870 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6871 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6872 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6873 | InvokeRuntimeCallingConvention calling_convention; |
| 6874 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6875 | } |
| 6876 | |
| 6877 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6878 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6879 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6880 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6881 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6882 | if (instruction->IsEnter()) { |
| 6883 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6884 | } else { |
| 6885 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6886 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6887 | } |
| 6888 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6889 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6890 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6891 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6892 | |
| 6893 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6894 | LocationSummary* locations = |
| 6895 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6896 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6897 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6898 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6899 | locations->SetInAt(1, Location::Any()); |
| 6900 | locations->SetOut(Location::SameAsFirstInput()); |
| 6901 | } |
| 6902 | |
| 6903 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6904 | HandleBitwiseOperation(instruction); |
| 6905 | } |
| 6906 | |
| 6907 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6908 | HandleBitwiseOperation(instruction); |
| 6909 | } |
| 6910 | |
| 6911 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6912 | HandleBitwiseOperation(instruction); |
| 6913 | } |
| 6914 | |
| 6915 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6916 | LocationSummary* locations = instruction->GetLocations(); |
| 6917 | Location first = locations->InAt(0); |
| 6918 | Location second = locations->InAt(1); |
| 6919 | DCHECK(first.Equals(locations->Out())); |
| 6920 | |
| 6921 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6922 | if (second.IsRegister()) { |
| 6923 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6924 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6925 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6926 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6927 | } else { |
| 6928 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6929 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6930 | } |
| 6931 | } else if (second.IsConstant()) { |
| 6932 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6933 | __ andl(first.AsRegister<Register>(), |
| 6934 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6935 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6936 | __ orl(first.AsRegister<Register>(), |
| 6937 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6938 | } else { |
| 6939 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6940 | __ xorl(first.AsRegister<Register>(), |
| 6941 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6942 | } |
| 6943 | } else { |
| 6944 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6945 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6946 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6947 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6948 | } else { |
| 6949 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6950 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6951 | } |
| 6952 | } |
| 6953 | } else { |
| 6954 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6955 | if (second.IsRegisterPair()) { |
| 6956 | if (instruction->IsAnd()) { |
| 6957 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6958 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6959 | } else if (instruction->IsOr()) { |
| 6960 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6961 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6962 | } else { |
| 6963 | DCHECK(instruction->IsXor()); |
| 6964 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6965 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6966 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6967 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6968 | if (instruction->IsAnd()) { |
| 6969 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6970 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6971 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6972 | } else if (instruction->IsOr()) { |
| 6973 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6974 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6975 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6976 | } else { |
| 6977 | DCHECK(instruction->IsXor()); |
| 6978 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6979 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6980 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6981 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6982 | } else { |
| 6983 | DCHECK(second.IsConstant()) << second; |
| 6984 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6985 | int32_t low_value = Low32Bits(value); |
| 6986 | int32_t high_value = High32Bits(value); |
| 6987 | Immediate low(low_value); |
| 6988 | Immediate high(high_value); |
| 6989 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6990 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6991 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6992 | if (low_value == 0) { |
| 6993 | __ xorl(first_low, first_low); |
| 6994 | } else if (low_value != -1) { |
| 6995 | __ andl(first_low, low); |
| 6996 | } |
| 6997 | if (high_value == 0) { |
| 6998 | __ xorl(first_high, first_high); |
| 6999 | } else if (high_value != -1) { |
| 7000 | __ andl(first_high, high); |
| 7001 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7002 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7003 | if (low_value != 0) { |
| 7004 | __ orl(first_low, low); |
| 7005 | } |
| 7006 | if (high_value != 0) { |
| 7007 | __ orl(first_high, high); |
| 7008 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7009 | } else { |
| 7010 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7011 | if (low_value != 0) { |
| 7012 | __ xorl(first_low, low); |
| 7013 | } |
| 7014 | if (high_value != 0) { |
| 7015 | __ xorl(first_high, high); |
| 7016 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7017 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7018 | } |
| 7019 | } |
| 7020 | } |
| 7021 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7022 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 7023 | Location out, |
| 7024 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7025 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7026 | Register out_reg = out.AsRegister<Register>(); |
| 7027 | if (kEmitCompilerReadBarrier) { |
| 7028 | if (kUseBakerReadBarrier) { |
| 7029 | // Load with fast path based Baker's read barrier. |
| 7030 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7031 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7032 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7033 | } else { |
| 7034 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7035 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7036 | // in the following move operation, as we will need it for the |
| 7037 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7038 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7039 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7040 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7041 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7042 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7043 | } |
| 7044 | } else { |
| 7045 | // Plain load with no read barrier. |
| 7046 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7047 | __ movl(out_reg, Address(out_reg, offset)); |
| 7048 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7049 | } |
| 7050 | } |
| 7051 | |
| 7052 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 7053 | Location out, |
| 7054 | Location obj, |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 7055 | uint32_t offset, |
| 7056 | bool emit_read_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7057 | Register out_reg = out.AsRegister<Register>(); |
| 7058 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 7059 | if (emit_read_barrier) { |
| 7060 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7061 | if (kUseBakerReadBarrier) { |
| 7062 | // Load with fast path based Baker's read barrier. |
| 7063 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7064 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7065 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7066 | } else { |
| 7067 | // Load with slow path based read barrier. |
| 7068 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7069 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7070 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7071 | } |
| 7072 | } else { |
| 7073 | // Plain load with no read barrier. |
| 7074 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7075 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7076 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7077 | } |
| 7078 | } |
| 7079 | |
| 7080 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 7081 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7082 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7083 | Label* fixup_label, |
| 7084 | bool requires_read_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7085 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7086 | if (requires_read_barrier) { |
| 7087 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7088 | if (kUseBakerReadBarrier) { |
| 7089 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7090 | // Baker's read barrier are used: |
| 7091 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7092 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7093 | // if (Thread::Current()->GetIsGcMarking()) { |
| 7094 | // root = ReadBarrier::Mark(root) |
| 7095 | // } |
| 7096 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7097 | // /* GcRoot<mirror::Object> */ root = *address |
| 7098 | __ movl(root_reg, address); |
| 7099 | if (fixup_label != nullptr) { |
| 7100 | __ Bind(fixup_label); |
| 7101 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7102 | static_assert( |
| 7103 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7104 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7105 | "have different sizes."); |
| 7106 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7107 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7108 | "have different sizes."); |
| 7109 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7110 | // Slow path marking the GC root `root`. |
| 7111 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7112 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7113 | codegen_->AddSlowPath(slow_path); |
| 7114 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7115 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7116 | Immediate(0)); |
| 7117 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7118 | __ Bind(slow_path->GetExitLabel()); |
| 7119 | } else { |
| 7120 | // GC root loaded through a slow path for read barriers other |
| 7121 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7122 | // /* GcRoot<mirror::Object>* */ root = address |
| 7123 | __ leal(root_reg, address); |
| 7124 | if (fixup_label != nullptr) { |
| 7125 | __ Bind(fixup_label); |
| 7126 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7127 | // /* mirror::Object* */ root = root->Read() |
| 7128 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7129 | } |
| 7130 | } else { |
| 7131 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7132 | // /* GcRoot<mirror::Object> */ root = *address |
| 7133 | __ movl(root_reg, address); |
| 7134 | if (fixup_label != nullptr) { |
| 7135 | __ Bind(fixup_label); |
| 7136 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7137 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7138 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7139 | } |
| 7140 | } |
| 7141 | |
| 7142 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7143 | Location ref, |
| 7144 | Register obj, |
| 7145 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7146 | bool needs_null_check) { |
| 7147 | DCHECK(kEmitCompilerReadBarrier); |
| 7148 | DCHECK(kUseBakerReadBarrier); |
| 7149 | |
| 7150 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7151 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7152 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7153 | } |
| 7154 | |
| 7155 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7156 | Location ref, |
| 7157 | Register obj, |
| 7158 | uint32_t data_offset, |
| 7159 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7160 | bool needs_null_check) { |
| 7161 | DCHECK(kEmitCompilerReadBarrier); |
| 7162 | DCHECK(kUseBakerReadBarrier); |
| 7163 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7164 | static_assert( |
| 7165 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7166 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7167 | // /* HeapReference<Object> */ ref = |
| 7168 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7169 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7170 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7171 | } |
| 7172 | |
| 7173 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7174 | Location ref, |
| 7175 | Register obj, |
| 7176 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7177 | bool needs_null_check, |
| 7178 | bool always_update_field, |
| 7179 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7180 | DCHECK(kEmitCompilerReadBarrier); |
| 7181 | DCHECK(kUseBakerReadBarrier); |
| 7182 | |
| 7183 | // In slow path based read barriers, the read barrier call is |
| 7184 | // inserted after the original load. However, in fast path based |
| 7185 | // Baker's read barriers, we need to perform the load of |
| 7186 | // mirror::Object::monitor_ *before* the original reference load. |
| 7187 | // This load-load ordering is required by the read barrier. |
| 7188 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7189 | // |
| 7190 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7191 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7192 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7193 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7194 | // if (is_gray) { |
| 7195 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7196 | // } |
| 7197 | // |
| 7198 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7199 | // slightly more complex as: |
| 7200 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7201 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7202 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7203 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7204 | // - it performs additional checks that we do not do here for |
| 7205 | // performance reasons. |
| 7206 | |
| 7207 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7208 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7209 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7210 | // 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] | 7211 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7212 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7213 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7214 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7215 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7216 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7217 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7218 | // ref = ReadBarrier::Mark(ref); |
| 7219 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7220 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7221 | if (needs_null_check) { |
| 7222 | MaybeRecordImplicitNullCheck(instruction); |
| 7223 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7224 | |
| 7225 | // Load fence to prevent load-load reordering. |
| 7226 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7227 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7228 | |
| 7229 | // The actual reference load. |
| 7230 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7231 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7232 | |
| 7233 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7234 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7235 | SlowPathCode* slow_path; |
| 7236 | if (always_update_field) { |
| 7237 | DCHECK(temp != nullptr); |
| 7238 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| 7239 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7240 | } else { |
| 7241 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 7242 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7243 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7244 | AddSlowPath(slow_path); |
| 7245 | |
| 7246 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7247 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7248 | |
| 7249 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7250 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7251 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7252 | __ Bind(slow_path->GetExitLabel()); |
| 7253 | } |
| 7254 | |
| 7255 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7256 | Location out, |
| 7257 | Location ref, |
| 7258 | Location obj, |
| 7259 | uint32_t offset, |
| 7260 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7261 | DCHECK(kEmitCompilerReadBarrier); |
| 7262 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7263 | // Insert a slow path based read barrier *after* the reference load. |
| 7264 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7265 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7266 | // reference will be carried out by the runtime within the slow |
| 7267 | // path. |
| 7268 | // |
| 7269 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7270 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7271 | // not used by the artReadBarrierSlow entry point. |
| 7272 | // |
| 7273 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7274 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7275 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7276 | AddSlowPath(slow_path); |
| 7277 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7278 | __ jmp(slow_path->GetEntryLabel()); |
| 7279 | __ Bind(slow_path->GetExitLabel()); |
| 7280 | } |
| 7281 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7282 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7283 | Location out, |
| 7284 | Location ref, |
| 7285 | Location obj, |
| 7286 | uint32_t offset, |
| 7287 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7288 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7289 | // Baker's read barriers shall be handled by the fast path |
| 7290 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7291 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7292 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7293 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7294 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7295 | } else if (kPoisonHeapReferences) { |
| 7296 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7297 | } |
| 7298 | } |
| 7299 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7300 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7301 | Location out, |
| 7302 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7303 | DCHECK(kEmitCompilerReadBarrier); |
| 7304 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7305 | // Insert a slow path based read barrier *after* the GC root load. |
| 7306 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7307 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7308 | // not need to do anything special for this here. |
| 7309 | SlowPathCode* slow_path = |
| 7310 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7311 | AddSlowPath(slow_path); |
| 7312 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7313 | __ jmp(slow_path->GetEntryLabel()); |
| 7314 | __ Bind(slow_path->GetExitLabel()); |
| 7315 | } |
| 7316 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7317 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7318 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7319 | LOG(FATAL) << "Unreachable"; |
| 7320 | } |
| 7321 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7322 | void InstructionCodeGeneratorX86::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 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7327 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7328 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7329 | LocationSummary* locations = |
| 7330 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7331 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7332 | } |
| 7333 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7334 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7335 | int32_t lower_bound, |
| 7336 | uint32_t num_entries, |
| 7337 | HBasicBlock* switch_block, |
| 7338 | HBasicBlock* default_block) { |
| 7339 | // Figure out the correct compare values and jump conditions. |
| 7340 | // Handle the first compare/branch as a special case because it might |
| 7341 | // jump to the default case. |
| 7342 | DCHECK_GT(num_entries, 2u); |
| 7343 | Condition first_condition; |
| 7344 | uint32_t index; |
| 7345 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7346 | if (lower_bound != 0) { |
| 7347 | first_condition = kLess; |
| 7348 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7349 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7350 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7351 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7352 | index = 1; |
| 7353 | } else { |
| 7354 | // Handle all the compare/jumps below. |
| 7355 | first_condition = kBelow; |
| 7356 | index = 0; |
| 7357 | } |
| 7358 | |
| 7359 | // Handle the rest of the compare/jumps. |
| 7360 | for (; index + 1 < num_entries; index += 2) { |
| 7361 | int32_t compare_to_value = lower_bound + index + 1; |
| 7362 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7363 | // Jump to successors[index] if value < case_value[index]. |
| 7364 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7365 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7366 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7367 | } |
| 7368 | |
| 7369 | if (index != num_entries) { |
| 7370 | // There are an odd number of entries. Handle the last one. |
| 7371 | DCHECK_EQ(index + 1, num_entries); |
| 7372 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7373 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7374 | } |
| 7375 | |
| 7376 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7377 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7378 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7379 | } |
| 7380 | } |
| 7381 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7382 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7383 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7384 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7385 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7386 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7387 | |
| 7388 | GenPackedSwitchWithCompares(value_reg, |
| 7389 | lower_bound, |
| 7390 | num_entries, |
| 7391 | switch_instr->GetBlock(), |
| 7392 | switch_instr->GetDefaultBlock()); |
| 7393 | } |
| 7394 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7395 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7396 | LocationSummary* locations = |
| 7397 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7398 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7399 | |
| 7400 | // Constant area pointer. |
| 7401 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7402 | |
| 7403 | // And the temporary we need. |
| 7404 | locations->AddTemp(Location::RequiresRegister()); |
| 7405 | } |
| 7406 | |
| 7407 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7408 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7409 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7410 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7411 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7412 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7413 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7414 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7415 | GenPackedSwitchWithCompares(value_reg, |
| 7416 | lower_bound, |
| 7417 | num_entries, |
| 7418 | switch_instr->GetBlock(), |
| 7419 | default_block); |
| 7420 | return; |
| 7421 | } |
| 7422 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7423 | // Optimizing has a jump area. |
| 7424 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7425 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7426 | |
| 7427 | // Remove the bias, if needed. |
| 7428 | if (lower_bound != 0) { |
| 7429 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7430 | value_reg = temp_reg; |
| 7431 | } |
| 7432 | |
| 7433 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7434 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7435 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7436 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7437 | |
| 7438 | // We are in the range of the table. |
| 7439 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7440 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7441 | |
| 7442 | // Compute the actual target address by adding in constant_area. |
| 7443 | __ addl(temp_reg, constant_area); |
| 7444 | |
| 7445 | // And jump. |
| 7446 | __ jmp(temp_reg); |
| 7447 | } |
| 7448 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7449 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7450 | HX86ComputeBaseMethodAddress* insn) { |
| 7451 | LocationSummary* locations = |
| 7452 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7453 | locations->SetOut(Location::RequiresRegister()); |
| 7454 | } |
| 7455 | |
| 7456 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7457 | HX86ComputeBaseMethodAddress* insn) { |
| 7458 | LocationSummary* locations = insn->GetLocations(); |
| 7459 | Register reg = locations->Out().AsRegister<Register>(); |
| 7460 | |
| 7461 | // Generate call to next instruction. |
| 7462 | Label next_instruction; |
| 7463 | __ call(&next_instruction); |
| 7464 | __ Bind(&next_instruction); |
| 7465 | |
| 7466 | // Remember this offset for later use with constant area. |
| 7467 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7468 | |
| 7469 | // Grab the return address off the stack. |
| 7470 | __ popl(reg); |
| 7471 | } |
| 7472 | |
| 7473 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7474 | HX86LoadFromConstantTable* insn) { |
| 7475 | LocationSummary* locations = |
| 7476 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7477 | |
| 7478 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7479 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7480 | |
| 7481 | // 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] | 7482 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7483 | return; |
| 7484 | } |
| 7485 | |
| 7486 | switch (insn->GetType()) { |
| 7487 | case Primitive::kPrimFloat: |
| 7488 | case Primitive::kPrimDouble: |
| 7489 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7490 | break; |
| 7491 | |
| 7492 | case Primitive::kPrimInt: |
| 7493 | locations->SetOut(Location::RequiresRegister()); |
| 7494 | break; |
| 7495 | |
| 7496 | default: |
| 7497 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7498 | } |
| 7499 | } |
| 7500 | |
| 7501 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7502 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7503 | return; |
| 7504 | } |
| 7505 | |
| 7506 | LocationSummary* locations = insn->GetLocations(); |
| 7507 | Location out = locations->Out(); |
| 7508 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7509 | HConstant *value = insn->GetConstant(); |
| 7510 | |
| 7511 | switch (insn->GetType()) { |
| 7512 | case Primitive::kPrimFloat: |
| 7513 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7514 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7515 | break; |
| 7516 | |
| 7517 | case Primitive::kPrimDouble: |
| 7518 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7519 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7520 | break; |
| 7521 | |
| 7522 | case Primitive::kPrimInt: |
| 7523 | __ movl(out.AsRegister<Register>(), |
| 7524 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7525 | break; |
| 7526 | |
| 7527 | default: |
| 7528 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7529 | } |
| 7530 | } |
| 7531 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7532 | /** |
| 7533 | * Class to handle late fixup of offsets into constant area. |
| 7534 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7535 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7536 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7537 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7538 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7539 | |
| 7540 | protected: |
| 7541 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7542 | |
| 7543 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7544 | |
| 7545 | private: |
| 7546 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7547 | // Patch the correct offset for the instruction. The place to patch is the |
| 7548 | // last 4 bytes of the instruction. |
| 7549 | // The value to patch is the distance from the offset in the constant area |
| 7550 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7551 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7552 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7553 | |
| 7554 | // Patch in the right value. |
| 7555 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7556 | } |
| 7557 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7558 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7559 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7560 | }; |
| 7561 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7562 | /** |
| 7563 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7564 | * constant area. |
| 7565 | */ |
| 7566 | class JumpTableRIPFixup : public RIPFixup { |
| 7567 | public: |
| 7568 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7569 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7570 | |
| 7571 | void CreateJumpTable() { |
| 7572 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7573 | |
| 7574 | // Ensure that the reference to the jump table has the correct offset. |
| 7575 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7576 | SetOffset(offset_in_constant_table); |
| 7577 | |
| 7578 | // The label values in the jump table are computed relative to the |
| 7579 | // instruction addressing the constant area. |
| 7580 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7581 | |
| 7582 | // Populate the jump table with the correct values for the jump table. |
| 7583 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7584 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7585 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7586 | // The value that we want is the target offset - the position of the table. |
| 7587 | for (int32_t i = 0; i < num_entries; i++) { |
| 7588 | HBasicBlock* b = successors[i]; |
| 7589 | Label* l = codegen_->GetLabelOf(b); |
| 7590 | DCHECK(l->IsBound()); |
| 7591 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7592 | assembler->AppendInt32(offset_to_block); |
| 7593 | } |
| 7594 | } |
| 7595 | |
| 7596 | private: |
| 7597 | const HX86PackedSwitch* switch_instr_; |
| 7598 | }; |
| 7599 | |
| 7600 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7601 | // Generate the constant area if needed. |
| 7602 | X86Assembler* assembler = GetAssembler(); |
| 7603 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7604 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7605 | // byte values. |
| 7606 | assembler->Align(4, 0); |
| 7607 | constant_area_start_ = assembler->CodeSize(); |
| 7608 | |
| 7609 | // Populate any jump tables. |
| 7610 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7611 | jump_table->CreateJumpTable(); |
| 7612 | } |
| 7613 | |
| 7614 | // And now add the constant area to the generated code. |
| 7615 | assembler->AddConstantArea(); |
| 7616 | } |
| 7617 | |
| 7618 | // And finish up. |
| 7619 | CodeGenerator::Finalize(allocator); |
| 7620 | } |
| 7621 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7622 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7623 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7624 | return Address(reg, kDummy32BitOffset, fixup); |
| 7625 | } |
| 7626 | |
| 7627 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7628 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7629 | return Address(reg, kDummy32BitOffset, fixup); |
| 7630 | } |
| 7631 | |
| 7632 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7633 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7634 | return Address(reg, kDummy32BitOffset, fixup); |
| 7635 | } |
| 7636 | |
| 7637 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7638 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7639 | return Address(reg, kDummy32BitOffset, fixup); |
| 7640 | } |
| 7641 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7642 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7643 | if (value == 0) { |
| 7644 | __ xorl(dest, dest); |
| 7645 | } else { |
| 7646 | __ movl(dest, Immediate(value)); |
| 7647 | } |
| 7648 | } |
| 7649 | |
| 7650 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7651 | if (value == 0) { |
| 7652 | __ testl(dest, dest); |
| 7653 | } else { |
| 7654 | __ cmpl(dest, Immediate(value)); |
| 7655 | } |
| 7656 | } |
| 7657 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7658 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7659 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7660 | GenerateIntCompare(lhs_reg, rhs); |
| 7661 | } |
| 7662 | |
| 7663 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7664 | if (rhs.IsConstant()) { |
| 7665 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7666 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7667 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7668 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7669 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7670 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7671 | } |
| 7672 | } |
| 7673 | |
| 7674 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7675 | Location index, |
| 7676 | ScaleFactor scale, |
| 7677 | uint32_t data_offset) { |
| 7678 | return index.IsConstant() ? |
| 7679 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7680 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7681 | } |
| 7682 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7683 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7684 | Register reg, |
| 7685 | Register value) { |
| 7686 | // Create a fixup to be used to create and address the jump table. |
| 7687 | JumpTableRIPFixup* table_fixup = |
| 7688 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7689 | |
| 7690 | // We have to populate the jump tables. |
| 7691 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7692 | |
| 7693 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7694 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7695 | } |
| 7696 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7697 | // TODO: target as memory. |
| 7698 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7699 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7700 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7701 | return; |
| 7702 | } |
| 7703 | |
| 7704 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7705 | |
| 7706 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7707 | if (target.Equals(return_loc)) { |
| 7708 | return; |
| 7709 | } |
| 7710 | |
| 7711 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7712 | // with the else branch. |
| 7713 | if (type == Primitive::kPrimLong) { |
| 7714 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7715 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7716 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7717 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7718 | } else { |
| 7719 | // Let the parallel move resolver take care of all of this. |
| 7720 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7721 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7722 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7723 | } |
| 7724 | } |
| 7725 | |
Nicolas Geoffray | 997d121 | 2016-11-09 10:36:29 +0000 | [diff] [blame] | 7726 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7727 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| 7728 | const auto& it = jit_string_roots_.find(StringReference(&info.dex_file, info.index)); |
| 7729 | DCHECK(it != jit_string_roots_.end()); |
| 7730 | size_t index_in_table = it->second; |
| 7731 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7732 | uintptr_t address = |
| 7733 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7734 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7735 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7736 | dchecked_integral_cast<uint32_t>(address); |
| 7737 | } |
| 7738 | } |
| 7739 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7740 | #undef __ |
| 7741 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7742 | } // namespace x86 |
| 7743 | } // namespace art |