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) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 154 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 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; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 228 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex().index_; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 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; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 268 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex().index_)); |
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(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 315 | DCHECK(instruction_->IsCheckCast() |
| 316 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | |
| 318 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 319 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 320 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 321 | if (!is_fatal_) { |
| 322 | SaveLiveRegisters(codegen, locations); |
| 323 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
| 325 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 326 | // move resolver. |
| 327 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 328 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 329 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 330 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 331 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 332 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 333 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 334 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 335 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 336 | instruction_, |
| 337 | instruction_->GetDexPc(), |
| 338 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 339 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 340 | } else { |
| 341 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 342 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 343 | instruction_, |
| 344 | instruction_->GetDexPc(), |
| 345 | this); |
| 346 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 349 | if (!is_fatal_) { |
| 350 | if (instruction_->IsInstanceOf()) { |
| 351 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 352 | } |
| 353 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 354 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 355 | __ jmp(GetExitLabel()); |
| 356 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 359 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 360 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 361 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 362 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 364 | |
| 365 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 366 | }; |
| 367 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 368 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 369 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 370 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 371 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 372 | |
| 373 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 374 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 375 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 376 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 377 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 380 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 381 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 382 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 384 | }; |
| 385 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 386 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 387 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 388 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 389 | |
| 390 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 391 | LocationSummary* locations = instruction_->GetLocations(); |
| 392 | __ Bind(GetEntryLabel()); |
| 393 | SaveLiveRegisters(codegen, locations); |
| 394 | |
| 395 | InvokeRuntimeCallingConvention calling_convention; |
| 396 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 397 | parallel_move.AddMove( |
| 398 | locations->InAt(0), |
| 399 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 400 | Primitive::kPrimNot, |
| 401 | nullptr); |
| 402 | parallel_move.AddMove( |
| 403 | locations->InAt(1), |
| 404 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 405 | Primitive::kPrimInt, |
| 406 | nullptr); |
| 407 | parallel_move.AddMove( |
| 408 | locations->InAt(2), |
| 409 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 410 | Primitive::kPrimNot, |
| 411 | nullptr); |
| 412 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 413 | |
| 414 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 415 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 416 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 417 | RestoreLiveRegisters(codegen, locations); |
| 418 | __ jmp(GetExitLabel()); |
| 419 | } |
| 420 | |
| 421 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 422 | |
| 423 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 424 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 425 | }; |
| 426 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 427 | // Slow path marking an object reference `ref` during a read |
| 428 | // barrier. The field `obj.field` in the object `obj` holding this |
| 429 | // reference does not get updated by this slow path after marking (see |
| 430 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 431 | // |
| 432 | // This means that after the execution of this slow path, `ref` will |
| 433 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 434 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 435 | // probably still be a from-space reference (unless it gets updated by |
| 436 | // another thread, or if another thread installed another object |
| 437 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 438 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 439 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 440 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 441 | Location ref, |
| 442 | bool unpoison_ref_before_marking) |
| 443 | : SlowPathCode(instruction), |
| 444 | ref_(ref), |
| 445 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 446 | DCHECK(kEmitCompilerReadBarrier); |
| 447 | } |
| 448 | |
| 449 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 450 | |
| 451 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 452 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 453 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 454 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 455 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 456 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 457 | instruction_->IsStaticFieldGet() || |
| 458 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 459 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 460 | instruction_->IsLoadClass() || |
| 461 | instruction_->IsLoadString() || |
| 462 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 463 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 464 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 465 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 466 | << "Unexpected instruction in read barrier marking slow path: " |
| 467 | << instruction_->DebugName(); |
| 468 | |
| 469 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 470 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 471 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 472 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 473 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 474 | // No need to save live registers; it's taken care of by the |
| 475 | // entrypoint. Also, there is no need to update the stack mask, |
| 476 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 477 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 478 | DCHECK_NE(ref_reg, ESP); |
| 479 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 480 | // "Compact" slow path, saving two moves. |
| 481 | // |
| 482 | // Instead of using the standard runtime calling convention (input |
| 483 | // and output in EAX): |
| 484 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 485 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 486 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 487 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 488 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 489 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 490 | // of a dedicated entrypoint: |
| 491 | // |
| 492 | // rX <- ReadBarrierMarkRegX(rX) |
| 493 | // |
| 494 | int32_t entry_point_offset = |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 495 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 496 | // This runtime call does not require a stack map. |
| 497 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 498 | __ jmp(GetExitLabel()); |
| 499 | } |
| 500 | |
| 501 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 502 | // The location (register) of the marked object reference. |
| 503 | const Location ref_; |
| 504 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 505 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 506 | |
| 507 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 508 | }; |
| 509 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | // Slow path marking an object reference `ref` during a read barrier, |
| 511 | // and if needed, atomically updating the field `obj.field` in the |
| 512 | // object `obj` holding this reference after marking (contrary to |
| 513 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 514 | // `obj.field`). |
| 515 | // |
| 516 | // This means that after the execution of this slow path, both `ref` |
| 517 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 518 | // hold the same to-space reference (unless another thread installed |
| 519 | // another object reference (different from `ref`) in `obj.field`). |
| 520 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 521 | public: |
| 522 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 523 | Location ref, |
| 524 | Register obj, |
| 525 | const Address& field_addr, |
| 526 | bool unpoison_ref_before_marking, |
| 527 | Register temp) |
| 528 | : SlowPathCode(instruction), |
| 529 | ref_(ref), |
| 530 | obj_(obj), |
| 531 | field_addr_(field_addr), |
| 532 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 533 | temp_(temp) { |
| 534 | DCHECK(kEmitCompilerReadBarrier); |
| 535 | } |
| 536 | |
| 537 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 538 | |
| 539 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 540 | LocationSummary* locations = instruction_->GetLocations(); |
| 541 | Register ref_reg = ref_.AsRegister<Register>(); |
| 542 | DCHECK(locations->CanCall()); |
| 543 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 544 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 545 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 546 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 547 | << instruction_->DebugName(); |
| 548 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 549 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 550 | |
| 551 | __ Bind(GetEntryLabel()); |
| 552 | if (unpoison_ref_before_marking_) { |
| 553 | // Object* ref = ref_addr->AsMirrorPtr() |
| 554 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 555 | } |
| 556 | |
| 557 | // Save the old (unpoisoned) reference. |
| 558 | __ movl(temp_, ref_reg); |
| 559 | |
| 560 | // No need to save live registers; it's taken care of by the |
| 561 | // entrypoint. Also, there is no need to update the stack mask, |
| 562 | // as this runtime call will not trigger a garbage collection. |
| 563 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 564 | DCHECK_NE(ref_reg, ESP); |
| 565 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 566 | // "Compact" slow path, saving two moves. |
| 567 | // |
| 568 | // Instead of using the standard runtime calling convention (input |
| 569 | // and output in EAX): |
| 570 | // |
| 571 | // EAX <- ref |
| 572 | // EAX <- ReadBarrierMark(EAX) |
| 573 | // ref <- EAX |
| 574 | // |
| 575 | // we just use rX (the register containing `ref`) as input and output |
| 576 | // of a dedicated entrypoint: |
| 577 | // |
| 578 | // rX <- ReadBarrierMarkRegX(rX) |
| 579 | // |
| 580 | int32_t entry_point_offset = |
| 581 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| 582 | // This runtime call does not require a stack map. |
| 583 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 584 | |
| 585 | // If the new reference is different from the old reference, |
| 586 | // update the field in the holder (`*field_addr`). |
| 587 | // |
| 588 | // Note that this field could also hold a different object, if |
| 589 | // another thread had concurrently changed it. In that case, the |
| 590 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 591 | // operation below would abort the CAS, leaving the field as-is. |
| 592 | NearLabel done; |
| 593 | __ cmpl(temp_, ref_reg); |
| 594 | __ j(kEqual, &done); |
| 595 | |
| 596 | // Update the the holder's field atomically. This may fail if |
| 597 | // mutator updates before us, but it's OK. This is achieved |
| 598 | // using a strong compare-and-set (CAS) operation with relaxed |
| 599 | // memory synchronization ordering, where the expected value is |
| 600 | // the old reference and the desired value is the new reference. |
| 601 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 602 | // instruction, which requires the expected value (the old |
| 603 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 604 | // expected value (stored in `temp_`) into EAX. |
| 605 | __ pushl(EAX); |
| 606 | __ movl(EAX, temp_); |
| 607 | |
| 608 | // Convenience aliases. |
| 609 | Register base = obj_; |
| 610 | Register expected = EAX; |
| 611 | Register value = ref_reg; |
| 612 | |
| 613 | bool base_equals_value = (base == value); |
| 614 | if (kPoisonHeapReferences) { |
| 615 | if (base_equals_value) { |
| 616 | // If `base` and `value` are the same register location, move |
| 617 | // `value` to a temporary register. This way, poisoning |
| 618 | // `value` won't invalidate `base`. |
| 619 | value = temp_; |
| 620 | __ movl(value, base); |
| 621 | } |
| 622 | |
| 623 | // Check that the register allocator did not assign the location |
| 624 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 625 | // poisoning (when enabled) works as intended below. |
| 626 | // - If `value` were equal to `expected`, both references would |
| 627 | // be poisoned twice, meaning they would not be poisoned at |
| 628 | // all, as heap poisoning uses address negation. |
| 629 | // - If `base` were equal to `expected`, poisoning `expected` |
| 630 | // would invalidate `base`. |
| 631 | DCHECK_NE(value, expected); |
| 632 | DCHECK_NE(base, expected); |
| 633 | |
| 634 | __ PoisonHeapReference(expected); |
| 635 | __ PoisonHeapReference(value); |
| 636 | } |
| 637 | |
| 638 | __ LockCmpxchgl(field_addr_, value); |
| 639 | |
| 640 | // If heap poisoning is enabled, we need to unpoison the values |
| 641 | // that were poisoned earlier. |
| 642 | if (kPoisonHeapReferences) { |
| 643 | if (base_equals_value) { |
| 644 | // `value` has been moved to a temporary register, no need |
| 645 | // to unpoison it. |
| 646 | } else { |
| 647 | __ UnpoisonHeapReference(value); |
| 648 | } |
| 649 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 650 | } |
| 651 | |
| 652 | // Restore EAX. |
| 653 | __ popl(EAX); |
| 654 | |
| 655 | __ Bind(&done); |
| 656 | __ jmp(GetExitLabel()); |
| 657 | } |
| 658 | |
| 659 | private: |
| 660 | // The location (register) of the marked object reference. |
| 661 | const Location ref_; |
| 662 | // The register containing the object holding the marked object reference field. |
| 663 | const Register obj_; |
| 664 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 665 | const Address field_addr_; |
| 666 | |
| 667 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 668 | const bool unpoison_ref_before_marking_; |
| 669 | |
| 670 | const Register temp_; |
| 671 | |
| 672 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 673 | }; |
| 674 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 675 | // Slow path generating a read barrier for a heap reference. |
| 676 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 677 | public: |
| 678 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 679 | Location out, |
| 680 | Location ref, |
| 681 | Location obj, |
| 682 | uint32_t offset, |
| 683 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 684 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 685 | out_(out), |
| 686 | ref_(ref), |
| 687 | obj_(obj), |
| 688 | offset_(offset), |
| 689 | index_(index) { |
| 690 | DCHECK(kEmitCompilerReadBarrier); |
| 691 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 692 | // has been overwritten by (or after) the heap object reference load |
| 693 | // to be instrumented, e.g.: |
| 694 | // |
| 695 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 696 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 697 | // |
| 698 | // In that case, we have lost the information about the original |
| 699 | // object, and the emitted read barrier cannot work properly. |
| 700 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 701 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 702 | } |
| 703 | |
| 704 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 705 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 706 | LocationSummary* locations = instruction_->GetLocations(); |
| 707 | Register reg_out = out_.AsRegister<Register>(); |
| 708 | DCHECK(locations->CanCall()); |
| 709 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 710 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 711 | instruction_->IsStaticFieldGet() || |
| 712 | instruction_->IsArrayGet() || |
| 713 | instruction_->IsInstanceOf() || |
| 714 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 715 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 716 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 717 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 718 | |
| 719 | __ Bind(GetEntryLabel()); |
| 720 | SaveLiveRegisters(codegen, locations); |
| 721 | |
| 722 | // We may have to change the index's value, but as `index_` is a |
| 723 | // constant member (like other "inputs" of this slow path), |
| 724 | // introduce a copy of it, `index`. |
| 725 | Location index = index_; |
| 726 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 727 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 728 | if (instruction_->IsArrayGet()) { |
| 729 | // Compute the actual memory offset and store it in `index`. |
| 730 | Register index_reg = index_.AsRegister<Register>(); |
| 731 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 732 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 733 | // We are about to change the value of `index_reg` (see the |
| 734 | // calls to art::x86::X86Assembler::shll and |
| 735 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 736 | // not been saved by the previous call to |
| 737 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 738 | // callee-save register -- |
| 739 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 740 | // callee-save registers, as it has been designed with the |
| 741 | // assumption that callee-save registers are supposed to be |
| 742 | // handled by the called function. So, as a callee-save |
| 743 | // register, `index_reg` _would_ eventually be saved onto |
| 744 | // the stack, but it would be too late: we would have |
| 745 | // changed its value earlier. Therefore, we manually save |
| 746 | // it here into another freely available register, |
| 747 | // `free_reg`, chosen of course among the caller-save |
| 748 | // registers (as a callee-save `free_reg` register would |
| 749 | // exhibit the same problem). |
| 750 | // |
| 751 | // Note we could have requested a temporary register from |
| 752 | // the register allocator instead; but we prefer not to, as |
| 753 | // this is a slow path, and we know we can find a |
| 754 | // caller-save register that is available. |
| 755 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 756 | __ movl(free_reg, index_reg); |
| 757 | index_reg = free_reg; |
| 758 | index = Location::RegisterLocation(index_reg); |
| 759 | } else { |
| 760 | // The initial register stored in `index_` has already been |
| 761 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 762 | // (as it is not a callee-save register), so we can freely |
| 763 | // use it. |
| 764 | } |
| 765 | // Shifting the index value contained in `index_reg` by the scale |
| 766 | // factor (2) cannot overflow in practice, as the runtime is |
| 767 | // unable to allocate object arrays with a size larger than |
| 768 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 769 | __ shll(index_reg, Immediate(TIMES_4)); |
| 770 | static_assert( |
| 771 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 772 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 773 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 774 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 775 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 776 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 777 | // (as in the case of ArrayGet), as it is actually an offset |
| 778 | // to an object field within an object. |
| 779 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 780 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 781 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 782 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 783 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 784 | DCHECK_EQ(offset_, 0U); |
| 785 | DCHECK(index_.IsRegisterPair()); |
| 786 | // UnsafeGet's offset location is a register pair, the low |
| 787 | // part contains the correct offset. |
| 788 | index = index_.ToLow(); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | // We're moving two or three locations to locations that could |
| 793 | // overlap, so we need a parallel move resolver. |
| 794 | InvokeRuntimeCallingConvention calling_convention; |
| 795 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 796 | parallel_move.AddMove(ref_, |
| 797 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 798 | Primitive::kPrimNot, |
| 799 | nullptr); |
| 800 | parallel_move.AddMove(obj_, |
| 801 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 802 | Primitive::kPrimNot, |
| 803 | nullptr); |
| 804 | if (index.IsValid()) { |
| 805 | parallel_move.AddMove(index, |
| 806 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 807 | Primitive::kPrimInt, |
| 808 | nullptr); |
| 809 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 810 | } else { |
| 811 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 812 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 813 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 814 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 815 | CheckEntrypointTypes< |
| 816 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 817 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 818 | |
| 819 | RestoreLiveRegisters(codegen, locations); |
| 820 | __ jmp(GetExitLabel()); |
| 821 | } |
| 822 | |
| 823 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 824 | |
| 825 | private: |
| 826 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 827 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 828 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 829 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 830 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 831 | return static_cast<Register>(i); |
| 832 | } |
| 833 | } |
| 834 | // We shall never fail to find a free caller-save register, as |
| 835 | // there are more than two core caller-save registers on x86 |
| 836 | // (meaning it is possible to find one which is different from |
| 837 | // `ref` and `obj`). |
| 838 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 839 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 840 | UNREACHABLE(); |
| 841 | } |
| 842 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 843 | const Location out_; |
| 844 | const Location ref_; |
| 845 | const Location obj_; |
| 846 | const uint32_t offset_; |
| 847 | // An additional location containing an index to an array. |
| 848 | // Only used for HArrayGet and the UnsafeGetObject & |
| 849 | // UnsafeGetObjectVolatile intrinsics. |
| 850 | const Location index_; |
| 851 | |
| 852 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 853 | }; |
| 854 | |
| 855 | // Slow path generating a read barrier for a GC root. |
| 856 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 857 | public: |
| 858 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 859 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 860 | DCHECK(kEmitCompilerReadBarrier); |
| 861 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 862 | |
| 863 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 864 | LocationSummary* locations = instruction_->GetLocations(); |
| 865 | Register reg_out = out_.AsRegister<Register>(); |
| 866 | DCHECK(locations->CanCall()); |
| 867 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 868 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 869 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 870 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 871 | |
| 872 | __ Bind(GetEntryLabel()); |
| 873 | SaveLiveRegisters(codegen, locations); |
| 874 | |
| 875 | InvokeRuntimeCallingConvention calling_convention; |
| 876 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 877 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 878 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 879 | instruction_, |
| 880 | instruction_->GetDexPc(), |
| 881 | this); |
| 882 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 883 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 884 | |
| 885 | RestoreLiveRegisters(codegen, locations); |
| 886 | __ jmp(GetExitLabel()); |
| 887 | } |
| 888 | |
| 889 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 890 | |
| 891 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 892 | const Location out_; |
| 893 | const Location root_; |
| 894 | |
| 895 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 896 | }; |
| 897 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 898 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 899 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 900 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 901 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 902 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 903 | switch (cond) { |
| 904 | case kCondEQ: return kEqual; |
| 905 | case kCondNE: return kNotEqual; |
| 906 | case kCondLT: return kLess; |
| 907 | case kCondLE: return kLessEqual; |
| 908 | case kCondGT: return kGreater; |
| 909 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 910 | case kCondB: return kBelow; |
| 911 | case kCondBE: return kBelowEqual; |
| 912 | case kCondA: return kAbove; |
| 913 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 914 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 915 | LOG(FATAL) << "Unreachable"; |
| 916 | UNREACHABLE(); |
| 917 | } |
| 918 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 919 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 920 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 921 | switch (cond) { |
| 922 | case kCondEQ: return kEqual; |
| 923 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 924 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 925 | case kCondLT: return kBelow; |
| 926 | case kCondLE: return kBelowEqual; |
| 927 | case kCondGT: return kAbove; |
| 928 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 929 | // Unsigned remain unchanged. |
| 930 | case kCondB: return kBelow; |
| 931 | case kCondBE: return kBelowEqual; |
| 932 | case kCondA: return kAbove; |
| 933 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 934 | } |
| 935 | LOG(FATAL) << "Unreachable"; |
| 936 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 939 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 940 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 944 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 945 | } |
| 946 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 947 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 948 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 949 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 950 | } |
| 951 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 952 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 953 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 954 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 955 | } |
| 956 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 957 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 958 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 959 | return GetFloatingPointSpillSlotSize(); |
| 960 | } |
| 961 | |
| 962 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 963 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 964 | return GetFloatingPointSpillSlotSize(); |
| 965 | } |
| 966 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 967 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 968 | HInstruction* instruction, |
| 969 | uint32_t dex_pc, |
| 970 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 971 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 972 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 973 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 974 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 975 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 976 | } |
| 977 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 978 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 979 | HInstruction* instruction, |
| 980 | SlowPathCode* slow_path) { |
| 981 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 982 | GenerateInvokeRuntime(entry_point_offset); |
| 983 | } |
| 984 | |
| 985 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 986 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 987 | } |
| 988 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 989 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 990 | const X86InstructionSetFeatures& isa_features, |
| 991 | const CompilerOptions& compiler_options, |
| 992 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 993 | : CodeGenerator(graph, |
| 994 | kNumberOfCpuRegisters, |
| 995 | kNumberOfXmmRegisters, |
| 996 | kNumberOfRegisterPairs, |
| 997 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 998 | arraysize(kCoreCalleeSaves)) |
| 999 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1000 | 0, |
| 1001 | compiler_options, |
| 1002 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1003 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1004 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1005 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1006 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1007 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1008 | isa_features_(isa_features), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1009 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1010 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1011 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1012 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1013 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1014 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1015 | constant_area_start_(-1), |
| 1016 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1017 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1018 | // Use a fake return address register to mimic Quick. |
| 1019 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1020 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1021 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1022 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1023 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1024 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1025 | } |
| 1026 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1027 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1028 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1029 | assembler_(codegen->GetAssembler()), |
| 1030 | codegen_(codegen) {} |
| 1031 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1032 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1033 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1034 | } |
| 1035 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1036 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1037 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1038 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1039 | bool skip_overflow_check = |
| 1040 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1041 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1042 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1043 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1044 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1045 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1048 | if (HasEmptyFrame()) { |
| 1049 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1050 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1051 | |
| 1052 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1053 | Register reg = kCoreCalleeSaves[i]; |
| 1054 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1055 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1056 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1057 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1061 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1062 | // Initialize should_deoptimize flag to 0. |
| 1063 | __ movl(Address(ESP, -kShouldDeoptimizeFlagSize), Immediate(0)); |
| 1064 | } |
| 1065 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1066 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1067 | __ subl(ESP, Immediate(adjust)); |
| 1068 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1069 | // Save the current method if we need it. Note that we do not |
| 1070 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1071 | // in the SSA graph. |
| 1072 | if (RequiresCurrentMethod()) { |
| 1073 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1074 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1078 | __ cfi().RememberState(); |
| 1079 | if (!HasEmptyFrame()) { |
| 1080 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1081 | __ addl(ESP, Immediate(adjust)); |
| 1082 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1083 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1084 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1085 | Register reg = kCoreCalleeSaves[i]; |
| 1086 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1087 | __ popl(reg); |
| 1088 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1089 | __ cfi().Restore(DWARFReg(reg)); |
| 1090 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1091 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1092 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1093 | __ ret(); |
| 1094 | __ cfi().RestoreState(); |
| 1095 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1098 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1099 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1102 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 1103 | switch (type) { |
| 1104 | case Primitive::kPrimBoolean: |
| 1105 | case Primitive::kPrimByte: |
| 1106 | case Primitive::kPrimChar: |
| 1107 | case Primitive::kPrimShort: |
| 1108 | case Primitive::kPrimInt: |
| 1109 | case Primitive::kPrimNot: |
| 1110 | return Location::RegisterLocation(EAX); |
| 1111 | |
| 1112 | case Primitive::kPrimLong: |
| 1113 | return Location::RegisterPairLocation(EAX, EDX); |
| 1114 | |
| 1115 | case Primitive::kPrimVoid: |
| 1116 | return Location::NoLocation(); |
| 1117 | |
| 1118 | case Primitive::kPrimDouble: |
| 1119 | case Primitive::kPrimFloat: |
| 1120 | return Location::FpuRegisterLocation(XMM0); |
| 1121 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1122 | |
| 1123 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1127 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1128 | } |
| 1129 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1130 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1131 | switch (type) { |
| 1132 | case Primitive::kPrimBoolean: |
| 1133 | case Primitive::kPrimByte: |
| 1134 | case Primitive::kPrimChar: |
| 1135 | case Primitive::kPrimShort: |
| 1136 | case Primitive::kPrimInt: |
| 1137 | case Primitive::kPrimNot: { |
| 1138 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1139 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1140 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1141 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1142 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1143 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1144 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1145 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1146 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1147 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1148 | uint32_t index = gp_index_; |
| 1149 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1150 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1151 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1152 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1153 | calling_convention.GetRegisterPairAt(index)); |
| 1154 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1155 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1156 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1161 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1162 | stack_index_++; |
| 1163 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1164 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1165 | } else { |
| 1166 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1171 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1172 | stack_index_ += 2; |
| 1173 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1174 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1175 | } else { |
| 1176 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1180 | case Primitive::kPrimVoid: |
| 1181 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1182 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1183 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1184 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1185 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1186 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1187 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1188 | if (source.Equals(destination)) { |
| 1189 | return; |
| 1190 | } |
| 1191 | if (destination.IsRegister()) { |
| 1192 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1193 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1194 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1195 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1196 | } else { |
| 1197 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1198 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1199 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1200 | } else if (destination.IsFpuRegister()) { |
| 1201 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1202 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1203 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1204 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1205 | } else { |
| 1206 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1207 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1208 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1209 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1210 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1211 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1212 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1213 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1214 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1215 | } else if (source.IsConstant()) { |
| 1216 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1217 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1218 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1219 | } else { |
| 1220 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1221 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1222 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1228 | if (source.Equals(destination)) { |
| 1229 | return; |
| 1230 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1231 | if (destination.IsRegisterPair()) { |
| 1232 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1233 | EmitParallelMoves( |
| 1234 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1235 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1236 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1237 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1238 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1239 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1240 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1241 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1242 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1243 | __ psrlq(src_reg, Immediate(32)); |
| 1244 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1245 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1246 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1247 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1248 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1249 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1250 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1251 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1252 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1253 | if (source.IsFpuRegister()) { |
| 1254 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1255 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1256 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1257 | } else if (source.IsRegisterPair()) { |
| 1258 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1259 | // Create stack space for 2 elements. |
| 1260 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1261 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1262 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1263 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1264 | // And remove the temporary stack space we allocated. |
| 1265 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1266 | } else { |
| 1267 | LOG(FATAL) << "Unimplemented"; |
| 1268 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1269 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1270 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1271 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1272 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1273 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1274 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1275 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1276 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1277 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1278 | } else if (source.IsConstant()) { |
| 1279 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1280 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1281 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1282 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1283 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1284 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1285 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1286 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1287 | EmitParallelMoves( |
| 1288 | Location::StackSlot(source.GetStackIndex()), |
| 1289 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1290 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1291 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1292 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1293 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1298 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1299 | DCHECK(location.IsRegister()); |
| 1300 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1301 | } |
| 1302 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1303 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1304 | HParallelMove move(GetGraph()->GetArena()); |
| 1305 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1306 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1307 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1308 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1309 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1310 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1311 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1315 | if (location.IsRegister()) { |
| 1316 | locations->AddTemp(location); |
| 1317 | } else if (location.IsRegisterPair()) { |
| 1318 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1319 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1320 | } else { |
| 1321 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1322 | } |
| 1323 | } |
| 1324 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1325 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1326 | DCHECK(!successor->IsExitBlock()); |
| 1327 | |
| 1328 | HBasicBlock* block = got->GetBlock(); |
| 1329 | HInstruction* previous = got->GetPrevious(); |
| 1330 | |
| 1331 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1332 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1333 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
| 1337 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1338 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1339 | } |
| 1340 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1341 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1345 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1346 | got->SetLocations(nullptr); |
| 1347 | } |
| 1348 | |
| 1349 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1350 | HandleGoto(got, got->GetSuccessor()); |
| 1351 | } |
| 1352 | |
| 1353 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1354 | try_boundary->SetLocations(nullptr); |
| 1355 | } |
| 1356 | |
| 1357 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1358 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1359 | if (!successor->IsExitBlock()) { |
| 1360 | HandleGoto(try_boundary, successor); |
| 1361 | } |
| 1362 | } |
| 1363 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1364 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1365 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1368 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1371 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1372 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1373 | LabelType* true_label, |
| 1374 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1375 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1376 | __ j(kUnordered, true_label); |
| 1377 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1378 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1379 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1380 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1381 | } |
| 1382 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1383 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1384 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1385 | LabelType* true_label, |
| 1386 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1387 | LocationSummary* locations = cond->GetLocations(); |
| 1388 | Location left = locations->InAt(0); |
| 1389 | Location right = locations->InAt(1); |
| 1390 | IfCondition if_cond = cond->GetCondition(); |
| 1391 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1392 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1393 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1394 | IfCondition true_high_cond = if_cond; |
| 1395 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1396 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1397 | |
| 1398 | // Set the conditions for the test, remembering that == needs to be |
| 1399 | // decided using the low words. |
| 1400 | switch (if_cond) { |
| 1401 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1402 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1403 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1404 | break; |
| 1405 | case kCondLT: |
| 1406 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1407 | break; |
| 1408 | case kCondLE: |
| 1409 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1410 | break; |
| 1411 | case kCondGT: |
| 1412 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1413 | break; |
| 1414 | case kCondGE: |
| 1415 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1416 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1417 | case kCondB: |
| 1418 | false_high_cond = kCondA; |
| 1419 | break; |
| 1420 | case kCondBE: |
| 1421 | true_high_cond = kCondB; |
| 1422 | break; |
| 1423 | case kCondA: |
| 1424 | false_high_cond = kCondB; |
| 1425 | break; |
| 1426 | case kCondAE: |
| 1427 | true_high_cond = kCondA; |
| 1428 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | if (right.IsConstant()) { |
| 1432 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1433 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1434 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1435 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1436 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1437 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1438 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1440 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1441 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1442 | __ j(X86Condition(true_high_cond), true_label); |
| 1443 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1444 | } |
| 1445 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1446 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1447 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1448 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1449 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1450 | |
| 1451 | __ cmpl(left_high, right_high); |
| 1452 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1453 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1454 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1455 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1456 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1457 | __ j(X86Condition(true_high_cond), true_label); |
| 1458 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1459 | } |
| 1460 | // Must be equal high, so compare the lows. |
| 1461 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1462 | } else { |
| 1463 | DCHECK(right.IsDoubleStackSlot()); |
| 1464 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1465 | if (if_cond == kCondNE) { |
| 1466 | __ j(X86Condition(true_high_cond), true_label); |
| 1467 | } else if (if_cond == kCondEQ) { |
| 1468 | __ j(X86Condition(false_high_cond), false_label); |
| 1469 | } else { |
| 1470 | __ j(X86Condition(true_high_cond), true_label); |
| 1471 | __ j(X86Condition(false_high_cond), false_label); |
| 1472 | } |
| 1473 | // Must be equal high, so compare the lows. |
| 1474 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1475 | } |
| 1476 | // The last comparison might be unsigned. |
| 1477 | __ j(final_condition, true_label); |
| 1478 | } |
| 1479 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1480 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1481 | Location rhs, |
| 1482 | HInstruction* insn, |
| 1483 | bool is_double) { |
| 1484 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1485 | if (is_double) { |
| 1486 | if (rhs.IsFpuRegister()) { |
| 1487 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1488 | } else if (const_area != nullptr) { |
| 1489 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1490 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1491 | codegen_->LiteralDoubleAddress( |
| 1492 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1493 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1494 | } else { |
| 1495 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1496 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1497 | } |
| 1498 | } else { |
| 1499 | if (rhs.IsFpuRegister()) { |
| 1500 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1501 | } else if (const_area != nullptr) { |
| 1502 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1503 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1504 | codegen_->LiteralFloatAddress( |
| 1505 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1506 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1507 | } else { |
| 1508 | DCHECK(rhs.IsStackSlot()); |
| 1509 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1514 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1515 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1516 | LabelType* true_target_in, |
| 1517 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1518 | // Generated branching requires both targets to be explicit. If either of the |
| 1519 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1520 | LabelType fallthrough_target; |
| 1521 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1522 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1523 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1524 | LocationSummary* locations = condition->GetLocations(); |
| 1525 | Location left = locations->InAt(0); |
| 1526 | Location right = locations->InAt(1); |
| 1527 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1528 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1529 | switch (type) { |
| 1530 | case Primitive::kPrimLong: |
| 1531 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1532 | break; |
| 1533 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1534 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1535 | GenerateFPJumps(condition, true_target, false_target); |
| 1536 | break; |
| 1537 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1538 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1539 | GenerateFPJumps(condition, true_target, false_target); |
| 1540 | break; |
| 1541 | default: |
| 1542 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1543 | } |
| 1544 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1545 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1546 | __ jmp(false_target); |
| 1547 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1548 | |
| 1549 | if (fallthrough_target.IsLinked()) { |
| 1550 | __ Bind(&fallthrough_target); |
| 1551 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1552 | } |
| 1553 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1554 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1555 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1556 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1557 | // conditions if they are materialized due to the complex branching. |
| 1558 | return cond->IsCondition() && |
| 1559 | cond->GetNext() == branch && |
| 1560 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1561 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1562 | } |
| 1563 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1564 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1565 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1566 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1567 | LabelType* true_target, |
| 1568 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1569 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1570 | |
| 1571 | if (true_target == nullptr && false_target == nullptr) { |
| 1572 | // Nothing to do. The code always falls through. |
| 1573 | return; |
| 1574 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1575 | // Constant condition, statically compared against "true" (integer value 1). |
| 1576 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1577 | if (true_target != nullptr) { |
| 1578 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1579 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1580 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1581 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1582 | if (false_target != nullptr) { |
| 1583 | __ jmp(false_target); |
| 1584 | } |
| 1585 | } |
| 1586 | return; |
| 1587 | } |
| 1588 | |
| 1589 | // The following code generates these patterns: |
| 1590 | // (1) true_target == nullptr && false_target != nullptr |
| 1591 | // - opposite condition true => branch to false_target |
| 1592 | // (2) true_target != nullptr && false_target == nullptr |
| 1593 | // - condition true => branch to true_target |
| 1594 | // (3) true_target != nullptr && false_target != nullptr |
| 1595 | // - condition true => branch to true_target |
| 1596 | // - branch to false_target |
| 1597 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1598 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1599 | if (true_target == nullptr) { |
| 1600 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1601 | } else { |
| 1602 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1603 | } |
| 1604 | } else { |
| 1605 | // Materialized condition, compare against 0. |
| 1606 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1607 | if (lhs.IsRegister()) { |
| 1608 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1609 | } else { |
| 1610 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1611 | } |
| 1612 | if (true_target == nullptr) { |
| 1613 | __ j(kEqual, false_target); |
| 1614 | } else { |
| 1615 | __ j(kNotEqual, true_target); |
| 1616 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1617 | } |
| 1618 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1619 | // Condition has not been materialized, use its inputs as the comparison and |
| 1620 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1621 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1622 | |
| 1623 | // If this is a long or FP comparison that has been folded into |
| 1624 | // the HCondition, generate the comparison directly. |
| 1625 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1626 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1627 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1628 | return; |
| 1629 | } |
| 1630 | |
| 1631 | Location lhs = condition->GetLocations()->InAt(0); |
| 1632 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1633 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1634 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1635 | if (true_target == nullptr) { |
| 1636 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1637 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1638 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1639 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1640 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1641 | |
| 1642 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1643 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1644 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1645 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1649 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1650 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1651 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1652 | locations->SetInAt(0, Location::Any()); |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1657 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1658 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1659 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1660 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1661 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1662 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1663 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1667 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1668 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1669 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1670 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1671 | locations->SetInAt(0, Location::Any()); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1676 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1677 | GenerateTestAndBranch<Label>(deoptimize, |
| 1678 | /* condition_input_index */ 0, |
| 1679 | slow_path->GetEntryLabel(), |
| 1680 | /* false_target */ nullptr); |
| 1681 | } |
| 1682 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1683 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1684 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1685 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1686 | locations->SetOut(Location::RequiresRegister()); |
| 1687 | } |
| 1688 | |
| 1689 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1690 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1691 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1692 | } |
| 1693 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1694 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1695 | // There are no conditional move instructions for XMMs. |
| 1696 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1697 | return false; |
| 1698 | } |
| 1699 | |
| 1700 | // A FP condition doesn't generate the single CC that we need. |
| 1701 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1702 | HInstruction* condition = select->GetCondition(); |
| 1703 | if (condition->IsCondition()) { |
| 1704 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1705 | if (compare_type == Primitive::kPrimLong || |
| 1706 | Primitive::IsFloatingPointType(compare_type)) { |
| 1707 | return false; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | // We can generate a CMOV for this Select. |
| 1712 | return true; |
| 1713 | } |
| 1714 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1715 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1716 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1717 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1718 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1719 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1720 | } else { |
| 1721 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1722 | if (SelectCanUseCMOV(select)) { |
| 1723 | if (select->InputAt(1)->IsConstant()) { |
| 1724 | // Cmov can't handle a constant value. |
| 1725 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1726 | } else { |
| 1727 | locations->SetInAt(1, Location::Any()); |
| 1728 | } |
| 1729 | } else { |
| 1730 | locations->SetInAt(1, Location::Any()); |
| 1731 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1732 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1733 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1734 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1735 | } |
| 1736 | locations->SetOut(Location::SameAsFirstInput()); |
| 1737 | } |
| 1738 | |
| 1739 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1740 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1741 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1742 | if (SelectCanUseCMOV(select)) { |
| 1743 | // If both the condition and the source types are integer, we can generate |
| 1744 | // a CMOV to implement Select. |
| 1745 | |
| 1746 | HInstruction* select_condition = select->GetCondition(); |
| 1747 | Condition cond = kNotEqual; |
| 1748 | |
| 1749 | // Figure out how to test the 'condition'. |
| 1750 | if (select_condition->IsCondition()) { |
| 1751 | HCondition* condition = select_condition->AsCondition(); |
| 1752 | if (!condition->IsEmittedAtUseSite()) { |
| 1753 | // This was a previously materialized condition. |
| 1754 | // Can we use the existing condition code? |
| 1755 | if (AreEflagsSetFrom(condition, select)) { |
| 1756 | // Materialization was the previous instruction. Condition codes are right. |
| 1757 | cond = X86Condition(condition->GetCondition()); |
| 1758 | } else { |
| 1759 | // No, we have to recreate the condition code. |
| 1760 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1761 | __ testl(cond_reg, cond_reg); |
| 1762 | } |
| 1763 | } else { |
| 1764 | // We can't handle FP or long here. |
| 1765 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1766 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1767 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1768 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1769 | cond = X86Condition(condition->GetCondition()); |
| 1770 | } |
| 1771 | } else { |
| 1772 | // Must be a boolean condition, which needs to be compared to 0. |
| 1773 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1774 | __ testl(cond_reg, cond_reg); |
| 1775 | } |
| 1776 | |
| 1777 | // If the condition is true, overwrite the output, which already contains false. |
| 1778 | Location false_loc = locations->InAt(0); |
| 1779 | Location true_loc = locations->InAt(1); |
| 1780 | if (select->GetType() == Primitive::kPrimLong) { |
| 1781 | // 64 bit conditional move. |
| 1782 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1783 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1784 | if (true_loc.IsRegisterPair()) { |
| 1785 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1786 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1787 | } else { |
| 1788 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1789 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1790 | } |
| 1791 | } else { |
| 1792 | // 32 bit conditional move. |
| 1793 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1794 | if (true_loc.IsRegister()) { |
| 1795 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1796 | } else { |
| 1797 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1798 | } |
| 1799 | } |
| 1800 | } else { |
| 1801 | NearLabel false_target; |
| 1802 | GenerateTestAndBranch<NearLabel>( |
| 1803 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1804 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1805 | __ Bind(&false_target); |
| 1806 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1809 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1810 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1811 | } |
| 1812 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1813 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1814 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void CodeGeneratorX86::GenerateNop() { |
| 1818 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1821 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1822 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1823 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1824 | // Handle the long/FP comparisons made in instruction simplification. |
| 1825 | switch (cond->InputAt(0)->GetType()) { |
| 1826 | case Primitive::kPrimLong: { |
| 1827 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1828 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1829 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1830 | locations->SetOut(Location::RequiresRegister()); |
| 1831 | } |
| 1832 | break; |
| 1833 | } |
| 1834 | case Primitive::kPrimFloat: |
| 1835 | case Primitive::kPrimDouble: { |
| 1836 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1837 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1838 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1839 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1840 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1841 | } else { |
| 1842 | locations->SetInAt(1, Location::Any()); |
| 1843 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1844 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1845 | locations->SetOut(Location::RequiresRegister()); |
| 1846 | } |
| 1847 | break; |
| 1848 | } |
| 1849 | default: |
| 1850 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1851 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1852 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1853 | // We need a byte register. |
| 1854 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1855 | } |
| 1856 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1857 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1860 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1861 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1862 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1863 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1864 | |
| 1865 | LocationSummary* locations = cond->GetLocations(); |
| 1866 | Location lhs = locations->InAt(0); |
| 1867 | Location rhs = locations->InAt(1); |
| 1868 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1869 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1870 | |
| 1871 | switch (cond->InputAt(0)->GetType()) { |
| 1872 | default: { |
| 1873 | // Integer case. |
| 1874 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1875 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1876 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1877 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1878 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1879 | return; |
| 1880 | } |
| 1881 | case Primitive::kPrimLong: |
| 1882 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1883 | break; |
| 1884 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1885 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1886 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1887 | break; |
| 1888 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1889 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1890 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1891 | break; |
| 1892 | } |
| 1893 | |
| 1894 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1895 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1896 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1897 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1898 | __ Bind(&false_label); |
| 1899 | __ xorl(reg, reg); |
| 1900 | __ jmp(&done_label); |
| 1901 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1902 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1903 | __ Bind(&true_label); |
| 1904 | __ movl(reg, Immediate(1)); |
| 1905 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1909 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1913 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1917 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1921 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1925 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1929 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1933 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1937 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1941 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1945 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1949 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1953 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1956 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1957 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1961 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1965 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1969 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1973 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1977 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1981 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1985 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1988 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1989 | LocationSummary* locations = |
| 1990 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1991 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1994 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1995 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1998 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1999 | LocationSummary* locations = |
| 2000 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2001 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2002 | } |
| 2003 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2004 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2005 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2008 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2009 | LocationSummary* locations = |
| 2010 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2011 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2012 | } |
| 2013 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2014 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2015 | // Will be generated at use site. |
| 2016 | } |
| 2017 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2018 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2019 | LocationSummary* locations = |
| 2020 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2021 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2022 | } |
| 2023 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2024 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2025 | // Will be generated at use site. |
| 2026 | } |
| 2027 | |
| 2028 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2029 | LocationSummary* locations = |
| 2030 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2031 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2032 | } |
| 2033 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2034 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2035 | // Will be generated at use site. |
| 2036 | } |
| 2037 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2038 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2039 | memory_barrier->SetLocations(nullptr); |
| 2040 | } |
| 2041 | |
| 2042 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2043 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2044 | } |
| 2045 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2046 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2047 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2050 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2051 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2054 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2055 | LocationSummary* locations = |
| 2056 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2057 | switch (ret->InputAt(0)->GetType()) { |
| 2058 | case Primitive::kPrimBoolean: |
| 2059 | case Primitive::kPrimByte: |
| 2060 | case Primitive::kPrimChar: |
| 2061 | case Primitive::kPrimShort: |
| 2062 | case Primitive::kPrimInt: |
| 2063 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2064 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2065 | break; |
| 2066 | |
| 2067 | case Primitive::kPrimLong: |
| 2068 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2069 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2070 | break; |
| 2071 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2072 | case Primitive::kPrimFloat: |
| 2073 | case Primitive::kPrimDouble: |
| 2074 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2075 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2076 | break; |
| 2077 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2078 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2079 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2080 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2083 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2084 | if (kIsDebugBuild) { |
| 2085 | switch (ret->InputAt(0)->GetType()) { |
| 2086 | case Primitive::kPrimBoolean: |
| 2087 | case Primitive::kPrimByte: |
| 2088 | case Primitive::kPrimChar: |
| 2089 | case Primitive::kPrimShort: |
| 2090 | case Primitive::kPrimInt: |
| 2091 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2092 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2093 | break; |
| 2094 | |
| 2095 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2096 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2097 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2098 | break; |
| 2099 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2100 | case Primitive::kPrimFloat: |
| 2101 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2102 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2103 | break; |
| 2104 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2105 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2106 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2107 | } |
| 2108 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2109 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2112 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2113 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2114 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2115 | // the method_idx. |
| 2116 | HandleInvoke(invoke); |
| 2117 | } |
| 2118 | |
| 2119 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2120 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2121 | } |
| 2122 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2123 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2124 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2125 | // art::PrepareForRegisterAllocation. |
| 2126 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2127 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2128 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2129 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2130 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2131 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2132 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2133 | return; |
| 2134 | } |
| 2135 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2136 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2137 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2138 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2139 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2140 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2141 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2142 | } |
| 2143 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2144 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2145 | if (invoke->GetLocations()->Intrinsified()) { |
| 2146 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2147 | intrinsic.Dispatch(invoke); |
| 2148 | return true; |
| 2149 | } |
| 2150 | return false; |
| 2151 | } |
| 2152 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2153 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2154 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2155 | // art::PrepareForRegisterAllocation. |
| 2156 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2157 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2158 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2159 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2160 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2161 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2162 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2163 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2164 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2165 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2169 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2170 | if (intrinsic.TryDispatch(invoke)) { |
| 2171 | return; |
| 2172 | } |
| 2173 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2174 | HandleInvoke(invoke); |
| 2175 | } |
| 2176 | |
| 2177 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2178 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2179 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2182 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2183 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2184 | return; |
| 2185 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2186 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2187 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2188 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2189 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2192 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2193 | // This call to HandleInvoke allocates a temporary (core) register |
| 2194 | // which is also used to transfer the hidden argument from FP to |
| 2195 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2196 | HandleInvoke(invoke); |
| 2197 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2198 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2202 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2203 | LocationSummary* locations = invoke->GetLocations(); |
| 2204 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2205 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2206 | Location receiver = locations->InAt(0); |
| 2207 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2208 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2209 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2210 | // won't be modified thereafter, before the `call` instruction. |
| 2211 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2212 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2213 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2214 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2215 | if (receiver.IsStackSlot()) { |
| 2216 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2217 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2218 | __ movl(temp, Address(temp, class_offset)); |
| 2219 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2220 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2221 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2222 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2223 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2224 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2225 | // emit a read barrier for the previous class reference load. |
| 2226 | // However this is not required in practice, as this is an |
| 2227 | // intermediate/temporary reference and because the current |
| 2228 | // concurrent copying collector keeps the from-space memory |
| 2229 | // intact/accessible until the end of the marking phase (the |
| 2230 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2231 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2232 | // temp = temp->GetAddressOfIMT() |
| 2233 | __ movl(temp, |
| 2234 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2235 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2236 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2237 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2238 | __ movl(temp, Address(temp, method_offset)); |
| 2239 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2240 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2241 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2242 | |
| 2243 | DCHECK(!codegen_->IsLeafMethod()); |
| 2244 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2245 | } |
| 2246 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2247 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2248 | HandleInvoke(invoke); |
| 2249 | } |
| 2250 | |
| 2251 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2252 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2253 | } |
| 2254 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2255 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2256 | LocationSummary* locations = |
| 2257 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2258 | switch (neg->GetResultType()) { |
| 2259 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2260 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2262 | locations->SetOut(Location::SameAsFirstInput()); |
| 2263 | break; |
| 2264 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2265 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2266 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2267 | locations->SetOut(Location::SameAsFirstInput()); |
| 2268 | locations->AddTemp(Location::RequiresRegister()); |
| 2269 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2270 | break; |
| 2271 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2272 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2273 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2274 | locations->SetOut(Location::SameAsFirstInput()); |
| 2275 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2276 | break; |
| 2277 | |
| 2278 | default: |
| 2279 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2284 | LocationSummary* locations = neg->GetLocations(); |
| 2285 | Location out = locations->Out(); |
| 2286 | Location in = locations->InAt(0); |
| 2287 | switch (neg->GetResultType()) { |
| 2288 | case Primitive::kPrimInt: |
| 2289 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2290 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2291 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2292 | break; |
| 2293 | |
| 2294 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2295 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2296 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2297 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2298 | // Negation is similar to subtraction from zero. The least |
| 2299 | // significant byte triggers a borrow when it is different from |
| 2300 | // zero; to take it into account, add 1 to the most significant |
| 2301 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2302 | // operation. |
| 2303 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2304 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2305 | break; |
| 2306 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2307 | case Primitive::kPrimFloat: { |
| 2308 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2309 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2310 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2311 | // Implement float negation with an exclusive or with value |
| 2312 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2313 | // single-precision floating-point number). |
| 2314 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2315 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2316 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2317 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2318 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2319 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2320 | case Primitive::kPrimDouble: { |
| 2321 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2322 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2323 | // Implement double negation with an exclusive or with value |
| 2324 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2325 | // a double-precision floating-point number). |
| 2326 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2327 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2328 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2329 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2330 | |
| 2331 | default: |
| 2332 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2333 | } |
| 2334 | } |
| 2335 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2336 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2337 | LocationSummary* locations = |
| 2338 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2339 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2340 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2341 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2342 | locations->SetOut(Location::SameAsFirstInput()); |
| 2343 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2344 | } |
| 2345 | |
| 2346 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2347 | LocationSummary* locations = neg->GetLocations(); |
| 2348 | Location out = locations->Out(); |
| 2349 | DCHECK(locations->InAt(0).Equals(out)); |
| 2350 | |
| 2351 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2352 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2353 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2354 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2355 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2356 | } else { |
| 2357 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2358 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2359 | } |
| 2360 | } |
| 2361 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2362 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2363 | Primitive::Type result_type = conversion->GetResultType(); |
| 2364 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2365 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2366 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2367 | // The float-to-long and double-to-long type conversions rely on a |
| 2368 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2369 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2370 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2371 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2372 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2373 | : LocationSummary::kNoCall; |
| 2374 | LocationSummary* locations = |
| 2375 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2376 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2377 | // The Java language does not allow treating boolean as an integral type but |
| 2378 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2379 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2380 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2381 | case Primitive::kPrimByte: |
| 2382 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2383 | case Primitive::kPrimLong: { |
| 2384 | // Type conversion from long to byte is a result of code transformations. |
| 2385 | HInstruction* input = conversion->InputAt(0); |
| 2386 | Location input_location = input->IsConstant() |
| 2387 | ? Location::ConstantLocation(input->AsConstant()) |
| 2388 | : Location::RegisterPairLocation(EAX, EDX); |
| 2389 | locations->SetInAt(0, input_location); |
| 2390 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2391 | // the validation of the linear scan implementation |
| 2392 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2393 | break; |
| 2394 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2395 | case Primitive::kPrimBoolean: |
| 2396 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimShort: |
| 2398 | case Primitive::kPrimInt: |
| 2399 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2400 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2401 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2402 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2403 | // the validation of the linear scan implementation |
| 2404 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2405 | break; |
| 2406 | |
| 2407 | default: |
| 2408 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2409 | << " to " << result_type; |
| 2410 | } |
| 2411 | break; |
| 2412 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimShort: |
| 2414 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2415 | case Primitive::kPrimLong: |
| 2416 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2417 | case Primitive::kPrimBoolean: |
| 2418 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2419 | case Primitive::kPrimByte: |
| 2420 | case Primitive::kPrimInt: |
| 2421 | case Primitive::kPrimChar: |
| 2422 | // Processing a Dex `int-to-short' instruction. |
| 2423 | locations->SetInAt(0, Location::Any()); |
| 2424 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2425 | break; |
| 2426 | |
| 2427 | default: |
| 2428 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2429 | << " to " << result_type; |
| 2430 | } |
| 2431 | break; |
| 2432 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimInt: |
| 2434 | switch (input_type) { |
| 2435 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2436 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2437 | locations->SetInAt(0, Location::Any()); |
| 2438 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2439 | break; |
| 2440 | |
| 2441 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2442 | // Processing a Dex `float-to-int' instruction. |
| 2443 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2444 | locations->SetOut(Location::RequiresRegister()); |
| 2445 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2446 | break; |
| 2447 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2448 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2449 | // Processing a Dex `double-to-int' instruction. |
| 2450 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2451 | locations->SetOut(Location::RequiresRegister()); |
| 2452 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2453 | break; |
| 2454 | |
| 2455 | default: |
| 2456 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2457 | << " to " << result_type; |
| 2458 | } |
| 2459 | break; |
| 2460 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2461 | case Primitive::kPrimLong: |
| 2462 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2463 | case Primitive::kPrimBoolean: |
| 2464 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2465 | case Primitive::kPrimByte: |
| 2466 | case Primitive::kPrimShort: |
| 2467 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2468 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2469 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2470 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2471 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2472 | break; |
| 2473 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2474 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2475 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2476 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2477 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2478 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2479 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2480 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2481 | // The runtime helper puts the result in EAX, EDX. |
| 2482 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2483 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2484 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2485 | |
| 2486 | default: |
| 2487 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2488 | << " to " << result_type; |
| 2489 | } |
| 2490 | break; |
| 2491 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2492 | case Primitive::kPrimChar: |
| 2493 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2494 | case Primitive::kPrimLong: |
| 2495 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2496 | case Primitive::kPrimBoolean: |
| 2497 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2498 | case Primitive::kPrimByte: |
| 2499 | case Primitive::kPrimShort: |
| 2500 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2501 | // Processing a Dex `int-to-char' instruction. |
| 2502 | locations->SetInAt(0, Location::Any()); |
| 2503 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2504 | break; |
| 2505 | |
| 2506 | default: |
| 2507 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2508 | << " to " << result_type; |
| 2509 | } |
| 2510 | break; |
| 2511 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2512 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2513 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimBoolean: |
| 2515 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimByte: |
| 2517 | case Primitive::kPrimShort: |
| 2518 | case Primitive::kPrimInt: |
| 2519 | case Primitive::kPrimChar: |
| 2520 | // Processing a Dex `int-to-float' instruction. |
| 2521 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2522 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2523 | break; |
| 2524 | |
| 2525 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2526 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2527 | locations->SetInAt(0, Location::Any()); |
| 2528 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2529 | break; |
| 2530 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2532 | // Processing a Dex `double-to-float' instruction. |
| 2533 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2534 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | |
| 2537 | default: |
| 2538 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2539 | << " to " << result_type; |
| 2540 | }; |
| 2541 | break; |
| 2542 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2543 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2544 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2545 | case Primitive::kPrimBoolean: |
| 2546 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2547 | case Primitive::kPrimByte: |
| 2548 | case Primitive::kPrimShort: |
| 2549 | case Primitive::kPrimInt: |
| 2550 | case Primitive::kPrimChar: |
| 2551 | // Processing a Dex `int-to-double' instruction. |
| 2552 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2553 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2554 | break; |
| 2555 | |
| 2556 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2557 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2558 | locations->SetInAt(0, Location::Any()); |
| 2559 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2560 | break; |
| 2561 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2563 | // Processing a Dex `float-to-double' instruction. |
| 2564 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2565 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2566 | break; |
| 2567 | |
| 2568 | default: |
| 2569 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2570 | << " to " << result_type; |
| 2571 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2572 | break; |
| 2573 | |
| 2574 | default: |
| 2575 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2576 | << " to " << result_type; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2581 | LocationSummary* locations = conversion->GetLocations(); |
| 2582 | Location out = locations->Out(); |
| 2583 | Location in = locations->InAt(0); |
| 2584 | Primitive::Type result_type = conversion->GetResultType(); |
| 2585 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2586 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2587 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimByte: |
| 2589 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimLong: |
| 2591 | // Type conversion from long to byte is a result of code transformations. |
| 2592 | if (in.IsRegisterPair()) { |
| 2593 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2594 | } else { |
| 2595 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2596 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2597 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2598 | } |
| 2599 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2600 | case Primitive::kPrimBoolean: |
| 2601 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimShort: |
| 2603 | case Primitive::kPrimInt: |
| 2604 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2605 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2606 | if (in.IsRegister()) { |
| 2607 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2608 | } else { |
| 2609 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2610 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2611 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2612 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2613 | break; |
| 2614 | |
| 2615 | default: |
| 2616 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2617 | << " to " << result_type; |
| 2618 | } |
| 2619 | break; |
| 2620 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2621 | case Primitive::kPrimShort: |
| 2622 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2623 | case Primitive::kPrimLong: |
| 2624 | // Type conversion from long to short is a result of code transformations. |
| 2625 | if (in.IsRegisterPair()) { |
| 2626 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2627 | } else if (in.IsDoubleStackSlot()) { |
| 2628 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2629 | } else { |
| 2630 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2631 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2632 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2633 | } |
| 2634 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2635 | case Primitive::kPrimBoolean: |
| 2636 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimByte: |
| 2638 | case Primitive::kPrimInt: |
| 2639 | case Primitive::kPrimChar: |
| 2640 | // Processing a Dex `int-to-short' instruction. |
| 2641 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2642 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2643 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2644 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2645 | } else { |
| 2646 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2647 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2648 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2649 | } |
| 2650 | break; |
| 2651 | |
| 2652 | default: |
| 2653 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2654 | << " to " << result_type; |
| 2655 | } |
| 2656 | break; |
| 2657 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2658 | case Primitive::kPrimInt: |
| 2659 | switch (input_type) { |
| 2660 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2661 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2662 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2663 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2664 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2665 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2666 | } else { |
| 2667 | DCHECK(in.IsConstant()); |
| 2668 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2669 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2670 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2671 | } |
| 2672 | break; |
| 2673 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2674 | case Primitive::kPrimFloat: { |
| 2675 | // Processing a Dex `float-to-int' instruction. |
| 2676 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2677 | Register output = out.AsRegister<Register>(); |
| 2678 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2679 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2680 | |
| 2681 | __ movl(output, Immediate(kPrimIntMax)); |
| 2682 | // temp = int-to-float(output) |
| 2683 | __ cvtsi2ss(temp, output); |
| 2684 | // if input >= temp goto done |
| 2685 | __ comiss(input, temp); |
| 2686 | __ j(kAboveEqual, &done); |
| 2687 | // if input == NaN goto nan |
| 2688 | __ j(kUnordered, &nan); |
| 2689 | // output = float-to-int-truncate(input) |
| 2690 | __ cvttss2si(output, input); |
| 2691 | __ jmp(&done); |
| 2692 | __ Bind(&nan); |
| 2693 | // output = 0 |
| 2694 | __ xorl(output, output); |
| 2695 | __ Bind(&done); |
| 2696 | break; |
| 2697 | } |
| 2698 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2699 | case Primitive::kPrimDouble: { |
| 2700 | // Processing a Dex `double-to-int' instruction. |
| 2701 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2702 | Register output = out.AsRegister<Register>(); |
| 2703 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2704 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2705 | |
| 2706 | __ movl(output, Immediate(kPrimIntMax)); |
| 2707 | // temp = int-to-double(output) |
| 2708 | __ cvtsi2sd(temp, output); |
| 2709 | // if input >= temp goto done |
| 2710 | __ comisd(input, temp); |
| 2711 | __ j(kAboveEqual, &done); |
| 2712 | // if input == NaN goto nan |
| 2713 | __ j(kUnordered, &nan); |
| 2714 | // output = double-to-int-truncate(input) |
| 2715 | __ cvttsd2si(output, input); |
| 2716 | __ jmp(&done); |
| 2717 | __ Bind(&nan); |
| 2718 | // output = 0 |
| 2719 | __ xorl(output, output); |
| 2720 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2721 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2722 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2723 | |
| 2724 | default: |
| 2725 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2726 | << " to " << result_type; |
| 2727 | } |
| 2728 | break; |
| 2729 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2730 | case Primitive::kPrimLong: |
| 2731 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2732 | case Primitive::kPrimBoolean: |
| 2733 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2734 | case Primitive::kPrimByte: |
| 2735 | case Primitive::kPrimShort: |
| 2736 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2737 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2738 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2739 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2740 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2741 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2742 | __ cdq(); |
| 2743 | break; |
| 2744 | |
| 2745 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2746 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2747 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2748 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2749 | break; |
| 2750 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2751 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2752 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2753 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2754 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2755 | break; |
| 2756 | |
| 2757 | default: |
| 2758 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2759 | << " to " << result_type; |
| 2760 | } |
| 2761 | break; |
| 2762 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2763 | case Primitive::kPrimChar: |
| 2764 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2765 | case Primitive::kPrimLong: |
| 2766 | // Type conversion from long to short is a result of code transformations. |
| 2767 | if (in.IsRegisterPair()) { |
| 2768 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2769 | } else if (in.IsDoubleStackSlot()) { |
| 2770 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2771 | } else { |
| 2772 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2773 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2774 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2775 | } |
| 2776 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2777 | case Primitive::kPrimBoolean: |
| 2778 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2779 | case Primitive::kPrimByte: |
| 2780 | case Primitive::kPrimShort: |
| 2781 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2782 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2783 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2784 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2785 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2786 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2787 | } else { |
| 2788 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2789 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2790 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2791 | } |
| 2792 | break; |
| 2793 | |
| 2794 | default: |
| 2795 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2796 | << " to " << result_type; |
| 2797 | } |
| 2798 | break; |
| 2799 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2800 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2801 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2802 | case Primitive::kPrimBoolean: |
| 2803 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2804 | case Primitive::kPrimByte: |
| 2805 | case Primitive::kPrimShort: |
| 2806 | case Primitive::kPrimInt: |
| 2807 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2808 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2809 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2810 | break; |
| 2811 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2812 | case Primitive::kPrimLong: { |
| 2813 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2814 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2815 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2816 | // Create stack space for the call to |
| 2817 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2818 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2819 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2820 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2821 | __ subl(ESP, Immediate(adjustment)); |
| 2822 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2823 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2824 | // Load the value to the FP stack, using temporaries if needed. |
| 2825 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2826 | |
| 2827 | if (out.IsStackSlot()) { |
| 2828 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2829 | } else { |
| 2830 | __ fstps(Address(ESP, 0)); |
| 2831 | Location stack_temp = Location::StackSlot(0); |
| 2832 | codegen_->Move32(out, stack_temp); |
| 2833 | } |
| 2834 | |
| 2835 | // Remove the temporary stack space we allocated. |
| 2836 | if (adjustment != 0) { |
| 2837 | __ addl(ESP, Immediate(adjustment)); |
| 2838 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2839 | break; |
| 2840 | } |
| 2841 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2842 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2843 | // Processing a Dex `double-to-float' instruction. |
| 2844 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | |
| 2847 | default: |
| 2848 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2849 | << " to " << result_type; |
| 2850 | }; |
| 2851 | break; |
| 2852 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2853 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2854 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2855 | case Primitive::kPrimBoolean: |
| 2856 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2857 | case Primitive::kPrimByte: |
| 2858 | case Primitive::kPrimShort: |
| 2859 | case Primitive::kPrimInt: |
| 2860 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2861 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2862 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2863 | break; |
| 2864 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2865 | case Primitive::kPrimLong: { |
| 2866 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2867 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2868 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2869 | // Create stack space for the call to |
| 2870 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2871 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2872 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2873 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2874 | __ subl(ESP, Immediate(adjustment)); |
| 2875 | } |
| 2876 | |
| 2877 | // Load the value to the FP stack, using temporaries if needed. |
| 2878 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2879 | |
| 2880 | if (out.IsDoubleStackSlot()) { |
| 2881 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2882 | } else { |
| 2883 | __ fstpl(Address(ESP, 0)); |
| 2884 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2885 | codegen_->Move64(out, stack_temp); |
| 2886 | } |
| 2887 | |
| 2888 | // Remove the temporary stack space we allocated. |
| 2889 | if (adjustment != 0) { |
| 2890 | __ addl(ESP, Immediate(adjustment)); |
| 2891 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2892 | break; |
| 2893 | } |
| 2894 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2895 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2896 | // Processing a Dex `float-to-double' instruction. |
| 2897 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2898 | break; |
| 2899 | |
| 2900 | default: |
| 2901 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2902 | << " to " << result_type; |
| 2903 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2904 | break; |
| 2905 | |
| 2906 | default: |
| 2907 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2908 | << " to " << result_type; |
| 2909 | } |
| 2910 | } |
| 2911 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2912 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2913 | LocationSummary* locations = |
| 2914 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2915 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2916 | case Primitive::kPrimInt: { |
| 2917 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2918 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2919 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2920 | break; |
| 2921 | } |
| 2922 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2923 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2924 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2925 | locations->SetInAt(1, Location::Any()); |
| 2926 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2927 | break; |
| 2928 | } |
| 2929 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2930 | case Primitive::kPrimFloat: |
| 2931 | case Primitive::kPrimDouble: { |
| 2932 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2933 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2934 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2935 | } else if (add->InputAt(1)->IsConstant()) { |
| 2936 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2937 | } else { |
| 2938 | locations->SetInAt(1, Location::Any()); |
| 2939 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2940 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2941 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2942 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2943 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2944 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2945 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2946 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2947 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2951 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2952 | Location first = locations->InAt(0); |
| 2953 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2954 | Location out = locations->Out(); |
| 2955 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2956 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2957 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2958 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2959 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2960 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2961 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2962 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2963 | } else { |
| 2964 | __ leal(out.AsRegister<Register>(), Address( |
| 2965 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2966 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2967 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2968 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2969 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2970 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2971 | } else { |
| 2972 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2973 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2974 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2975 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2976 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2977 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2978 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2982 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2983 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2984 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2985 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2986 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2987 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2988 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2989 | } else { |
| 2990 | DCHECK(second.IsConstant()) << second; |
| 2991 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2992 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2993 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2994 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2995 | break; |
| 2996 | } |
| 2997 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2998 | case Primitive::kPrimFloat: { |
| 2999 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3000 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3001 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3002 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3003 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3004 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3005 | codegen_->LiteralFloatAddress( |
| 3006 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3007 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3008 | } else { |
| 3009 | DCHECK(second.IsStackSlot()); |
| 3010 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3011 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3012 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | case Primitive::kPrimDouble: { |
| 3016 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3017 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3018 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3019 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3020 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3021 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3022 | codegen_->LiteralDoubleAddress( |
| 3023 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3024 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3025 | } else { |
| 3026 | DCHECK(second.IsDoubleStackSlot()); |
| 3027 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3028 | } |
| 3029 | break; |
| 3030 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3031 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3032 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3033 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3034 | } |
| 3035 | } |
| 3036 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3037 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3038 | LocationSummary* locations = |
| 3039 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3040 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3041 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3042 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3043 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3044 | locations->SetInAt(1, Location::Any()); |
| 3045 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3046 | break; |
| 3047 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3048 | case Primitive::kPrimFloat: |
| 3049 | case Primitive::kPrimDouble: { |
| 3050 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3051 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3052 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3053 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3054 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3055 | } else { |
| 3056 | locations->SetInAt(1, Location::Any()); |
| 3057 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3058 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3059 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3060 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3061 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3062 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3063 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3064 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3068 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3069 | Location first = locations->InAt(0); |
| 3070 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3071 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3072 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3073 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3074 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3075 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3076 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3077 | __ subl(first.AsRegister<Register>(), |
| 3078 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3079 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3080 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3081 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3082 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3086 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3087 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3088 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3089 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3090 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3091 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3092 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3093 | } else { |
| 3094 | DCHECK(second.IsConstant()) << second; |
| 3095 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3096 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3097 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3098 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3099 | break; |
| 3100 | } |
| 3101 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3102 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3103 | if (second.IsFpuRegister()) { |
| 3104 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3105 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3106 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3107 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3108 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3109 | codegen_->LiteralFloatAddress( |
| 3110 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3111 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3112 | } else { |
| 3113 | DCHECK(second.IsStackSlot()); |
| 3114 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3115 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3116 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3120 | if (second.IsFpuRegister()) { |
| 3121 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3122 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3123 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3124 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3125 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3126 | codegen_->LiteralDoubleAddress( |
| 3127 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3128 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3129 | } else { |
| 3130 | DCHECK(second.IsDoubleStackSlot()); |
| 3131 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3132 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3133 | break; |
| 3134 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3135 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3136 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3137 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3138 | } |
| 3139 | } |
| 3140 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3141 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3142 | LocationSummary* locations = |
| 3143 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3144 | switch (mul->GetResultType()) { |
| 3145 | case Primitive::kPrimInt: |
| 3146 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3147 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3148 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3149 | // Can use 3 operand multiply. |
| 3150 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3151 | } else { |
| 3152 | locations->SetOut(Location::SameAsFirstInput()); |
| 3153 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3154 | break; |
| 3155 | case Primitive::kPrimLong: { |
| 3156 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3157 | locations->SetInAt(1, Location::Any()); |
| 3158 | locations->SetOut(Location::SameAsFirstInput()); |
| 3159 | // Needed for imul on 32bits with 64bits output. |
| 3160 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3161 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3162 | break; |
| 3163 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3164 | case Primitive::kPrimFloat: |
| 3165 | case Primitive::kPrimDouble: { |
| 3166 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3167 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3168 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3169 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3170 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3171 | } else { |
| 3172 | locations->SetInAt(1, Location::Any()); |
| 3173 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3174 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3175 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3176 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3177 | |
| 3178 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3179 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3184 | LocationSummary* locations = mul->GetLocations(); |
| 3185 | Location first = locations->InAt(0); |
| 3186 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3187 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3188 | |
| 3189 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3190 | case Primitive::kPrimInt: |
| 3191 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3192 | // problems where the output may not be the same as the first operand. |
| 3193 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3194 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3195 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3196 | } else if (second.IsRegister()) { |
| 3197 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3198 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3199 | } else { |
| 3200 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3201 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3202 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3203 | } |
| 3204 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3205 | |
| 3206 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3207 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3208 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3209 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3210 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3211 | |
| 3212 | DCHECK_EQ(EAX, eax); |
| 3213 | DCHECK_EQ(EDX, edx); |
| 3214 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3215 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3216 | // output: in1 |
| 3217 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3218 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3219 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3220 | if (second.IsConstant()) { |
| 3221 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3222 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3223 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3224 | int32_t low_value = Low32Bits(value); |
| 3225 | int32_t high_value = High32Bits(value); |
| 3226 | Immediate low(low_value); |
| 3227 | Immediate high(high_value); |
| 3228 | |
| 3229 | __ movl(eax, high); |
| 3230 | // eax <- in1.lo * in2.hi |
| 3231 | __ imull(eax, in1_lo); |
| 3232 | // in1.hi <- in1.hi * in2.lo |
| 3233 | __ imull(in1_hi, low); |
| 3234 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3235 | __ addl(in1_hi, eax); |
| 3236 | // move in2_lo to eax to prepare for double precision |
| 3237 | __ movl(eax, low); |
| 3238 | // edx:eax <- in1.lo * in2.lo |
| 3239 | __ mull(in1_lo); |
| 3240 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3241 | __ addl(in1_hi, edx); |
| 3242 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3243 | __ movl(in1_lo, eax); |
| 3244 | } else if (second.IsRegisterPair()) { |
| 3245 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3246 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3247 | |
| 3248 | __ movl(eax, in2_hi); |
| 3249 | // eax <- in1.lo * in2.hi |
| 3250 | __ imull(eax, in1_lo); |
| 3251 | // in1.hi <- in1.hi * in2.lo |
| 3252 | __ imull(in1_hi, in2_lo); |
| 3253 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3254 | __ addl(in1_hi, eax); |
| 3255 | // move in1_lo to eax to prepare for double precision |
| 3256 | __ movl(eax, in1_lo); |
| 3257 | // edx:eax <- in1.lo * in2.lo |
| 3258 | __ mull(in2_lo); |
| 3259 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3260 | __ addl(in1_hi, edx); |
| 3261 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3262 | __ movl(in1_lo, eax); |
| 3263 | } else { |
| 3264 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3265 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3266 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3267 | |
| 3268 | __ movl(eax, in2_hi); |
| 3269 | // eax <- in1.lo * in2.hi |
| 3270 | __ imull(eax, in1_lo); |
| 3271 | // in1.hi <- in1.hi * in2.lo |
| 3272 | __ imull(in1_hi, in2_lo); |
| 3273 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3274 | __ addl(in1_hi, eax); |
| 3275 | // move in1_lo to eax to prepare for double precision |
| 3276 | __ movl(eax, in1_lo); |
| 3277 | // edx:eax <- in1.lo * in2.lo |
| 3278 | __ mull(in2_lo); |
| 3279 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3280 | __ addl(in1_hi, edx); |
| 3281 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3282 | __ movl(in1_lo, eax); |
| 3283 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3284 | |
| 3285 | break; |
| 3286 | } |
| 3287 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3288 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3289 | DCHECK(first.Equals(locations->Out())); |
| 3290 | if (second.IsFpuRegister()) { |
| 3291 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3292 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3293 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3294 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3295 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3296 | codegen_->LiteralFloatAddress( |
| 3297 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3298 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3299 | } else { |
| 3300 | DCHECK(second.IsStackSlot()); |
| 3301 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3302 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3303 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3307 | DCHECK(first.Equals(locations->Out())); |
| 3308 | if (second.IsFpuRegister()) { |
| 3309 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3310 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3311 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3312 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3313 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3314 | codegen_->LiteralDoubleAddress( |
| 3315 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3316 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3317 | } else { |
| 3318 | DCHECK(second.IsDoubleStackSlot()); |
| 3319 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3320 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3321 | break; |
| 3322 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3323 | |
| 3324 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3325 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3326 | } |
| 3327 | } |
| 3328 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3329 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3330 | uint32_t temp_offset, |
| 3331 | uint32_t stack_adjustment, |
| 3332 | bool is_fp, |
| 3333 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3334 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3335 | DCHECK(!is_wide); |
| 3336 | if (is_fp) { |
| 3337 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3338 | } else { |
| 3339 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3340 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3341 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3342 | DCHECK(is_wide); |
| 3343 | if (is_fp) { |
| 3344 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3345 | } else { |
| 3346 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3347 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3348 | } else { |
| 3349 | // 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] | 3350 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3351 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3352 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3353 | if (is_fp) { |
| 3354 | __ flds(Address(ESP, temp_offset)); |
| 3355 | } else { |
| 3356 | __ filds(Address(ESP, temp_offset)); |
| 3357 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3358 | } else { |
| 3359 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3360 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3361 | if (is_fp) { |
| 3362 | __ fldl(Address(ESP, temp_offset)); |
| 3363 | } else { |
| 3364 | __ fildl(Address(ESP, temp_offset)); |
| 3365 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3366 | } |
| 3367 | } |
| 3368 | } |
| 3369 | |
| 3370 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3371 | Primitive::Type type = rem->GetResultType(); |
| 3372 | bool is_float = type == Primitive::kPrimFloat; |
| 3373 | size_t elem_size = Primitive::ComponentSize(type); |
| 3374 | LocationSummary* locations = rem->GetLocations(); |
| 3375 | Location first = locations->InAt(0); |
| 3376 | Location second = locations->InAt(1); |
| 3377 | Location out = locations->Out(); |
| 3378 | |
| 3379 | // Create stack space for 2 elements. |
| 3380 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3381 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3382 | |
| 3383 | // 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] | 3384 | const bool is_wide = !is_float; |
| 3385 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3386 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3387 | |
| 3388 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3389 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3390 | __ Bind(&retry); |
| 3391 | __ fprem(); |
| 3392 | |
| 3393 | // Move FP status to AX. |
| 3394 | __ fstsw(); |
| 3395 | |
| 3396 | // And see if the argument reduction is complete. This is signaled by the |
| 3397 | // C2 FPU flag bit set to 0. |
| 3398 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3399 | __ j(kNotEqual, &retry); |
| 3400 | |
| 3401 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3402 | // Store FP top of stack to real stack. |
| 3403 | if (is_float) { |
| 3404 | __ fsts(Address(ESP, 0)); |
| 3405 | } else { |
| 3406 | __ fstl(Address(ESP, 0)); |
| 3407 | } |
| 3408 | |
| 3409 | // Pop the 2 items from the FP stack. |
| 3410 | __ fucompp(); |
| 3411 | |
| 3412 | // Load the value from the stack into an XMM register. |
| 3413 | DCHECK(out.IsFpuRegister()) << out; |
| 3414 | if (is_float) { |
| 3415 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3416 | } else { |
| 3417 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3418 | } |
| 3419 | |
| 3420 | // And remove the temporary stack space we allocated. |
| 3421 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3422 | } |
| 3423 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3424 | |
| 3425 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3426 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3427 | |
| 3428 | LocationSummary* locations = instruction->GetLocations(); |
| 3429 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3430 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3431 | |
| 3432 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3433 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3434 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3435 | |
| 3436 | DCHECK(imm == 1 || imm == -1); |
| 3437 | |
| 3438 | if (instruction->IsRem()) { |
| 3439 | __ xorl(out_register, out_register); |
| 3440 | } else { |
| 3441 | __ movl(out_register, input_register); |
| 3442 | if (imm == -1) { |
| 3443 | __ negl(out_register); |
| 3444 | } |
| 3445 | } |
| 3446 | } |
| 3447 | |
| 3448 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3449 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3450 | LocationSummary* locations = instruction->GetLocations(); |
| 3451 | |
| 3452 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3453 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3454 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3455 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3456 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3457 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3458 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3459 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3460 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3461 | __ testl(input_register, input_register); |
| 3462 | __ cmovl(kGreaterEqual, num, input_register); |
| 3463 | int shift = CTZ(imm); |
| 3464 | __ sarl(num, Immediate(shift)); |
| 3465 | |
| 3466 | if (imm < 0) { |
| 3467 | __ negl(num); |
| 3468 | } |
| 3469 | |
| 3470 | __ movl(out_register, num); |
| 3471 | } |
| 3472 | |
| 3473 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3474 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3475 | |
| 3476 | LocationSummary* locations = instruction->GetLocations(); |
| 3477 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3478 | |
| 3479 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3480 | Register out = locations->Out().AsRegister<Register>(); |
| 3481 | Register num; |
| 3482 | Register edx; |
| 3483 | |
| 3484 | if (instruction->IsDiv()) { |
| 3485 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3486 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3487 | } else { |
| 3488 | edx = locations->Out().AsRegister<Register>(); |
| 3489 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3490 | } |
| 3491 | |
| 3492 | DCHECK_EQ(EAX, eax); |
| 3493 | DCHECK_EQ(EDX, edx); |
| 3494 | if (instruction->IsDiv()) { |
| 3495 | DCHECK_EQ(EAX, out); |
| 3496 | } else { |
| 3497 | DCHECK_EQ(EDX, out); |
| 3498 | } |
| 3499 | |
| 3500 | int64_t magic; |
| 3501 | int shift; |
| 3502 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3503 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3504 | // Save the numerator. |
| 3505 | __ movl(num, eax); |
| 3506 | |
| 3507 | // EAX = magic |
| 3508 | __ movl(eax, Immediate(magic)); |
| 3509 | |
| 3510 | // EDX:EAX = magic * numerator |
| 3511 | __ imull(num); |
| 3512 | |
| 3513 | if (imm > 0 && magic < 0) { |
| 3514 | // EDX += num |
| 3515 | __ addl(edx, num); |
| 3516 | } else if (imm < 0 && magic > 0) { |
| 3517 | __ subl(edx, num); |
| 3518 | } |
| 3519 | |
| 3520 | // Shift if needed. |
| 3521 | if (shift != 0) { |
| 3522 | __ sarl(edx, Immediate(shift)); |
| 3523 | } |
| 3524 | |
| 3525 | // EDX += 1 if EDX < 0 |
| 3526 | __ movl(eax, edx); |
| 3527 | __ shrl(edx, Immediate(31)); |
| 3528 | __ addl(edx, eax); |
| 3529 | |
| 3530 | if (instruction->IsRem()) { |
| 3531 | __ movl(eax, num); |
| 3532 | __ imull(edx, Immediate(imm)); |
| 3533 | __ subl(eax, edx); |
| 3534 | __ movl(edx, eax); |
| 3535 | } else { |
| 3536 | __ movl(eax, edx); |
| 3537 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3538 | } |
| 3539 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3540 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3541 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3542 | |
| 3543 | LocationSummary* locations = instruction->GetLocations(); |
| 3544 | Location out = locations->Out(); |
| 3545 | Location first = locations->InAt(0); |
| 3546 | Location second = locations->InAt(1); |
| 3547 | bool is_div = instruction->IsDiv(); |
| 3548 | |
| 3549 | switch (instruction->GetResultType()) { |
| 3550 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3551 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3552 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3553 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3554 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3555 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3556 | |
| 3557 | if (imm == 0) { |
| 3558 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3559 | } else if (imm == 1 || imm == -1) { |
| 3560 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3561 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3562 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3563 | } else { |
| 3564 | DCHECK(imm <= -2 || imm >= 2); |
| 3565 | GenerateDivRemWithAnyConstant(instruction); |
| 3566 | } |
| 3567 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3568 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3569 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3570 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3571 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3572 | Register second_reg = second.AsRegister<Register>(); |
| 3573 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3574 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3575 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3576 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3577 | __ cmpl(second_reg, Immediate(-1)); |
| 3578 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3579 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3580 | // edx:eax <- sign-extended of eax |
| 3581 | __ cdq(); |
| 3582 | // eax = quotient, edx = remainder |
| 3583 | __ idivl(second_reg); |
| 3584 | __ Bind(slow_path->GetExitLabel()); |
| 3585 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3586 | break; |
| 3587 | } |
| 3588 | |
| 3589 | case Primitive::kPrimLong: { |
| 3590 | InvokeRuntimeCallingConvention calling_convention; |
| 3591 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3592 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3593 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3594 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3595 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3596 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3597 | |
| 3598 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3599 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3600 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3601 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3602 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3603 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3604 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3605 | break; |
| 3606 | } |
| 3607 | |
| 3608 | default: |
| 3609 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3610 | } |
| 3611 | } |
| 3612 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3613 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3614 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3615 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3616 | : LocationSummary::kNoCall; |
| 3617 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3618 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3619 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3620 | case Primitive::kPrimInt: { |
| 3621 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3622 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3623 | locations->SetOut(Location::SameAsFirstInput()); |
| 3624 | // Intel uses edx:eax as the dividend. |
| 3625 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3626 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3627 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3628 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3629 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3630 | locations->AddTemp(Location::RequiresRegister()); |
| 3631 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3632 | break; |
| 3633 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3634 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3635 | InvokeRuntimeCallingConvention calling_convention; |
| 3636 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3637 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3638 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3639 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3640 | // Runtime helper puts the result in EAX, EDX. |
| 3641 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3642 | break; |
| 3643 | } |
| 3644 | case Primitive::kPrimFloat: |
| 3645 | case Primitive::kPrimDouble: { |
| 3646 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3647 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3648 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3649 | } else if (div->InputAt(1)->IsConstant()) { |
| 3650 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3651 | } else { |
| 3652 | locations->SetInAt(1, Location::Any()); |
| 3653 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3654 | locations->SetOut(Location::SameAsFirstInput()); |
| 3655 | break; |
| 3656 | } |
| 3657 | |
| 3658 | default: |
| 3659 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3664 | LocationSummary* locations = div->GetLocations(); |
| 3665 | Location first = locations->InAt(0); |
| 3666 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3667 | |
| 3668 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3669 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3670 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3671 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3672 | break; |
| 3673 | } |
| 3674 | |
| 3675 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3676 | if (second.IsFpuRegister()) { |
| 3677 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3678 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3679 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3680 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3681 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3682 | codegen_->LiteralFloatAddress( |
| 3683 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3684 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3685 | } else { |
| 3686 | DCHECK(second.IsStackSlot()); |
| 3687 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3688 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3689 | break; |
| 3690 | } |
| 3691 | |
| 3692 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3693 | if (second.IsFpuRegister()) { |
| 3694 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3695 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3696 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3697 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3698 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3699 | codegen_->LiteralDoubleAddress( |
| 3700 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3701 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3702 | } else { |
| 3703 | DCHECK(second.IsDoubleStackSlot()); |
| 3704 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3705 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3706 | break; |
| 3707 | } |
| 3708 | |
| 3709 | default: |
| 3710 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3711 | } |
| 3712 | } |
| 3713 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3714 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3715 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3716 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3717 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3718 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3719 | : LocationSummary::kNoCall; |
| 3720 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3721 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3722 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3723 | case Primitive::kPrimInt: { |
| 3724 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3725 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3726 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3727 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3728 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3729 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3730 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3731 | locations->AddTemp(Location::RequiresRegister()); |
| 3732 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3733 | break; |
| 3734 | } |
| 3735 | case Primitive::kPrimLong: { |
| 3736 | InvokeRuntimeCallingConvention calling_convention; |
| 3737 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3738 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3739 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3740 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3741 | // Runtime helper puts the result in EAX, EDX. |
| 3742 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3743 | break; |
| 3744 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3745 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3746 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3747 | locations->SetInAt(0, Location::Any()); |
| 3748 | locations->SetInAt(1, Location::Any()); |
| 3749 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3750 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3751 | break; |
| 3752 | } |
| 3753 | |
| 3754 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3755 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3756 | } |
| 3757 | } |
| 3758 | |
| 3759 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3760 | Primitive::Type type = rem->GetResultType(); |
| 3761 | switch (type) { |
| 3762 | case Primitive::kPrimInt: |
| 3763 | case Primitive::kPrimLong: { |
| 3764 | GenerateDivRemIntegral(rem); |
| 3765 | break; |
| 3766 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3767 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3768 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3769 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3770 | break; |
| 3771 | } |
| 3772 | default: |
| 3773 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3774 | } |
| 3775 | } |
| 3776 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3777 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3778 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3779 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3780 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3781 | case Primitive::kPrimByte: |
| 3782 | case Primitive::kPrimChar: |
| 3783 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3784 | case Primitive::kPrimInt: { |
| 3785 | locations->SetInAt(0, Location::Any()); |
| 3786 | break; |
| 3787 | } |
| 3788 | case Primitive::kPrimLong: { |
| 3789 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3790 | if (!instruction->IsConstant()) { |
| 3791 | locations->AddTemp(Location::RequiresRegister()); |
| 3792 | } |
| 3793 | break; |
| 3794 | } |
| 3795 | default: |
| 3796 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3797 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3801 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3802 | codegen_->AddSlowPath(slow_path); |
| 3803 | |
| 3804 | LocationSummary* locations = instruction->GetLocations(); |
| 3805 | Location value = locations->InAt(0); |
| 3806 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3807 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3808 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3809 | case Primitive::kPrimByte: |
| 3810 | case Primitive::kPrimChar: |
| 3811 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3812 | case Primitive::kPrimInt: { |
| 3813 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3814 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3815 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3816 | } else if (value.IsStackSlot()) { |
| 3817 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3818 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3819 | } else { |
| 3820 | DCHECK(value.IsConstant()) << value; |
| 3821 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3822 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3823 | } |
| 3824 | } |
| 3825 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3826 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3827 | case Primitive::kPrimLong: { |
| 3828 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3829 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3830 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3831 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3832 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3833 | } else { |
| 3834 | DCHECK(value.IsConstant()) << value; |
| 3835 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3836 | __ jmp(slow_path->GetEntryLabel()); |
| 3837 | } |
| 3838 | } |
| 3839 | break; |
| 3840 | } |
| 3841 | default: |
| 3842 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3843 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3844 | } |
| 3845 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3846 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3847 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3848 | |
| 3849 | LocationSummary* locations = |
| 3850 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3851 | |
| 3852 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3853 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3854 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3855 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3856 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3857 | // The shift count needs to be in CL or a constant. |
| 3858 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3859 | locations->SetOut(Location::SameAsFirstInput()); |
| 3860 | break; |
| 3861 | } |
| 3862 | default: |
| 3863 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3868 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3869 | |
| 3870 | LocationSummary* locations = op->GetLocations(); |
| 3871 | Location first = locations->InAt(0); |
| 3872 | Location second = locations->InAt(1); |
| 3873 | DCHECK(first.Equals(locations->Out())); |
| 3874 | |
| 3875 | switch (op->GetResultType()) { |
| 3876 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3877 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3878 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3879 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3880 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3881 | DCHECK_EQ(ECX, second_reg); |
| 3882 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3883 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3884 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3885 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3886 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3887 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3888 | } |
| 3889 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3890 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3891 | if (shift == 0) { |
| 3892 | return; |
| 3893 | } |
| 3894 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3895 | if (op->IsShl()) { |
| 3896 | __ shll(first_reg, imm); |
| 3897 | } else if (op->IsShr()) { |
| 3898 | __ sarl(first_reg, imm); |
| 3899 | } else { |
| 3900 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3901 | } |
| 3902 | } |
| 3903 | break; |
| 3904 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3905 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3906 | if (second.IsRegister()) { |
| 3907 | Register second_reg = second.AsRegister<Register>(); |
| 3908 | DCHECK_EQ(ECX, second_reg); |
| 3909 | if (op->IsShl()) { |
| 3910 | GenerateShlLong(first, second_reg); |
| 3911 | } else if (op->IsShr()) { |
| 3912 | GenerateShrLong(first, second_reg); |
| 3913 | } else { |
| 3914 | GenerateUShrLong(first, second_reg); |
| 3915 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3916 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3917 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3918 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3919 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3920 | if (shift != 0) { |
| 3921 | if (op->IsShl()) { |
| 3922 | GenerateShlLong(first, shift); |
| 3923 | } else if (op->IsShr()) { |
| 3924 | GenerateShrLong(first, shift); |
| 3925 | } else { |
| 3926 | GenerateUShrLong(first, shift); |
| 3927 | } |
| 3928 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3929 | } |
| 3930 | break; |
| 3931 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3932 | default: |
| 3933 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3934 | } |
| 3935 | } |
| 3936 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3937 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3938 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3939 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3940 | if (shift == 1) { |
| 3941 | // This is just an addition. |
| 3942 | __ addl(low, low); |
| 3943 | __ adcl(high, high); |
| 3944 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3945 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3946 | codegen_->EmitParallelMoves( |
| 3947 | loc.ToLow(), |
| 3948 | loc.ToHigh(), |
| 3949 | Primitive::kPrimInt, |
| 3950 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3951 | loc.ToLow(), |
| 3952 | Primitive::kPrimInt); |
| 3953 | } else if (shift > 32) { |
| 3954 | // Low part becomes 0. High part is low part << (shift-32). |
| 3955 | __ movl(high, low); |
| 3956 | __ shll(high, Immediate(shift - 32)); |
| 3957 | __ xorl(low, low); |
| 3958 | } else { |
| 3959 | // Between 1 and 31. |
| 3960 | __ shld(high, low, Immediate(shift)); |
| 3961 | __ shll(low, Immediate(shift)); |
| 3962 | } |
| 3963 | } |
| 3964 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3965 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3966 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3967 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3968 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3969 | __ testl(shifter, Immediate(32)); |
| 3970 | __ j(kEqual, &done); |
| 3971 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3972 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3973 | __ Bind(&done); |
| 3974 | } |
| 3975 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3976 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3977 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3978 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3979 | if (shift == 32) { |
| 3980 | // Need to copy the sign. |
| 3981 | DCHECK_NE(low, high); |
| 3982 | __ movl(low, high); |
| 3983 | __ sarl(high, Immediate(31)); |
| 3984 | } else if (shift > 32) { |
| 3985 | DCHECK_NE(low, high); |
| 3986 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3987 | __ movl(low, high); |
| 3988 | __ sarl(high, Immediate(31)); |
| 3989 | __ sarl(low, Immediate(shift - 32)); |
| 3990 | } else { |
| 3991 | // Between 1 and 31. |
| 3992 | __ shrd(low, high, Immediate(shift)); |
| 3993 | __ sarl(high, Immediate(shift)); |
| 3994 | } |
| 3995 | } |
| 3996 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3997 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3998 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3999 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4000 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4001 | __ testl(shifter, Immediate(32)); |
| 4002 | __ j(kEqual, &done); |
| 4003 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4004 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4005 | __ Bind(&done); |
| 4006 | } |
| 4007 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4008 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4009 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4010 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4011 | if (shift == 32) { |
| 4012 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4013 | codegen_->EmitParallelMoves( |
| 4014 | loc.ToHigh(), |
| 4015 | loc.ToLow(), |
| 4016 | Primitive::kPrimInt, |
| 4017 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4018 | loc.ToHigh(), |
| 4019 | Primitive::kPrimInt); |
| 4020 | } else if (shift > 32) { |
| 4021 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4022 | __ movl(low, high); |
| 4023 | __ shrl(low, Immediate(shift - 32)); |
| 4024 | __ xorl(high, high); |
| 4025 | } else { |
| 4026 | // Between 1 and 31. |
| 4027 | __ shrd(low, high, Immediate(shift)); |
| 4028 | __ shrl(high, Immediate(shift)); |
| 4029 | } |
| 4030 | } |
| 4031 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4032 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4033 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4034 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4035 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4036 | __ testl(shifter, Immediate(32)); |
| 4037 | __ j(kEqual, &done); |
| 4038 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4039 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4040 | __ Bind(&done); |
| 4041 | } |
| 4042 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4043 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4044 | LocationSummary* locations = |
| 4045 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4046 | |
| 4047 | switch (ror->GetResultType()) { |
| 4048 | case Primitive::kPrimLong: |
| 4049 | // Add the temporary needed. |
| 4050 | locations->AddTemp(Location::RequiresRegister()); |
| 4051 | FALLTHROUGH_INTENDED; |
| 4052 | case Primitive::kPrimInt: |
| 4053 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4054 | // The shift count needs to be in CL (unless it is a constant). |
| 4055 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4056 | locations->SetOut(Location::SameAsFirstInput()); |
| 4057 | break; |
| 4058 | default: |
| 4059 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4060 | UNREACHABLE(); |
| 4061 | } |
| 4062 | } |
| 4063 | |
| 4064 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4065 | LocationSummary* locations = ror->GetLocations(); |
| 4066 | Location first = locations->InAt(0); |
| 4067 | Location second = locations->InAt(1); |
| 4068 | |
| 4069 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 4070 | Register first_reg = first.AsRegister<Register>(); |
| 4071 | if (second.IsRegister()) { |
| 4072 | Register second_reg = second.AsRegister<Register>(); |
| 4073 | __ rorl(first_reg, second_reg); |
| 4074 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4075 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4076 | __ rorl(first_reg, imm); |
| 4077 | } |
| 4078 | return; |
| 4079 | } |
| 4080 | |
| 4081 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 4082 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4083 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4084 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4085 | if (second.IsRegister()) { |
| 4086 | Register second_reg = second.AsRegister<Register>(); |
| 4087 | DCHECK_EQ(second_reg, ECX); |
| 4088 | __ movl(temp_reg, first_reg_hi); |
| 4089 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4090 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4091 | __ movl(temp_reg, first_reg_hi); |
| 4092 | __ testl(second_reg, Immediate(32)); |
| 4093 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4094 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4095 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4096 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4097 | if (shift_amt == 0) { |
| 4098 | // Already fine. |
| 4099 | return; |
| 4100 | } |
| 4101 | if (shift_amt == 32) { |
| 4102 | // Just swap. |
| 4103 | __ movl(temp_reg, first_reg_lo); |
| 4104 | __ movl(first_reg_lo, first_reg_hi); |
| 4105 | __ movl(first_reg_hi, temp_reg); |
| 4106 | return; |
| 4107 | } |
| 4108 | |
| 4109 | Immediate imm(shift_amt); |
| 4110 | // Save the constents of the low value. |
| 4111 | __ movl(temp_reg, first_reg_lo); |
| 4112 | |
| 4113 | // Shift right into low, feeding bits from high. |
| 4114 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4115 | |
| 4116 | // Shift right into high, feeding bits from the original low. |
| 4117 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4118 | |
| 4119 | // Swap if needed. |
| 4120 | if (shift_amt > 32) { |
| 4121 | __ movl(temp_reg, first_reg_lo); |
| 4122 | __ movl(first_reg_lo, first_reg_hi); |
| 4123 | __ movl(first_reg_hi, temp_reg); |
| 4124 | } |
| 4125 | } |
| 4126 | } |
| 4127 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4128 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4129 | HandleShift(shl); |
| 4130 | } |
| 4131 | |
| 4132 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4133 | HandleShift(shl); |
| 4134 | } |
| 4135 | |
| 4136 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4137 | HandleShift(shr); |
| 4138 | } |
| 4139 | |
| 4140 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4141 | HandleShift(shr); |
| 4142 | } |
| 4143 | |
| 4144 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4145 | HandleShift(ushr); |
| 4146 | } |
| 4147 | |
| 4148 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4149 | HandleShift(ushr); |
| 4150 | } |
| 4151 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4152 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4153 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4154 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4155 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4156 | if (instruction->IsStringAlloc()) { |
| 4157 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4158 | } else { |
| 4159 | InvokeRuntimeCallingConvention calling_convention; |
| 4160 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4161 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4165 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4166 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4167 | if (instruction->IsStringAlloc()) { |
| 4168 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4169 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4170 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4171 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4172 | __ call(Address(temp, code_offset.Int32Value())); |
| 4173 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4174 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4175 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4176 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4177 | DCHECK(!codegen_->IsLeafMethod()); |
| 4178 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4179 | } |
| 4180 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4181 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4182 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4183 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4184 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4185 | InvokeRuntimeCallingConvention calling_convention; |
| 4186 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4187 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4188 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4192 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4193 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex().index_)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4194 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4195 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4196 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4197 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4198 | DCHECK(!codegen_->IsLeafMethod()); |
| 4199 | } |
| 4200 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4201 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4202 | LocationSummary* locations = |
| 4203 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4204 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4205 | if (location.IsStackSlot()) { |
| 4206 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4207 | } else if (location.IsDoubleStackSlot()) { |
| 4208 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4209 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4210 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4211 | } |
| 4212 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4213 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4214 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4215 | } |
| 4216 | |
| 4217 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4218 | LocationSummary* locations = |
| 4219 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4220 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4221 | } |
| 4222 | |
| 4223 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4224 | } |
| 4225 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4226 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4227 | LocationSummary* locations = |
| 4228 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4230 | locations->SetOut(Location::RequiresRegister()); |
| 4231 | } |
| 4232 | |
| 4233 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4234 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4235 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4236 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4237 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4238 | __ movl(locations->Out().AsRegister<Register>(), |
| 4239 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4240 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4241 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4242 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4243 | __ movl(locations->Out().AsRegister<Register>(), |
| 4244 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4245 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4246 | // temp = temp->GetImtEntryAt(method_offset); |
| 4247 | __ movl(locations->Out().AsRegister<Register>(), |
| 4248 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4249 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4250 | } |
| 4251 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4252 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4253 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4254 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4255 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4256 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4257 | } |
| 4258 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4259 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4260 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4261 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4262 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4263 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4264 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4265 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4266 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4267 | break; |
| 4268 | |
| 4269 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4270 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4271 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4272 | break; |
| 4273 | |
| 4274 | default: |
| 4275 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4276 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4277 | } |
| 4278 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4279 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4280 | LocationSummary* locations = |
| 4281 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4282 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4283 | locations->SetOut(Location::SameAsFirstInput()); |
| 4284 | } |
| 4285 | |
| 4286 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4287 | LocationSummary* locations = bool_not->GetLocations(); |
| 4288 | Location in = locations->InAt(0); |
| 4289 | Location out = locations->Out(); |
| 4290 | DCHECK(in.Equals(out)); |
| 4291 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4292 | } |
| 4293 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4294 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4295 | LocationSummary* locations = |
| 4296 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4297 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4298 | case Primitive::kPrimBoolean: |
| 4299 | case Primitive::kPrimByte: |
| 4300 | case Primitive::kPrimShort: |
| 4301 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4302 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4303 | case Primitive::kPrimLong: { |
| 4304 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4305 | locations->SetInAt(1, Location::Any()); |
| 4306 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4307 | break; |
| 4308 | } |
| 4309 | case Primitive::kPrimFloat: |
| 4310 | case Primitive::kPrimDouble: { |
| 4311 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4312 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4313 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4314 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4315 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4316 | } else { |
| 4317 | locations->SetInAt(1, Location::Any()); |
| 4318 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4319 | locations->SetOut(Location::RequiresRegister()); |
| 4320 | break; |
| 4321 | } |
| 4322 | default: |
| 4323 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4324 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4328 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4329 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4330 | Location left = locations->InAt(0); |
| 4331 | Location right = locations->InAt(1); |
| 4332 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4333 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4334 | Condition less_cond = kLess; |
| 4335 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4336 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4337 | case Primitive::kPrimBoolean: |
| 4338 | case Primitive::kPrimByte: |
| 4339 | case Primitive::kPrimShort: |
| 4340 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4341 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4342 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4343 | break; |
| 4344 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4345 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4346 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4347 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4348 | int32_t val_low = 0; |
| 4349 | int32_t val_high = 0; |
| 4350 | bool right_is_const = false; |
| 4351 | |
| 4352 | if (right.IsConstant()) { |
| 4353 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4354 | right_is_const = true; |
| 4355 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4356 | val_low = Low32Bits(val); |
| 4357 | val_high = High32Bits(val); |
| 4358 | } |
| 4359 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4360 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4361 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4362 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4363 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4364 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4365 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4366 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4367 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4368 | __ j(kLess, &less); // Signed compare. |
| 4369 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4370 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4371 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4372 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4373 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4374 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4375 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4376 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4377 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4378 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4379 | break; |
| 4380 | } |
| 4381 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4382 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4383 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4384 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4385 | break; |
| 4386 | } |
| 4387 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4388 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4389 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4390 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4391 | break; |
| 4392 | } |
| 4393 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4394 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4395 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4396 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4397 | __ movl(out, Immediate(0)); |
| 4398 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4399 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4400 | |
| 4401 | __ Bind(&greater); |
| 4402 | __ movl(out, Immediate(1)); |
| 4403 | __ jmp(&done); |
| 4404 | |
| 4405 | __ Bind(&less); |
| 4406 | __ movl(out, Immediate(-1)); |
| 4407 | |
| 4408 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4409 | } |
| 4410 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4411 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4412 | LocationSummary* locations = |
| 4413 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4414 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4415 | locations->SetInAt(i, Location::Any()); |
| 4416 | } |
| 4417 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4418 | } |
| 4419 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4420 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4421 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4422 | } |
| 4423 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4424 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4425 | /* |
| 4426 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4427 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4428 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4429 | */ |
| 4430 | switch (kind) { |
| 4431 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4432 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4433 | break; |
| 4434 | } |
| 4435 | case MemBarrierKind::kAnyStore: |
| 4436 | case MemBarrierKind::kLoadAny: |
| 4437 | case MemBarrierKind::kStoreStore: { |
| 4438 | // nop |
| 4439 | break; |
| 4440 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4441 | case MemBarrierKind::kNTStoreStore: |
| 4442 | // Non-Temporal Store/Store needs an explicit fence. |
| 4443 | MemoryFence(/* non-temporal */ true); |
| 4444 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4445 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4446 | } |
| 4447 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4448 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4449 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4450 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4451 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4452 | |
| 4453 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4454 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4455 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4456 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4457 | if (GetGraph()->HasIrreducibleLoops() && |
| 4458 | (dispatch_info.method_load_kind == |
| 4459 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4460 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4461 | } |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 4462 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4463 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4464 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4465 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4466 | Register temp) { |
| 4467 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4468 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4469 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4470 | return location.AsRegister<Register>(); |
| 4471 | } |
| 4472 | // For intrinsics we allow any location, so it may be on the stack. |
| 4473 | if (!location.IsRegister()) { |
| 4474 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4475 | return temp; |
| 4476 | } |
| 4477 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4478 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4479 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4480 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4481 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4482 | if (slow_path != nullptr) { |
| 4483 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4484 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4485 | __ movl(temp, Address(ESP, stack_offset)); |
| 4486 | return temp; |
| 4487 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4488 | } |
| 4489 | return location.AsRegister<Register>(); |
| 4490 | } |
| 4491 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4492 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4493 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4494 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4495 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4496 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4497 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4498 | uint32_t offset = |
| 4499 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4500 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4501 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4502 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4504 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4505 | break; |
| 4506 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4507 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4508 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4509 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4510 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4511 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4512 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4513 | // Bind a new fixup label at the end of the "movl" insn. |
| 4514 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4515 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4516 | break; |
| 4517 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4518 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4519 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4520 | Register method_reg; |
| 4521 | Register reg = temp.AsRegister<Register>(); |
| 4522 | if (current_method.IsRegister()) { |
| 4523 | method_reg = current_method.AsRegister<Register>(); |
| 4524 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4525 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4526 | DCHECK(!current_method.IsValid()); |
| 4527 | method_reg = reg; |
| 4528 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4529 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4530 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4531 | __ movl(reg, Address(method_reg, |
| 4532 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4533 | // temp = temp[index_in_cache]; |
| 4534 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4535 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4536 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4537 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4538 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4540 | return callee_method; |
| 4541 | } |
| 4542 | |
| 4543 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4544 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4545 | |
| 4546 | switch (invoke->GetCodePtrLocation()) { |
| 4547 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4548 | __ call(GetFrameEntryLabel()); |
| 4549 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4550 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4551 | // (callee_method + offset_of_quick_compiled_code)() |
| 4552 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4553 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4554 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4555 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4559 | } |
| 4560 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4561 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4562 | Register temp = temp_in.AsRegister<Register>(); |
| 4563 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4564 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4565 | |
| 4566 | // Use the calling convention instead of the location of the receiver, as |
| 4567 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4568 | // slow path, the arguments have been moved to the right place, so here we are |
| 4569 | // guaranteed that the receiver is the first register of the calling convention. |
| 4570 | InvokeDexCallingConvention calling_convention; |
| 4571 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4572 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4573 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4574 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4575 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4576 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4577 | // emit a read barrier for the previous class reference load. |
| 4578 | // However this is not required in practice, as this is an |
| 4579 | // intermediate/temporary reference and because the current |
| 4580 | // concurrent copying collector keeps the from-space memory |
| 4581 | // intact/accessible until the end of the marking phase (the |
| 4582 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4583 | __ MaybeUnpoisonHeapReference(temp); |
| 4584 | // temp = temp->GetMethodAt(method_offset); |
| 4585 | __ movl(temp, Address(temp, method_offset)); |
| 4586 | // call temp->GetEntryPoint(); |
| 4587 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4588 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4589 | } |
| 4590 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4591 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4592 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4593 | simple_patches_.emplace_back(); |
| 4594 | __ Bind(&simple_patches_.back()); |
| 4595 | } |
| 4596 | } |
| 4597 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4598 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
| 4599 | DCHECK(GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4600 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4601 | __ Bind(&string_patches_.back().label); |
| 4602 | } |
| 4603 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4604 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4605 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4606 | __ Bind(&type_patches_.back().label); |
| 4607 | } |
| 4608 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4609 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4610 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4611 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4612 | return &string_patches_.back().label; |
| 4613 | } |
| 4614 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4615 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4616 | uint32_t element_offset) { |
| 4617 | // Add the patch entry and bind its label at the end of the instruction. |
| 4618 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4619 | return &pc_relative_dex_cache_patches_.back().label; |
| 4620 | } |
| 4621 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4622 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4623 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4624 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4625 | |
| 4626 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4627 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| 4628 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 4629 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4630 | for (const PatchInfo<Label>& info : infos) { |
| 4631 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4632 | linker_patches->push_back( |
| 4633 | Factory(literal_offset, &info.dex_file, GetMethodAddressOffset(), info.index)); |
| 4634 | } |
| 4635 | } |
| 4636 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4637 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4638 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4639 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4640 | pc_relative_dex_cache_patches_.size() + |
| 4641 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4642 | string_patches_.size() + |
| 4643 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4644 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4645 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 4646 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4647 | for (const Label& label : simple_patches_) { |
| 4648 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4649 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4650 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4651 | if (!GetCompilerOptions().IsBootImage()) { |
| 4652 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 4653 | } else if (GetCompilerOptions().GetCompilePic()) { |
| 4654 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4655 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4656 | for (const PatchInfo<Label>& info : string_patches_) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4657 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4658 | linker_patches->push_back( |
| 4659 | LinkerPatch::StringPatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4660 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4661 | } |
| 4662 | if (GetCompilerOptions().GetCompilePic()) { |
| 4663 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(type_patches_, linker_patches); |
| 4664 | } else { |
| 4665 | for (const PatchInfo<Label>& info : type_patches_) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [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::TypePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4668 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4669 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4670 | } |
| 4671 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4672 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4673 | Register card, |
| 4674 | Register object, |
| 4675 | Register value, |
| 4676 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4677 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4678 | if (value_can_be_null) { |
| 4679 | __ testl(value, value); |
| 4680 | __ j(kEqual, &is_null); |
| 4681 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4682 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4683 | __ movl(temp, object); |
| 4684 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4685 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4686 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4687 | if (value_can_be_null) { |
| 4688 | __ Bind(&is_null); |
| 4689 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4690 | } |
| 4691 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4692 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4693 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4694 | |
| 4695 | bool object_field_get_with_read_barrier = |
| 4696 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4697 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4698 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4699 | kEmitCompilerReadBarrier ? |
| 4700 | LocationSummary::kCallOnSlowPath : |
| 4701 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4702 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4703 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4704 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4705 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4706 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4707 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4708 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4709 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4710 | // The output overlaps in case of long: we don't want the low move |
| 4711 | // to overwrite the object's location. Likewise, in the case of |
| 4712 | // an object field get with read barriers enabled, we do not want |
| 4713 | // the move to overwrite the object's location, as we need it to emit |
| 4714 | // the read barrier. |
| 4715 | locations->SetOut( |
| 4716 | Location::RequiresRegister(), |
| 4717 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4718 | Location::kOutputOverlap : |
| 4719 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4720 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4721 | |
| 4722 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4723 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4724 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4725 | // load the temp into the XMM and then copy the XMM into the |
| 4726 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4727 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4728 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4729 | } |
| 4730 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4731 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4732 | const FieldInfo& field_info) { |
| 4733 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4734 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4735 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4736 | Location base_loc = locations->InAt(0); |
| 4737 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4738 | Location out = locations->Out(); |
| 4739 | bool is_volatile = field_info.IsVolatile(); |
| 4740 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4741 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4742 | |
| 4743 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4744 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4745 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4746 | break; |
| 4747 | } |
| 4748 | |
| 4749 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4750 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4751 | break; |
| 4752 | } |
| 4753 | |
| 4754 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4755 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4756 | break; |
| 4757 | } |
| 4758 | |
| 4759 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4760 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4761 | break; |
| 4762 | } |
| 4763 | |
| 4764 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4765 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4766 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4767 | |
| 4768 | case Primitive::kPrimNot: { |
| 4769 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4770 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4771 | // Note that a potential implicit null check is handled in this |
| 4772 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4773 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4774 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4775 | if (is_volatile) { |
| 4776 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4777 | } |
| 4778 | } else { |
| 4779 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4780 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4781 | if (is_volatile) { |
| 4782 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4783 | } |
| 4784 | // If read barriers are enabled, emit read barriers other than |
| 4785 | // Baker's using a slow path (and also unpoison the loaded |
| 4786 | // reference, if heap poisoning is enabled). |
| 4787 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4788 | } |
| 4789 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4790 | } |
| 4791 | |
| 4792 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4793 | if (is_volatile) { |
| 4794 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4795 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4796 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4797 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4798 | __ psrlq(temp, Immediate(32)); |
| 4799 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4800 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4801 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4802 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4803 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4804 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4805 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4806 | break; |
| 4807 | } |
| 4808 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4809 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4810 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4811 | break; |
| 4812 | } |
| 4813 | |
| 4814 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4815 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4816 | break; |
| 4817 | } |
| 4818 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4819 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4820 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4821 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4822 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4823 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4824 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4825 | // Potential implicit null checks, in the case of reference or |
| 4826 | // long fields, are handled in the previous switch statement. |
| 4827 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4828 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4829 | } |
| 4830 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4831 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4832 | if (field_type == Primitive::kPrimNot) { |
| 4833 | // Memory barriers, in the case of references, are also handled |
| 4834 | // in the previous switch statement. |
| 4835 | } else { |
| 4836 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4837 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4838 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4842 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4843 | |
| 4844 | LocationSummary* locations = |
| 4845 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4846 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4847 | bool is_volatile = field_info.IsVolatile(); |
| 4848 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4849 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4850 | || (field_type == Primitive::kPrimByte); |
| 4851 | |
| 4852 | // The register allocator does not support multiple |
| 4853 | // inputs that die at entry with one in a specific register. |
| 4854 | if (is_byte_type) { |
| 4855 | // Ensure the value is in a byte register. |
| 4856 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4857 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4858 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4859 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4860 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4861 | } else { |
| 4862 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4863 | } |
| 4864 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4865 | // 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] | 4866 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4867 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4868 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4869 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4870 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4871 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4872 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4873 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4874 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4875 | } else { |
| 4876 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4877 | |
| 4878 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4879 | // Temporary registers for the write barrier. |
| 4880 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4881 | // Ensure the card is in a byte register. |
| 4882 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4883 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4888 | const FieldInfo& field_info, |
| 4889 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4890 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4891 | |
| 4892 | LocationSummary* locations = instruction->GetLocations(); |
| 4893 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4894 | Location value = locations->InAt(1); |
| 4895 | bool is_volatile = field_info.IsVolatile(); |
| 4896 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4897 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4898 | bool needs_write_barrier = |
| 4899 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4900 | |
| 4901 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4902 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4905 | bool maybe_record_implicit_null_check_done = false; |
| 4906 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4907 | switch (field_type) { |
| 4908 | case Primitive::kPrimBoolean: |
| 4909 | case Primitive::kPrimByte: { |
| 4910 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4911 | break; |
| 4912 | } |
| 4913 | |
| 4914 | case Primitive::kPrimShort: |
| 4915 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4916 | if (value.IsConstant()) { |
| 4917 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4918 | __ movw(Address(base, offset), Immediate(v)); |
| 4919 | } else { |
| 4920 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4921 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4922 | break; |
| 4923 | } |
| 4924 | |
| 4925 | case Primitive::kPrimInt: |
| 4926 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4927 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4928 | // Note that in the case where `value` is a null reference, |
| 4929 | // we do not enter this block, as the reference does not |
| 4930 | // need poisoning. |
| 4931 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4932 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4933 | __ movl(temp, value.AsRegister<Register>()); |
| 4934 | __ PoisonHeapReference(temp); |
| 4935 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4936 | } else if (value.IsConstant()) { |
| 4937 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4938 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4939 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4940 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4941 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4942 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4943 | break; |
| 4944 | } |
| 4945 | |
| 4946 | case Primitive::kPrimLong: { |
| 4947 | if (is_volatile) { |
| 4948 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4949 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4950 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4951 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4952 | __ punpckldq(temp1, temp2); |
| 4953 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4954 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4955 | } else if (value.IsConstant()) { |
| 4956 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4957 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4958 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4959 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4960 | } else { |
| 4961 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4962 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4963 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4964 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4965 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4966 | break; |
| 4967 | } |
| 4968 | |
| 4969 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4970 | if (value.IsConstant()) { |
| 4971 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4972 | __ movl(Address(base, offset), Immediate(v)); |
| 4973 | } else { |
| 4974 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4975 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4976 | break; |
| 4977 | } |
| 4978 | |
| 4979 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4980 | if (value.IsConstant()) { |
| 4981 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4982 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4983 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4984 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4985 | maybe_record_implicit_null_check_done = true; |
| 4986 | } else { |
| 4987 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4988 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4989 | break; |
| 4990 | } |
| 4991 | |
| 4992 | case Primitive::kPrimVoid: |
| 4993 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4994 | UNREACHABLE(); |
| 4995 | } |
| 4996 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4997 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4998 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4999 | } |
| 5000 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5001 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5002 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5003 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5004 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5005 | } |
| 5006 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5007 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5008 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5013 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5014 | } |
| 5015 | |
| 5016 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5017 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5018 | } |
| 5019 | |
| 5020 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5021 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5022 | } |
| 5023 | |
| 5024 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5025 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5029 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5030 | } |
| 5031 | |
| 5032 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5033 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5034 | } |
| 5035 | |
| 5036 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5037 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5038 | } |
| 5039 | |
| 5040 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5041 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5042 | } |
| 5043 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5044 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5045 | HUnresolvedInstanceFieldGet* instruction) { |
| 5046 | FieldAccessCallingConventionX86 calling_convention; |
| 5047 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5048 | instruction, instruction->GetFieldType(), calling_convention); |
| 5049 | } |
| 5050 | |
| 5051 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5052 | HUnresolvedInstanceFieldGet* instruction) { |
| 5053 | FieldAccessCallingConventionX86 calling_convention; |
| 5054 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5055 | instruction->GetFieldType(), |
| 5056 | instruction->GetFieldIndex(), |
| 5057 | instruction->GetDexPc(), |
| 5058 | calling_convention); |
| 5059 | } |
| 5060 | |
| 5061 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5062 | HUnresolvedInstanceFieldSet* instruction) { |
| 5063 | FieldAccessCallingConventionX86 calling_convention; |
| 5064 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5065 | instruction, instruction->GetFieldType(), calling_convention); |
| 5066 | } |
| 5067 | |
| 5068 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5069 | HUnresolvedInstanceFieldSet* instruction) { |
| 5070 | FieldAccessCallingConventionX86 calling_convention; |
| 5071 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5072 | instruction->GetFieldType(), |
| 5073 | instruction->GetFieldIndex(), |
| 5074 | instruction->GetDexPc(), |
| 5075 | calling_convention); |
| 5076 | } |
| 5077 | |
| 5078 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5079 | HUnresolvedStaticFieldGet* instruction) { |
| 5080 | FieldAccessCallingConventionX86 calling_convention; |
| 5081 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5082 | instruction, instruction->GetFieldType(), calling_convention); |
| 5083 | } |
| 5084 | |
| 5085 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5086 | HUnresolvedStaticFieldGet* instruction) { |
| 5087 | FieldAccessCallingConventionX86 calling_convention; |
| 5088 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5089 | instruction->GetFieldType(), |
| 5090 | instruction->GetFieldIndex(), |
| 5091 | instruction->GetDexPc(), |
| 5092 | calling_convention); |
| 5093 | } |
| 5094 | |
| 5095 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5096 | HUnresolvedStaticFieldSet* instruction) { |
| 5097 | FieldAccessCallingConventionX86 calling_convention; |
| 5098 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5099 | instruction, instruction->GetFieldType(), calling_convention); |
| 5100 | } |
| 5101 | |
| 5102 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5103 | HUnresolvedStaticFieldSet* instruction) { |
| 5104 | FieldAccessCallingConventionX86 calling_convention; |
| 5105 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5106 | instruction->GetFieldType(), |
| 5107 | instruction->GetFieldIndex(), |
| 5108 | instruction->GetDexPc(), |
| 5109 | calling_convention); |
| 5110 | } |
| 5111 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5112 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5113 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5114 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5115 | ? Location::RequiresRegister() |
| 5116 | : Location::Any(); |
| 5117 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5118 | } |
| 5119 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5120 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5121 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5122 | return; |
| 5123 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5124 | LocationSummary* locations = instruction->GetLocations(); |
| 5125 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5126 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5127 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5128 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5129 | } |
| 5130 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5131 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5132 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5133 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5134 | |
| 5135 | LocationSummary* locations = instruction->GetLocations(); |
| 5136 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5137 | |
| 5138 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5139 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5140 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5141 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5142 | } else { |
| 5143 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5144 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5145 | __ jmp(slow_path->GetEntryLabel()); |
| 5146 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5147 | } |
| 5148 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5149 | } |
| 5150 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5151 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5152 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5153 | } |
| 5154 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5155 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5156 | bool object_array_get_with_read_barrier = |
| 5157 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5158 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5159 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5160 | object_array_get_with_read_barrier ? |
| 5161 | LocationSummary::kCallOnSlowPath : |
| 5162 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5163 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5164 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5165 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5166 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5167 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5168 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5169 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5170 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5171 | // The output overlaps in case of long: we don't want the low move |
| 5172 | // to overwrite the array's location. Likewise, in the case of an |
| 5173 | // object array get with read barriers enabled, we do not want the |
| 5174 | // move to overwrite the array's location, as we need it to emit |
| 5175 | // the read barrier. |
| 5176 | locations->SetOut( |
| 5177 | Location::RequiresRegister(), |
| 5178 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5179 | Location::kOutputOverlap : |
| 5180 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5181 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5185 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5186 | Location obj_loc = locations->InAt(0); |
| 5187 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5188 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5189 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5190 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5191 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5192 | Primitive::Type type = instruction->GetType(); |
| 5193 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5194 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5195 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5196 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5197 | break; |
| 5198 | } |
| 5199 | |
| 5200 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5201 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5202 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5203 | break; |
| 5204 | } |
| 5205 | |
| 5206 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5207 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5208 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5209 | break; |
| 5210 | } |
| 5211 | |
| 5212 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5213 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5214 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5215 | // Branch cases into compressed and uncompressed for each index's type. |
| 5216 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5217 | NearLabel done, not_compressed; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5218 | __ testl(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5219 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5220 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5221 | "Expecting 0=compressed, 1=uncompressed"); |
| 5222 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5223 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5224 | __ jmp(&done); |
| 5225 | __ Bind(¬_compressed); |
| 5226 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5227 | __ Bind(&done); |
| 5228 | } else { |
| 5229 | // Common case for charAt of array of char or when string compression's |
| 5230 | // feature is turned off. |
| 5231 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5232 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5233 | break; |
| 5234 | } |
| 5235 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5236 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5237 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5238 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5239 | break; |
| 5240 | } |
| 5241 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5242 | case Primitive::kPrimNot: { |
| 5243 | static_assert( |
| 5244 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5245 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5246 | // /* HeapReference<Object> */ out = |
| 5247 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5248 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5249 | // Note that a potential implicit null check is handled in this |
| 5250 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5251 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5252 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5253 | } else { |
| 5254 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5255 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5256 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5257 | // If read barriers are enabled, emit read barriers other than |
| 5258 | // Baker's using a slow path (and also unpoison the loaded |
| 5259 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5260 | if (index.IsConstant()) { |
| 5261 | uint32_t offset = |
| 5262 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5263 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5264 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5265 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5266 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5267 | } |
| 5268 | } |
| 5269 | break; |
| 5270 | } |
| 5271 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5272 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5273 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5274 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5275 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5276 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5277 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5278 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5279 | break; |
| 5280 | } |
| 5281 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5282 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5283 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5284 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5285 | break; |
| 5286 | } |
| 5287 | |
| 5288 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5289 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5290 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5291 | break; |
| 5292 | } |
| 5293 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5294 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5295 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5296 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5297 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5298 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5299 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5300 | // Potential implicit null checks, in the case of reference or |
| 5301 | // long arrays, are handled in the previous switch statement. |
| 5302 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5303 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5304 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5308 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5309 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5310 | bool needs_write_barrier = |
| 5311 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5312 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5313 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5314 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5315 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5316 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5317 | LocationSummary::kCallOnSlowPath : |
| 5318 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5319 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5320 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5321 | || (value_type == Primitive::kPrimByte); |
| 5322 | // We need the inputs to be different than the output in case of long operation. |
| 5323 | // In case of a byte operation, the register allocator does not support multiple |
| 5324 | // inputs that die at entry with one in a specific register. |
| 5325 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5326 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5327 | if (is_byte_type) { |
| 5328 | // Ensure the value is in a byte register. |
| 5329 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5330 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5331 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5332 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5333 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5334 | } |
| 5335 | if (needs_write_barrier) { |
| 5336 | // Temporary registers for the write barrier. |
| 5337 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5338 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5339 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5340 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5344 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5345 | Location array_loc = locations->InAt(0); |
| 5346 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5347 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5348 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5349 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5350 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5351 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5352 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5353 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5354 | bool needs_write_barrier = |
| 5355 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5356 | |
| 5357 | switch (value_type) { |
| 5358 | case Primitive::kPrimBoolean: |
| 5359 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5360 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5361 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5362 | if (value.IsRegister()) { |
| 5363 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5364 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5365 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5366 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5367 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5368 | break; |
| 5369 | } |
| 5370 | |
| 5371 | case Primitive::kPrimShort: |
| 5372 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5373 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5374 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5375 | if (value.IsRegister()) { |
| 5376 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5377 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5378 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5379 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5380 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5381 | break; |
| 5382 | } |
| 5383 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5384 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5385 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5386 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5387 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5388 | if (!value.IsRegister()) { |
| 5389 | // Just setting null. |
| 5390 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5391 | DCHECK(value.IsConstant()) << value; |
| 5392 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5393 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5394 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5395 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5396 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5397 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5398 | |
| 5399 | DCHECK(needs_write_barrier); |
| 5400 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5401 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5402 | // short when Baker read barriers are enabled. |
| 5403 | Label done; |
| 5404 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5405 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5406 | Location temp_loc = locations->GetTemp(0); |
| 5407 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5408 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5409 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5410 | codegen_->AddSlowPath(slow_path); |
| 5411 | if (instruction->GetValueCanBeNull()) { |
| 5412 | __ testl(register_value, register_value); |
| 5413 | __ j(kNotEqual, ¬_null); |
| 5414 | __ movl(address, Immediate(0)); |
| 5415 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5416 | __ jmp(&done); |
| 5417 | __ Bind(¬_null); |
| 5418 | } |
| 5419 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5420 | // Note that when Baker read barriers are enabled, the type |
| 5421 | // checks are performed without read barriers. This is fine, |
| 5422 | // even in the case where a class object is in the from-space |
| 5423 | // after the flip, as a comparison involving such a type would |
| 5424 | // not produce a false positive; it may of course produce a |
| 5425 | // false negative, in which case we would take the ArraySet |
| 5426 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5427 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5428 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5429 | __ movl(temp, Address(array, class_offset)); |
| 5430 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5431 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5432 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5433 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5434 | __ movl(temp, Address(temp, component_offset)); |
| 5435 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5436 | // nor the object reference in `register_value->klass`, as |
| 5437 | // we are comparing two poisoned references. |
| 5438 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5439 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5440 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5441 | __ j(kEqual, &do_put); |
| 5442 | // If heap poisoning is enabled, the `temp` reference has |
| 5443 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5444 | __ MaybeUnpoisonHeapReference(temp); |
| 5445 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5446 | // If heap poisoning is enabled, no need to unpoison the |
| 5447 | // heap reference loaded below, as it is only used for a |
| 5448 | // comparison with null. |
| 5449 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5450 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5451 | __ Bind(&do_put); |
| 5452 | } else { |
| 5453 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5454 | } |
| 5455 | } |
| 5456 | |
| 5457 | if (kPoisonHeapReferences) { |
| 5458 | __ movl(temp, register_value); |
| 5459 | __ PoisonHeapReference(temp); |
| 5460 | __ movl(address, temp); |
| 5461 | } else { |
| 5462 | __ movl(address, register_value); |
| 5463 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5464 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5465 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5466 | } |
| 5467 | |
| 5468 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5469 | codegen_->MarkGCCard( |
| 5470 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5471 | __ Bind(&done); |
| 5472 | |
| 5473 | if (slow_path != nullptr) { |
| 5474 | __ Bind(slow_path->GetExitLabel()); |
| 5475 | } |
| 5476 | |
| 5477 | break; |
| 5478 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5479 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5480 | case Primitive::kPrimInt: { |
| 5481 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5482 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5483 | if (value.IsRegister()) { |
| 5484 | __ movl(address, value.AsRegister<Register>()); |
| 5485 | } else { |
| 5486 | DCHECK(value.IsConstant()) << value; |
| 5487 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5488 | __ movl(address, Immediate(v)); |
| 5489 | } |
| 5490 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5491 | break; |
| 5492 | } |
| 5493 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5494 | case Primitive::kPrimLong: { |
| 5495 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5496 | if (value.IsRegisterPair()) { |
| 5497 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5498 | value.AsRegisterPairLow<Register>()); |
| 5499 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5500 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5501 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5502 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5503 | DCHECK(value.IsConstant()); |
| 5504 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5505 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5506 | Immediate(Low32Bits(val))); |
| 5507 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5508 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5509 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5510 | } |
| 5511 | break; |
| 5512 | } |
| 5513 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5514 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5515 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5516 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5517 | if (value.IsFpuRegister()) { |
| 5518 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5519 | } else { |
| 5520 | DCHECK(value.IsConstant()); |
| 5521 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5522 | __ movl(address, Immediate(v)); |
| 5523 | } |
| 5524 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5525 | break; |
| 5526 | } |
| 5527 | |
| 5528 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5529 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5530 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5531 | if (value.IsFpuRegister()) { |
| 5532 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5533 | } else { |
| 5534 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5535 | Address address_hi = |
| 5536 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5537 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5538 | __ movl(address, Immediate(Low32Bits(v))); |
| 5539 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5540 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5541 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5542 | break; |
| 5543 | } |
| 5544 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5545 | case Primitive::kPrimVoid: |
| 5546 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5547 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5548 | } |
| 5549 | } |
| 5550 | |
| 5551 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5552 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5553 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5554 | if (!instruction->IsEmittedAtUseSite()) { |
| 5555 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5556 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5557 | } |
| 5558 | |
| 5559 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5560 | if (instruction->IsEmittedAtUseSite()) { |
| 5561 | return; |
| 5562 | } |
| 5563 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5564 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5565 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5566 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5567 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5568 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5569 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5570 | // Mask out most significant bit in case the array is String's array of char. |
| 5571 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5572 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5573 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5577 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5578 | InvokeRuntimeCallingConvention calling_convention; |
| 5579 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5580 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5581 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5582 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5583 | HInstruction* length = instruction->InputAt(1); |
| 5584 | if (!length->IsEmittedAtUseSite()) { |
| 5585 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5586 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5587 | // Need register to see array's length. |
| 5588 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5589 | locations->AddTemp(Location::RequiresRegister()); |
| 5590 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5591 | } |
| 5592 | |
| 5593 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5594 | const bool is_string_compressed_char_at = |
| 5595 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5596 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5597 | Location index_loc = locations->InAt(0); |
| 5598 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5599 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5600 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5601 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5602 | if (length_loc.IsConstant()) { |
| 5603 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5604 | if (index_loc.IsConstant()) { |
| 5605 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5606 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5607 | if (index < 0 || index >= length) { |
| 5608 | codegen_->AddSlowPath(slow_path); |
| 5609 | __ jmp(slow_path->GetEntryLabel()); |
| 5610 | } else { |
| 5611 | // Some optimization after BCE may have generated this, and we should not |
| 5612 | // generate a bounds check if it is a valid range. |
| 5613 | } |
| 5614 | return; |
| 5615 | } |
| 5616 | |
| 5617 | // We have to reverse the jump condition because the length is the constant. |
| 5618 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5619 | __ cmpl(index_reg, Immediate(length)); |
| 5620 | codegen_->AddSlowPath(slow_path); |
| 5621 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5622 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5623 | HInstruction* array_length = instruction->InputAt(1); |
| 5624 | if (array_length->IsEmittedAtUseSite()) { |
| 5625 | // Address the length field in the array. |
| 5626 | DCHECK(array_length->IsArrayLength()); |
| 5627 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5628 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5629 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5630 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5631 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5632 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5633 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5634 | __ movl(length_reg, array_len); |
| 5635 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5636 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5637 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5638 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5639 | // Checking bounds for general case: |
| 5640 | // Array of char or string's array with feature compression off. |
| 5641 | if (index_loc.IsConstant()) { |
| 5642 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5643 | __ cmpl(array_len, Immediate(value)); |
| 5644 | } else { |
| 5645 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5646 | } |
| 5647 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5648 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5649 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5650 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5651 | } |
| 5652 | codegen_->AddSlowPath(slow_path); |
| 5653 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5654 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5655 | } |
| 5656 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5657 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5658 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5662 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5663 | } |
| 5664 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5665 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5666 | LocationSummary* locations = |
| 5667 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5668 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5672 | HBasicBlock* block = instruction->GetBlock(); |
| 5673 | if (block->GetLoopInformation() != nullptr) { |
| 5674 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5675 | // The back edge will generate the suspend check. |
| 5676 | return; |
| 5677 | } |
| 5678 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5679 | // The goto will generate the suspend check. |
| 5680 | return; |
| 5681 | } |
| 5682 | GenerateSuspendCheck(instruction, nullptr); |
| 5683 | } |
| 5684 | |
| 5685 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5686 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5687 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5688 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5689 | if (slow_path == nullptr) { |
| 5690 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5691 | instruction->SetSlowPath(slow_path); |
| 5692 | codegen_->AddSlowPath(slow_path); |
| 5693 | if (successor != nullptr) { |
| 5694 | DCHECK(successor->IsLoopHeader()); |
| 5695 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5696 | } |
| 5697 | } else { |
| 5698 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5699 | } |
| 5700 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5701 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5702 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5703 | if (successor == nullptr) { |
| 5704 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5705 | __ Bind(slow_path->GetReturnLabel()); |
| 5706 | } else { |
| 5707 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5708 | __ jmp(slow_path->GetEntryLabel()); |
| 5709 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5710 | } |
| 5711 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5712 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5713 | return codegen_->GetAssembler(); |
| 5714 | } |
| 5715 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5716 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5717 | ScratchRegisterScope ensure_scratch( |
| 5718 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5719 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5720 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5721 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5722 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5726 | ScratchRegisterScope ensure_scratch( |
| 5727 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5728 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5729 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5730 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5731 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5732 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5733 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5734 | } |
| 5735 | |
| 5736 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5737 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5738 | Location source = move->GetSource(); |
| 5739 | Location destination = move->GetDestination(); |
| 5740 | |
| 5741 | if (source.IsRegister()) { |
| 5742 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5743 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5744 | } else if (destination.IsFpuRegister()) { |
| 5745 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5746 | } else { |
| 5747 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5748 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5749 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5750 | } else if (source.IsRegisterPair()) { |
| 5751 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5752 | // Create stack space for 2 elements. |
| 5753 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5754 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5755 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5756 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5757 | // And remove the temporary stack space we allocated. |
| 5758 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5759 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5760 | if (destination.IsRegister()) { |
| 5761 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5762 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5763 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5764 | } else if (destination.IsRegisterPair()) { |
| 5765 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5766 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5767 | __ psrlq(src_reg, Immediate(32)); |
| 5768 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5769 | } else if (destination.IsStackSlot()) { |
| 5770 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5771 | } else { |
| 5772 | DCHECK(destination.IsDoubleStackSlot()); |
| 5773 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5774 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5775 | } else if (source.IsStackSlot()) { |
| 5776 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5777 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5778 | } else if (destination.IsFpuRegister()) { |
| 5779 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5780 | } else { |
| 5781 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5782 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5783 | } |
| 5784 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5785 | if (destination.IsRegisterPair()) { |
| 5786 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5787 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5788 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5789 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5790 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5791 | } else { |
| 5792 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5793 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5794 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5795 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5796 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5797 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5798 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5799 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5800 | if (value == 0) { |
| 5801 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5802 | } else { |
| 5803 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5804 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5805 | } else { |
| 5806 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5807 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5808 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5809 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5810 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5811 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5812 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5813 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5814 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5815 | if (value == 0) { |
| 5816 | // Easy handling of 0.0. |
| 5817 | __ xorps(dest, dest); |
| 5818 | } else { |
| 5819 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5820 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5821 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5822 | __ movl(temp, Immediate(value)); |
| 5823 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5824 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5825 | } else { |
| 5826 | DCHECK(destination.IsStackSlot()) << destination; |
| 5827 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5828 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5829 | } else if (constant->IsLongConstant()) { |
| 5830 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5831 | int32_t low_value = Low32Bits(value); |
| 5832 | int32_t high_value = High32Bits(value); |
| 5833 | Immediate low(low_value); |
| 5834 | Immediate high(high_value); |
| 5835 | if (destination.IsDoubleStackSlot()) { |
| 5836 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5837 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5838 | } else { |
| 5839 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5840 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5841 | } |
| 5842 | } else { |
| 5843 | DCHECK(constant->IsDoubleConstant()); |
| 5844 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5845 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5846 | int32_t low_value = Low32Bits(value); |
| 5847 | int32_t high_value = High32Bits(value); |
| 5848 | Immediate low(low_value); |
| 5849 | Immediate high(high_value); |
| 5850 | if (destination.IsFpuRegister()) { |
| 5851 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5852 | if (value == 0) { |
| 5853 | // Easy handling of 0.0. |
| 5854 | __ xorpd(dest, dest); |
| 5855 | } else { |
| 5856 | __ pushl(high); |
| 5857 | __ pushl(low); |
| 5858 | __ movsd(dest, Address(ESP, 0)); |
| 5859 | __ addl(ESP, Immediate(8)); |
| 5860 | } |
| 5861 | } else { |
| 5862 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5863 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5864 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5865 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5866 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5867 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5868 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5869 | } |
| 5870 | } |
| 5871 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5872 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5873 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5874 | ScratchRegisterScope ensure_scratch( |
| 5875 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5876 | |
| 5877 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5878 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5879 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5880 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5881 | } |
| 5882 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5883 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5884 | ScratchRegisterScope ensure_scratch( |
| 5885 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5886 | |
| 5887 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5888 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5889 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5890 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5891 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5892 | } |
| 5893 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5894 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5895 | ScratchRegisterScope ensure_scratch1( |
| 5896 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5897 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5898 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5899 | ScratchRegisterScope ensure_scratch2( |
| 5900 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5901 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5902 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5903 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5904 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5905 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5906 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5907 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5911 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5912 | Location source = move->GetSource(); |
| 5913 | Location destination = move->GetDestination(); |
| 5914 | |
| 5915 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5916 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5917 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5918 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5919 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5920 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5921 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5922 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5923 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5924 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5925 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5926 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5927 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5928 | // Use XOR Swap algorithm to avoid a temporary. |
| 5929 | DCHECK_NE(source.reg(), destination.reg()); |
| 5930 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5931 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5932 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5933 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5934 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5935 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5936 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5937 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5938 | // Take advantage of the 16 bytes in the XMM register. |
| 5939 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5940 | Address stack(ESP, destination.GetStackIndex()); |
| 5941 | // Load the double into the high doubleword. |
| 5942 | __ movhpd(reg, stack); |
| 5943 | |
| 5944 | // Store the low double into the destination. |
| 5945 | __ movsd(stack, reg); |
| 5946 | |
| 5947 | // Move the high double to the low double. |
| 5948 | __ psrldq(reg, Immediate(8)); |
| 5949 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5950 | // Take advantage of the 16 bytes in the XMM register. |
| 5951 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5952 | Address stack(ESP, source.GetStackIndex()); |
| 5953 | // Load the double into the high doubleword. |
| 5954 | __ movhpd(reg, stack); |
| 5955 | |
| 5956 | // Store the low double into the destination. |
| 5957 | __ movsd(stack, reg); |
| 5958 | |
| 5959 | // Move the high double to the low double. |
| 5960 | __ psrldq(reg, Immediate(8)); |
| 5961 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5962 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5963 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5964 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5965 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5966 | } |
| 5967 | } |
| 5968 | |
| 5969 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5970 | __ pushl(static_cast<Register>(reg)); |
| 5971 | } |
| 5972 | |
| 5973 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5974 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5975 | } |
| 5976 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5977 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 5978 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5979 | switch (desired_class_load_kind) { |
| 5980 | case HLoadClass::LoadKind::kReferrersClass: |
| 5981 | break; |
| 5982 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5983 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5984 | break; |
| 5985 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5986 | DCHECK(GetCompilerOptions().GetCompilePic()); |
Vladimir Marko | 48886c2 | 2017-01-06 11:45:47 +0000 | [diff] [blame^] | 5987 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5988 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5989 | // is incompatible with it. |
| 5990 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5991 | // with irreducible loops. |
| 5992 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5993 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5994 | } |
| 5995 | break; |
| 5996 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5997 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5998 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5999 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6000 | break; |
| 6001 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6002 | break; |
| 6003 | } |
| 6004 | return desired_class_load_kind; |
| 6005 | } |
| 6006 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6007 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6008 | if (cls->NeedsAccessCheck()) { |
| 6009 | InvokeRuntimeCallingConvention calling_convention; |
| 6010 | CodeGenerator::CreateLoadClassLocationSummary( |
| 6011 | cls, |
| 6012 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 6013 | Location::RegisterLocation(EAX), |
| 6014 | /* code_generator_supports_read_barrier */ true); |
| 6015 | return; |
| 6016 | } |
| 6017 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6018 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6019 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6020 | ? LocationSummary::kCallOnSlowPath |
| 6021 | : LocationSummary::kNoCall; |
| 6022 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6023 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6024 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6025 | } |
| 6026 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6027 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6028 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 6029 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
Vladimir Marko | 48886c2 | 2017-01-06 11:45:47 +0000 | [diff] [blame^] | 6030 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6031 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6032 | } |
| 6033 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6034 | } |
| 6035 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6036 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| 6037 | dex::TypeIndex dex_index, |
| 6038 | uint64_t address) { |
| 6039 | jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index), address); |
| 6040 | // Add a patch entry and return the label. |
| 6041 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 6042 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6043 | return &info->label; |
| 6044 | } |
| 6045 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6046 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6047 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6048 | if (cls->NeedsAccessCheck()) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6049 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex().index_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6050 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6051 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6052 | return; |
| 6053 | } |
| 6054 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6055 | Location out_loc = locations->Out(); |
| 6056 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6057 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6058 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6059 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6060 | ? kWithoutReadBarrier |
| 6061 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6062 | switch (cls->GetLoadKind()) { |
| 6063 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6064 | DCHECK(!cls->CanCallRuntime()); |
| 6065 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6066 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6067 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6068 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6069 | cls, |
| 6070 | out_loc, |
| 6071 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6072 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6073 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6074 | break; |
| 6075 | } |
| 6076 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6077 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6078 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6079 | codegen_->RecordTypePatch(cls); |
| 6080 | break; |
| 6081 | } |
| 6082 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6083 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6084 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6085 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6086 | codegen_->RecordTypePatch(cls); |
| 6087 | break; |
| 6088 | } |
| 6089 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6090 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6091 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6092 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6093 | __ movl(out, Immediate(address)); |
| 6094 | codegen_->RecordSimplePatch(); |
| 6095 | break; |
| 6096 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6097 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6098 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6099 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
| 6100 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetAddress()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6101 | // /* GcRoot<mirror::Class> */ out = *address |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6102 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6103 | break; |
| 6104 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6105 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 6106 | // /* GcRoot<mirror::Class>[] */ out = |
| 6107 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 6108 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6109 | __ movl(out, Address(current_method, |
| 6110 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 6111 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6112 | GenerateGcRootFieldLoad(cls, |
| 6113 | out_loc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6114 | Address(out, |
| 6115 | CodeGenerator::GetCacheOffset(cls->GetTypeIndex().index_)), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6116 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6117 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6118 | generate_null_check = !cls->IsInDexCache(); |
| 6119 | break; |
| 6120 | } |
| 6121 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6122 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6123 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6124 | DCHECK(cls->CanCallRuntime()); |
| 6125 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6126 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6127 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6128 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6129 | if (generate_null_check) { |
| 6130 | __ testl(out, out); |
| 6131 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6132 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6133 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6134 | if (cls->MustGenerateClinitCheck()) { |
| 6135 | GenerateClassInitializationCheck(slow_path, out); |
| 6136 | } else { |
| 6137 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6138 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6139 | } |
| 6140 | } |
| 6141 | |
| 6142 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6143 | LocationSummary* locations = |
| 6144 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6145 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6146 | if (check->HasUses()) { |
| 6147 | locations->SetOut(Location::SameAsFirstInput()); |
| 6148 | } |
| 6149 | } |
| 6150 | |
| 6151 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6152 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6153 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6154 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6155 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6156 | GenerateClassInitializationCheck(slow_path, |
| 6157 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6158 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6159 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6160 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6161 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6162 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6163 | Immediate(mirror::Class::kStatusInitialized)); |
| 6164 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6165 | __ Bind(slow_path->GetExitLabel()); |
| 6166 | // No need for memory fence, thanks to the X86 memory model. |
| 6167 | } |
| 6168 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6169 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6170 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6171 | switch (desired_string_load_kind) { |
| 6172 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6173 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6174 | break; |
| 6175 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6176 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6177 | FALLTHROUGH_INTENDED; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6178 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6179 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6180 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6181 | // is incompatible with it. |
| 6182 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6183 | // with irreducible loops. |
| 6184 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6185 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6186 | } |
| 6187 | break; |
| 6188 | case HLoadString::LoadKind::kBootImageAddress: |
| 6189 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6190 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6191 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6192 | case HLoadString::LoadKind::kJitTableAddress: |
| 6193 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6194 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6195 | } |
| 6196 | return desired_string_load_kind; |
| 6197 | } |
| 6198 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6199 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6200 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6201 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6202 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6203 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6204 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6205 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6206 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6207 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 6208 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6209 | } else { |
| 6210 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6211 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6212 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6213 | // Rely on the pResolveString and/or marking to save everything. |
| 6214 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6215 | InvokeRuntimeCallingConvention calling_convention; |
| 6216 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6217 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6218 | } else { |
| 6219 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6220 | } |
| 6221 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6222 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6225 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6226 | dex::StringIndex dex_index, |
| 6227 | Handle<mirror::String> handle) { |
| 6228 | jit_string_roots_.Overwrite( |
| 6229 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6230 | // Add a patch entry and return the label. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6231 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6232 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6233 | return &info->label; |
| 6234 | } |
| 6235 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6236 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6237 | // move. |
| 6238 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6239 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6240 | Location out_loc = locations->Out(); |
| 6241 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6242 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6243 | switch (load->GetLoadKind()) { |
| 6244 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6245 | __ movl(out, Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6246 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6247 | return; // No dex cache slow path. |
| 6248 | } |
| 6249 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6250 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6251 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6252 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6253 | return; // No dex cache slow path. |
| 6254 | } |
| 6255 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6256 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6257 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6258 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6259 | __ movl(out, Immediate(address)); |
| 6260 | codegen_->RecordSimplePatch(); |
| 6261 | return; // No dex cache slow path. |
| 6262 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6263 | case HLoadString::LoadKind::kBssEntry: { |
| 6264 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6265 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6266 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6267 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6268 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6269 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6270 | codegen_->AddSlowPath(slow_path); |
| 6271 | __ testl(out, out); |
| 6272 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6273 | __ Bind(slow_path->GetExitLabel()); |
| 6274 | return; |
| 6275 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6276 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6277 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6278 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6279 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6280 | // /* GcRoot<mirror::String> */ out = *address |
| 6281 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6282 | return; |
| 6283 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6284 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6285 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6286 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6287 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6288 | // 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] | 6289 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6290 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6291 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6292 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6293 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6294 | } |
| 6295 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6296 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6297 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6298 | } |
| 6299 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6300 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6301 | LocationSummary* locations = |
| 6302 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6303 | locations->SetOut(Location::RequiresRegister()); |
| 6304 | } |
| 6305 | |
| 6306 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6307 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6308 | } |
| 6309 | |
| 6310 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6311 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6312 | } |
| 6313 | |
| 6314 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6315 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6319 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6320 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6321 | InvokeRuntimeCallingConvention calling_convention; |
| 6322 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6323 | } |
| 6324 | |
| 6325 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6326 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6327 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6328 | } |
| 6329 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6330 | // Temp is used for read barrier. |
| 6331 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6332 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6333 | !kUseBakerReadBarrier && |
| 6334 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6335 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6336 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6337 | return 1; |
| 6338 | } |
| 6339 | return 0; |
| 6340 | } |
| 6341 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6342 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6343 | // interface pointer, one for loading the current interface. |
| 6344 | // The other checks have one temp for loading the object's class. |
| 6345 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6346 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6347 | return 2; |
| 6348 | } |
| 6349 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6350 | } |
| 6351 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6352 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6353 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6354 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6355 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6356 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6357 | case TypeCheckKind::kExactCheck: |
| 6358 | case TypeCheckKind::kAbstractClassCheck: |
| 6359 | case TypeCheckKind::kClassHierarchyCheck: |
| 6360 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6361 | call_kind = |
| 6362 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6363 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6364 | break; |
| 6365 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6366 | case TypeCheckKind::kUnresolvedCheck: |
| 6367 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6368 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6369 | break; |
| 6370 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6371 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6372 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6373 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6374 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6375 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6376 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6377 | locations->SetInAt(1, Location::Any()); |
| 6378 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6379 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6380 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6381 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6382 | } |
| 6383 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6384 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6385 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6386 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6387 | Location obj_loc = locations->InAt(0); |
| 6388 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6389 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6390 | Location out_loc = locations->Out(); |
| 6391 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6392 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6393 | DCHECK_LE(num_temps, 1u); |
| 6394 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6395 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6396 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6397 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6398 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6399 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6400 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6401 | |
| 6402 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6403 | // Avoid null check if we know obj is not null. |
| 6404 | if (instruction->MustDoNullCheck()) { |
| 6405 | __ testl(obj, obj); |
| 6406 | __ j(kEqual, &zero); |
| 6407 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6408 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6409 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6410 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6411 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6412 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6413 | out_loc, |
| 6414 | obj_loc, |
| 6415 | class_offset, |
| 6416 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6417 | if (cls.IsRegister()) { |
| 6418 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6419 | } else { |
| 6420 | DCHECK(cls.IsStackSlot()) << cls; |
| 6421 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6422 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6423 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6424 | // Classes must be equal for the instanceof to succeed. |
| 6425 | __ j(kNotEqual, &zero); |
| 6426 | __ movl(out, Immediate(1)); |
| 6427 | __ jmp(&done); |
| 6428 | break; |
| 6429 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6430 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6431 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6432 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6433 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6434 | out_loc, |
| 6435 | obj_loc, |
| 6436 | class_offset, |
| 6437 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6438 | // If the class is abstract, we eagerly fetch the super class of the |
| 6439 | // object to avoid doing a comparison we know will fail. |
| 6440 | NearLabel loop; |
| 6441 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6442 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6443 | GenerateReferenceLoadOneRegister(instruction, |
| 6444 | out_loc, |
| 6445 | super_offset, |
| 6446 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6447 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6448 | __ testl(out, out); |
| 6449 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6450 | __ j(kEqual, &done); |
| 6451 | if (cls.IsRegister()) { |
| 6452 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6453 | } else { |
| 6454 | DCHECK(cls.IsStackSlot()) << cls; |
| 6455 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6456 | } |
| 6457 | __ j(kNotEqual, &loop); |
| 6458 | __ movl(out, Immediate(1)); |
| 6459 | if (zero.IsLinked()) { |
| 6460 | __ jmp(&done); |
| 6461 | } |
| 6462 | break; |
| 6463 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6464 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6465 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6466 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6467 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6468 | out_loc, |
| 6469 | obj_loc, |
| 6470 | class_offset, |
| 6471 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6472 | // Walk over the class hierarchy to find a match. |
| 6473 | NearLabel loop, success; |
| 6474 | __ Bind(&loop); |
| 6475 | if (cls.IsRegister()) { |
| 6476 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6477 | } else { |
| 6478 | DCHECK(cls.IsStackSlot()) << cls; |
| 6479 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6480 | } |
| 6481 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6482 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6483 | GenerateReferenceLoadOneRegister(instruction, |
| 6484 | out_loc, |
| 6485 | super_offset, |
| 6486 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6487 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6488 | __ testl(out, out); |
| 6489 | __ j(kNotEqual, &loop); |
| 6490 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6491 | __ jmp(&done); |
| 6492 | __ Bind(&success); |
| 6493 | __ movl(out, Immediate(1)); |
| 6494 | if (zero.IsLinked()) { |
| 6495 | __ jmp(&done); |
| 6496 | } |
| 6497 | break; |
| 6498 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6499 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6500 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6501 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6502 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6503 | out_loc, |
| 6504 | obj_loc, |
| 6505 | class_offset, |
| 6506 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6507 | // Do an exact check. |
| 6508 | NearLabel exact_check; |
| 6509 | if (cls.IsRegister()) { |
| 6510 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6511 | } else { |
| 6512 | DCHECK(cls.IsStackSlot()) << cls; |
| 6513 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6514 | } |
| 6515 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6516 | // 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] | 6517 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6518 | GenerateReferenceLoadOneRegister(instruction, |
| 6519 | out_loc, |
| 6520 | component_offset, |
| 6521 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6522 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6523 | __ testl(out, out); |
| 6524 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6525 | __ j(kEqual, &done); |
| 6526 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6527 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6528 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6529 | __ movl(out, Immediate(1)); |
| 6530 | __ jmp(&done); |
| 6531 | break; |
| 6532 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6533 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6534 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6535 | // No read barrier since the slow path will retry upon failure. |
| 6536 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6537 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6538 | out_loc, |
| 6539 | obj_loc, |
| 6540 | class_offset, |
| 6541 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6542 | if (cls.IsRegister()) { |
| 6543 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6544 | } else { |
| 6545 | DCHECK(cls.IsStackSlot()) << cls; |
| 6546 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6547 | } |
| 6548 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6549 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6550 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6551 | codegen_->AddSlowPath(slow_path); |
| 6552 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6553 | __ movl(out, Immediate(1)); |
| 6554 | if (zero.IsLinked()) { |
| 6555 | __ jmp(&done); |
| 6556 | } |
| 6557 | break; |
| 6558 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6559 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6560 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6561 | case TypeCheckKind::kInterfaceCheck: { |
| 6562 | // 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] | 6563 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6564 | // cases. |
| 6565 | // |
| 6566 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6567 | // entry point without resorting to a type checking slow path |
| 6568 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6569 | // require to assign fixed registers for the inputs of this |
| 6570 | // HInstanceOf instruction (following the runtime calling |
| 6571 | // convention), which might be cluttered by the potential first |
| 6572 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6573 | // |
| 6574 | // TODO: Introduce a new runtime entry point taking the object |
| 6575 | // to test (instead of its class) as argument, and let it deal |
| 6576 | // with the read barrier issues. This will let us refactor this |
| 6577 | // case of the `switch` code as it was previously (with a direct |
| 6578 | // call to the runtime not using a type checking slow path). |
| 6579 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6580 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6581 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6582 | /* is_fatal */ false); |
| 6583 | codegen_->AddSlowPath(slow_path); |
| 6584 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6585 | if (zero.IsLinked()) { |
| 6586 | __ jmp(&done); |
| 6587 | } |
| 6588 | break; |
| 6589 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6590 | } |
| 6591 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6592 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6593 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6594 | __ xorl(out, out); |
| 6595 | } |
| 6596 | |
| 6597 | if (done.IsLinked()) { |
| 6598 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6599 | } |
| 6600 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6601 | if (slow_path != nullptr) { |
| 6602 | __ Bind(slow_path->GetExitLabel()); |
| 6603 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6604 | } |
| 6605 | |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6606 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6607 | switch (type_check_kind) { |
| 6608 | case TypeCheckKind::kExactCheck: |
| 6609 | case TypeCheckKind::kAbstractClassCheck: |
| 6610 | case TypeCheckKind::kClassHierarchyCheck: |
| 6611 | case TypeCheckKind::kArrayObjectCheck: |
| 6612 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6613 | case TypeCheckKind::kInterfaceCheck: |
| 6614 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6615 | case TypeCheckKind::kArrayCheck: |
| 6616 | case TypeCheckKind::kUnresolvedCheck: |
| 6617 | return false; |
| 6618 | } |
| 6619 | LOG(FATAL) << "Unreachable"; |
| 6620 | UNREACHABLE(); |
| 6621 | } |
| 6622 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6623 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6624 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6625 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6626 | LocationSummary::CallKind call_kind = |
| 6627 | IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch) |
| 6628 | ? LocationSummary::kNoCall |
| 6629 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6630 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6631 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6632 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6633 | // Require a register for the interface check since there is a loop that compares the class to |
| 6634 | // a memory address. |
| 6635 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6636 | } else { |
| 6637 | locations->SetInAt(1, Location::Any()); |
| 6638 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6639 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6640 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6641 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6642 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6643 | } |
| 6644 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6645 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6646 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6647 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6648 | Location obj_loc = locations->InAt(0); |
| 6649 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6650 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6651 | Location temp_loc = locations->GetTemp(0); |
| 6652 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6653 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6654 | DCHECK_GE(num_temps, 1u); |
| 6655 | DCHECK_LE(num_temps, 2u); |
| 6656 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6657 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6658 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6659 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6660 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6661 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6662 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6663 | const uint32_t object_array_data_offset = |
| 6664 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6665 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6666 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6667 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6668 | // read barriers is done for performance and code size reasons. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6669 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6670 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6671 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6672 | SlowPathCode* type_check_slow_path = |
| 6673 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6674 | is_type_check_slow_path_fatal); |
| 6675 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6676 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6677 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6678 | // Avoid null check if we know obj is not null. |
| 6679 | if (instruction->MustDoNullCheck()) { |
| 6680 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6681 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6682 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6683 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6684 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6685 | case TypeCheckKind::kExactCheck: |
| 6686 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6687 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6688 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6689 | temp_loc, |
| 6690 | obj_loc, |
| 6691 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6692 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6693 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6694 | if (cls.IsRegister()) { |
| 6695 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6696 | } else { |
| 6697 | DCHECK(cls.IsStackSlot()) << cls; |
| 6698 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6699 | } |
| 6700 | // Jump to slow path for throwing the exception or doing a |
| 6701 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6702 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6703 | break; |
| 6704 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6706 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6707 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6708 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6709 | temp_loc, |
| 6710 | obj_loc, |
| 6711 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6712 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6713 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6714 | // If the class is abstract, we eagerly fetch the super class of the |
| 6715 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6716 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6717 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6718 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6719 | GenerateReferenceLoadOneRegister(instruction, |
| 6720 | temp_loc, |
| 6721 | super_offset, |
| 6722 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6723 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6724 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6725 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6726 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6727 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6728 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6729 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6730 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6731 | if (cls.IsRegister()) { |
| 6732 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6733 | } else { |
| 6734 | DCHECK(cls.IsStackSlot()) << cls; |
| 6735 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6736 | } |
| 6737 | __ j(kNotEqual, &loop); |
| 6738 | break; |
| 6739 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6740 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6741 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6742 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6743 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6744 | temp_loc, |
| 6745 | obj_loc, |
| 6746 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6747 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6748 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6749 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6750 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6751 | __ Bind(&loop); |
| 6752 | if (cls.IsRegister()) { |
| 6753 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6754 | } else { |
| 6755 | DCHECK(cls.IsStackSlot()) << cls; |
| 6756 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6757 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6758 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6759 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6760 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6761 | GenerateReferenceLoadOneRegister(instruction, |
| 6762 | temp_loc, |
| 6763 | super_offset, |
| 6764 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6765 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6766 | |
| 6767 | // If the class reference currently in `temp` is not null, jump |
| 6768 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6769 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6770 | __ j(kNotZero, &loop); |
| 6771 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6772 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6773 | break; |
| 6774 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6775 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6776 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6777 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6778 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6779 | temp_loc, |
| 6780 | obj_loc, |
| 6781 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6782 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6783 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6784 | // Do an exact check. |
| 6785 | if (cls.IsRegister()) { |
| 6786 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6787 | } else { |
| 6788 | DCHECK(cls.IsStackSlot()) << cls; |
| 6789 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6790 | } |
| 6791 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6792 | |
| 6793 | // 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] | 6794 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6795 | GenerateReferenceLoadOneRegister(instruction, |
| 6796 | temp_loc, |
| 6797 | component_offset, |
| 6798 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6799 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6800 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6801 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6802 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6803 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6804 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6805 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6806 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6807 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6808 | break; |
| 6809 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6810 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6811 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6812 | // 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] | 6813 | // We cannot directly call the CheckCast runtime entry point |
| 6814 | // without resorting to a type checking slow path here (i.e. by |
| 6815 | // calling InvokeRuntime directly), as it would require to |
| 6816 | // assign fixed registers for the inputs of this HInstanceOf |
| 6817 | // instruction (following the runtime calling convention), which |
| 6818 | // might be cluttered by the potential first read barrier |
| 6819 | // emission at the beginning of this method. |
| 6820 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6821 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6822 | |
| 6823 | case TypeCheckKind::kInterfaceCheck: { |
| 6824 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6825 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6826 | // conditional flags and cause the conditional jump to be incorrect. Therefore we just jump |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6827 | // to the slow path if we are running under poisoning. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6828 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6829 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6830 | // doing this. |
| 6831 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6832 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6833 | temp_loc, |
| 6834 | obj_loc, |
| 6835 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6836 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6837 | |
| 6838 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6839 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6840 | temp_loc, |
| 6841 | temp_loc, |
| 6842 | iftable_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6843 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6844 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6845 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6846 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6847 | NearLabel start_loop; |
| 6848 | __ Bind(&start_loop); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6849 | // Need to subtract first to handle the empty array case. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6850 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6851 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6852 | // Go to next interface if the classes do not match. |
| 6853 | __ cmpl(cls.AsRegister<Register>(), |
| 6854 | CodeGeneratorX86::ArrayAddress(temp, |
| 6855 | maybe_temp2_loc, |
| 6856 | TIMES_4, |
| 6857 | object_array_data_offset)); |
| 6858 | __ j(kNotEqual, &start_loop); |
| 6859 | } else { |
| 6860 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6861 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 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 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7022 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7023 | HInstruction* instruction, |
| 7024 | Location out, |
| 7025 | uint32_t offset, |
| 7026 | Location maybe_temp, |
| 7027 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7028 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7029 | if (read_barrier_option == kWithReadBarrier) { |
| 7030 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7031 | if (kUseBakerReadBarrier) { |
| 7032 | // Load with fast path based Baker's read barrier. |
| 7033 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7034 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7035 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7036 | } else { |
| 7037 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7038 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7039 | // in the following move operation, as we will need it for the |
| 7040 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7041 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7042 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7043 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7044 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7045 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7046 | } |
| 7047 | } else { |
| 7048 | // Plain load with no read barrier. |
| 7049 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7050 | __ movl(out_reg, Address(out_reg, offset)); |
| 7051 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7052 | } |
| 7053 | } |
| 7054 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7055 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7056 | HInstruction* instruction, |
| 7057 | Location out, |
| 7058 | Location obj, |
| 7059 | uint32_t offset, |
| 7060 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7061 | Register out_reg = out.AsRegister<Register>(); |
| 7062 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7063 | if (read_barrier_option == kWithReadBarrier) { |
| 7064 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7065 | if (kUseBakerReadBarrier) { |
| 7066 | // Load with fast path based Baker's read barrier. |
| 7067 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7068 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7069 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7070 | } else { |
| 7071 | // Load with slow path based read barrier. |
| 7072 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7073 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7074 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7075 | } |
| 7076 | } else { |
| 7077 | // Plain load with no read barrier. |
| 7078 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7079 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7080 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7081 | } |
| 7082 | } |
| 7083 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7084 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7085 | HInstruction* instruction, |
| 7086 | Location root, |
| 7087 | const Address& address, |
| 7088 | Label* fixup_label, |
| 7089 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7090 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7091 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7092 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7093 | if (kUseBakerReadBarrier) { |
| 7094 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7095 | // Baker's read barrier are used: |
| 7096 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7097 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7098 | // if (Thread::Current()->GetIsGcMarking()) { |
| 7099 | // root = ReadBarrier::Mark(root) |
| 7100 | // } |
| 7101 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7102 | // /* GcRoot<mirror::Object> */ root = *address |
| 7103 | __ movl(root_reg, address); |
| 7104 | if (fixup_label != nullptr) { |
| 7105 | __ Bind(fixup_label); |
| 7106 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7107 | static_assert( |
| 7108 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7109 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7110 | "have different sizes."); |
| 7111 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7112 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7113 | "have different sizes."); |
| 7114 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7115 | // Slow path marking the GC root `root`. |
| 7116 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7117 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7118 | codegen_->AddSlowPath(slow_path); |
| 7119 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7120 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7121 | Immediate(0)); |
| 7122 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7123 | __ Bind(slow_path->GetExitLabel()); |
| 7124 | } else { |
| 7125 | // GC root loaded through a slow path for read barriers other |
| 7126 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7127 | // /* GcRoot<mirror::Object>* */ root = address |
| 7128 | __ leal(root_reg, address); |
| 7129 | if (fixup_label != nullptr) { |
| 7130 | __ Bind(fixup_label); |
| 7131 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7132 | // /* mirror::Object* */ root = root->Read() |
| 7133 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7134 | } |
| 7135 | } else { |
| 7136 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7137 | // /* GcRoot<mirror::Object> */ root = *address |
| 7138 | __ movl(root_reg, address); |
| 7139 | if (fixup_label != nullptr) { |
| 7140 | __ Bind(fixup_label); |
| 7141 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7142 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7143 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7144 | } |
| 7145 | } |
| 7146 | |
| 7147 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7148 | Location ref, |
| 7149 | Register obj, |
| 7150 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7151 | bool needs_null_check) { |
| 7152 | DCHECK(kEmitCompilerReadBarrier); |
| 7153 | DCHECK(kUseBakerReadBarrier); |
| 7154 | |
| 7155 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7156 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7157 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7158 | } |
| 7159 | |
| 7160 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7161 | Location ref, |
| 7162 | Register obj, |
| 7163 | uint32_t data_offset, |
| 7164 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7165 | bool needs_null_check) { |
| 7166 | DCHECK(kEmitCompilerReadBarrier); |
| 7167 | DCHECK(kUseBakerReadBarrier); |
| 7168 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7169 | static_assert( |
| 7170 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7171 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7172 | // /* HeapReference<Object> */ ref = |
| 7173 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7174 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7175 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7176 | } |
| 7177 | |
| 7178 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7179 | Location ref, |
| 7180 | Register obj, |
| 7181 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7182 | bool needs_null_check, |
| 7183 | bool always_update_field, |
| 7184 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7185 | DCHECK(kEmitCompilerReadBarrier); |
| 7186 | DCHECK(kUseBakerReadBarrier); |
| 7187 | |
| 7188 | // In slow path based read barriers, the read barrier call is |
| 7189 | // inserted after the original load. However, in fast path based |
| 7190 | // Baker's read barriers, we need to perform the load of |
| 7191 | // mirror::Object::monitor_ *before* the original reference load. |
| 7192 | // This load-load ordering is required by the read barrier. |
| 7193 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7194 | // |
| 7195 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7196 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7197 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7198 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7199 | // if (is_gray) { |
| 7200 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7201 | // } |
| 7202 | // |
| 7203 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7204 | // slightly more complex as: |
| 7205 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7206 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7207 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7208 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7209 | // - it performs additional checks that we do not do here for |
| 7210 | // performance reasons. |
| 7211 | |
| 7212 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7213 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7214 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7215 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7216 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7217 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7218 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7219 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7220 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7221 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7222 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7223 | // ref = ReadBarrier::Mark(ref); |
| 7224 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7225 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7226 | if (needs_null_check) { |
| 7227 | MaybeRecordImplicitNullCheck(instruction); |
| 7228 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7229 | |
| 7230 | // Load fence to prevent load-load reordering. |
| 7231 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7232 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7233 | |
| 7234 | // The actual reference load. |
| 7235 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7236 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7237 | |
| 7238 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7239 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7240 | SlowPathCode* slow_path; |
| 7241 | if (always_update_field) { |
| 7242 | DCHECK(temp != nullptr); |
| 7243 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| 7244 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7245 | } else { |
| 7246 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 7247 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7248 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7249 | AddSlowPath(slow_path); |
| 7250 | |
| 7251 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7252 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7253 | |
| 7254 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7255 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7256 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7257 | __ Bind(slow_path->GetExitLabel()); |
| 7258 | } |
| 7259 | |
| 7260 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7261 | Location out, |
| 7262 | Location ref, |
| 7263 | Location obj, |
| 7264 | uint32_t offset, |
| 7265 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7266 | DCHECK(kEmitCompilerReadBarrier); |
| 7267 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7268 | // Insert a slow path based read barrier *after* the reference load. |
| 7269 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7270 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7271 | // reference will be carried out by the runtime within the slow |
| 7272 | // path. |
| 7273 | // |
| 7274 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7275 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7276 | // not used by the artReadBarrierSlow entry point. |
| 7277 | // |
| 7278 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7279 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7280 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7281 | AddSlowPath(slow_path); |
| 7282 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7283 | __ jmp(slow_path->GetEntryLabel()); |
| 7284 | __ Bind(slow_path->GetExitLabel()); |
| 7285 | } |
| 7286 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7287 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7288 | Location out, |
| 7289 | Location ref, |
| 7290 | Location obj, |
| 7291 | uint32_t offset, |
| 7292 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7293 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7294 | // Baker's read barriers shall be handled by the fast path |
| 7295 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7296 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7297 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7298 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7299 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7300 | } else if (kPoisonHeapReferences) { |
| 7301 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7302 | } |
| 7303 | } |
| 7304 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7305 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7306 | Location out, |
| 7307 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7308 | DCHECK(kEmitCompilerReadBarrier); |
| 7309 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7310 | // Insert a slow path based read barrier *after* the GC root load. |
| 7311 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7312 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7313 | // not need to do anything special for this here. |
| 7314 | SlowPathCode* slow_path = |
| 7315 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7316 | AddSlowPath(slow_path); |
| 7317 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7318 | __ jmp(slow_path->GetEntryLabel()); |
| 7319 | __ Bind(slow_path->GetExitLabel()); |
| 7320 | } |
| 7321 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7322 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7323 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7324 | LOG(FATAL) << "Unreachable"; |
| 7325 | } |
| 7326 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7327 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7328 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7329 | LOG(FATAL) << "Unreachable"; |
| 7330 | } |
| 7331 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7332 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7333 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7334 | LocationSummary* locations = |
| 7335 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7336 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7337 | } |
| 7338 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7339 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7340 | int32_t lower_bound, |
| 7341 | uint32_t num_entries, |
| 7342 | HBasicBlock* switch_block, |
| 7343 | HBasicBlock* default_block) { |
| 7344 | // Figure out the correct compare values and jump conditions. |
| 7345 | // Handle the first compare/branch as a special case because it might |
| 7346 | // jump to the default case. |
| 7347 | DCHECK_GT(num_entries, 2u); |
| 7348 | Condition first_condition; |
| 7349 | uint32_t index; |
| 7350 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7351 | if (lower_bound != 0) { |
| 7352 | first_condition = kLess; |
| 7353 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7354 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7355 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7356 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7357 | index = 1; |
| 7358 | } else { |
| 7359 | // Handle all the compare/jumps below. |
| 7360 | first_condition = kBelow; |
| 7361 | index = 0; |
| 7362 | } |
| 7363 | |
| 7364 | // Handle the rest of the compare/jumps. |
| 7365 | for (; index + 1 < num_entries; index += 2) { |
| 7366 | int32_t compare_to_value = lower_bound + index + 1; |
| 7367 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7368 | // Jump to successors[index] if value < case_value[index]. |
| 7369 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7370 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7371 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7372 | } |
| 7373 | |
| 7374 | if (index != num_entries) { |
| 7375 | // There are an odd number of entries. Handle the last one. |
| 7376 | DCHECK_EQ(index + 1, num_entries); |
| 7377 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7378 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7379 | } |
| 7380 | |
| 7381 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7382 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7383 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7384 | } |
| 7385 | } |
| 7386 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7387 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7388 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7389 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7390 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7391 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7392 | |
| 7393 | GenPackedSwitchWithCompares(value_reg, |
| 7394 | lower_bound, |
| 7395 | num_entries, |
| 7396 | switch_instr->GetBlock(), |
| 7397 | switch_instr->GetDefaultBlock()); |
| 7398 | } |
| 7399 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7400 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7401 | LocationSummary* locations = |
| 7402 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7404 | |
| 7405 | // Constant area pointer. |
| 7406 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7407 | |
| 7408 | // And the temporary we need. |
| 7409 | locations->AddTemp(Location::RequiresRegister()); |
| 7410 | } |
| 7411 | |
| 7412 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7413 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7414 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7415 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7416 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7417 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7418 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7419 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7420 | GenPackedSwitchWithCompares(value_reg, |
| 7421 | lower_bound, |
| 7422 | num_entries, |
| 7423 | switch_instr->GetBlock(), |
| 7424 | default_block); |
| 7425 | return; |
| 7426 | } |
| 7427 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7428 | // Optimizing has a jump area. |
| 7429 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7430 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7431 | |
| 7432 | // Remove the bias, if needed. |
| 7433 | if (lower_bound != 0) { |
| 7434 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7435 | value_reg = temp_reg; |
| 7436 | } |
| 7437 | |
| 7438 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7439 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7440 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7441 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7442 | |
| 7443 | // We are in the range of the table. |
| 7444 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7445 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7446 | |
| 7447 | // Compute the actual target address by adding in constant_area. |
| 7448 | __ addl(temp_reg, constant_area); |
| 7449 | |
| 7450 | // And jump. |
| 7451 | __ jmp(temp_reg); |
| 7452 | } |
| 7453 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7454 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7455 | HX86ComputeBaseMethodAddress* insn) { |
| 7456 | LocationSummary* locations = |
| 7457 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7458 | locations->SetOut(Location::RequiresRegister()); |
| 7459 | } |
| 7460 | |
| 7461 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7462 | HX86ComputeBaseMethodAddress* insn) { |
| 7463 | LocationSummary* locations = insn->GetLocations(); |
| 7464 | Register reg = locations->Out().AsRegister<Register>(); |
| 7465 | |
| 7466 | // Generate call to next instruction. |
| 7467 | Label next_instruction; |
| 7468 | __ call(&next_instruction); |
| 7469 | __ Bind(&next_instruction); |
| 7470 | |
| 7471 | // Remember this offset for later use with constant area. |
| 7472 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7473 | |
| 7474 | // Grab the return address off the stack. |
| 7475 | __ popl(reg); |
| 7476 | } |
| 7477 | |
| 7478 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7479 | HX86LoadFromConstantTable* insn) { |
| 7480 | LocationSummary* locations = |
| 7481 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7482 | |
| 7483 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7484 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7485 | |
| 7486 | // If we don't need to be materialized, we only need the inputs to be set. |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7487 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7488 | return; |
| 7489 | } |
| 7490 | |
| 7491 | switch (insn->GetType()) { |
| 7492 | case Primitive::kPrimFloat: |
| 7493 | case Primitive::kPrimDouble: |
| 7494 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7495 | break; |
| 7496 | |
| 7497 | case Primitive::kPrimInt: |
| 7498 | locations->SetOut(Location::RequiresRegister()); |
| 7499 | break; |
| 7500 | |
| 7501 | default: |
| 7502 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7503 | } |
| 7504 | } |
| 7505 | |
| 7506 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7507 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7508 | return; |
| 7509 | } |
| 7510 | |
| 7511 | LocationSummary* locations = insn->GetLocations(); |
| 7512 | Location out = locations->Out(); |
| 7513 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7514 | HConstant *value = insn->GetConstant(); |
| 7515 | |
| 7516 | switch (insn->GetType()) { |
| 7517 | case Primitive::kPrimFloat: |
| 7518 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7519 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7520 | break; |
| 7521 | |
| 7522 | case Primitive::kPrimDouble: |
| 7523 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7524 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7525 | break; |
| 7526 | |
| 7527 | case Primitive::kPrimInt: |
| 7528 | __ movl(out.AsRegister<Register>(), |
| 7529 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7530 | break; |
| 7531 | |
| 7532 | default: |
| 7533 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7534 | } |
| 7535 | } |
| 7536 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7537 | /** |
| 7538 | * Class to handle late fixup of offsets into constant area. |
| 7539 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7540 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7541 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7542 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7543 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7544 | |
| 7545 | protected: |
| 7546 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7547 | |
| 7548 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7549 | |
| 7550 | private: |
| 7551 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7552 | // Patch the correct offset for the instruction. The place to patch is the |
| 7553 | // last 4 bytes of the instruction. |
| 7554 | // The value to patch is the distance from the offset in the constant area |
| 7555 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7556 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7557 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset(); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7558 | |
| 7559 | // Patch in the right value. |
| 7560 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7561 | } |
| 7562 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7563 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7564 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7565 | }; |
| 7566 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7567 | /** |
| 7568 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7569 | * constant area. |
| 7570 | */ |
| 7571 | class JumpTableRIPFixup : public RIPFixup { |
| 7572 | public: |
| 7573 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7574 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7575 | |
| 7576 | void CreateJumpTable() { |
| 7577 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7578 | |
| 7579 | // Ensure that the reference to the jump table has the correct offset. |
| 7580 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7581 | SetOffset(offset_in_constant_table); |
| 7582 | |
| 7583 | // The label values in the jump table are computed relative to the |
| 7584 | // instruction addressing the constant area. |
| 7585 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7586 | |
| 7587 | // Populate the jump table with the correct values for the jump table. |
| 7588 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7589 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7590 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7591 | // The value that we want is the target offset - the position of the table. |
| 7592 | for (int32_t i = 0; i < num_entries; i++) { |
| 7593 | HBasicBlock* b = successors[i]; |
| 7594 | Label* l = codegen_->GetLabelOf(b); |
| 7595 | DCHECK(l->IsBound()); |
| 7596 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7597 | assembler->AppendInt32(offset_to_block); |
| 7598 | } |
| 7599 | } |
| 7600 | |
| 7601 | private: |
| 7602 | const HX86PackedSwitch* switch_instr_; |
| 7603 | }; |
| 7604 | |
| 7605 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7606 | // Generate the constant area if needed. |
| 7607 | X86Assembler* assembler = GetAssembler(); |
| 7608 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7609 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7610 | // byte values. |
| 7611 | assembler->Align(4, 0); |
| 7612 | constant_area_start_ = assembler->CodeSize(); |
| 7613 | |
| 7614 | // Populate any jump tables. |
| 7615 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7616 | jump_table->CreateJumpTable(); |
| 7617 | } |
| 7618 | |
| 7619 | // And now add the constant area to the generated code. |
| 7620 | assembler->AddConstantArea(); |
| 7621 | } |
| 7622 | |
| 7623 | // And finish up. |
| 7624 | CodeGenerator::Finalize(allocator); |
| 7625 | } |
| 7626 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7627 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7628 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7629 | return Address(reg, kDummy32BitOffset, fixup); |
| 7630 | } |
| 7631 | |
| 7632 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7633 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7634 | return Address(reg, kDummy32BitOffset, fixup); |
| 7635 | } |
| 7636 | |
| 7637 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7638 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7639 | return Address(reg, kDummy32BitOffset, fixup); |
| 7640 | } |
| 7641 | |
| 7642 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7643 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7644 | return Address(reg, kDummy32BitOffset, fixup); |
| 7645 | } |
| 7646 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7647 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7648 | if (value == 0) { |
| 7649 | __ xorl(dest, dest); |
| 7650 | } else { |
| 7651 | __ movl(dest, Immediate(value)); |
| 7652 | } |
| 7653 | } |
| 7654 | |
| 7655 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7656 | if (value == 0) { |
| 7657 | __ testl(dest, dest); |
| 7658 | } else { |
| 7659 | __ cmpl(dest, Immediate(value)); |
| 7660 | } |
| 7661 | } |
| 7662 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7663 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7664 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7665 | GenerateIntCompare(lhs_reg, rhs); |
| 7666 | } |
| 7667 | |
| 7668 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7669 | if (rhs.IsConstant()) { |
| 7670 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7671 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7672 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7673 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7674 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7675 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7676 | } |
| 7677 | } |
| 7678 | |
| 7679 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7680 | Location index, |
| 7681 | ScaleFactor scale, |
| 7682 | uint32_t data_offset) { |
| 7683 | return index.IsConstant() ? |
| 7684 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7685 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7686 | } |
| 7687 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7688 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7689 | Register reg, |
| 7690 | Register value) { |
| 7691 | // Create a fixup to be used to create and address the jump table. |
| 7692 | JumpTableRIPFixup* table_fixup = |
| 7693 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7694 | |
| 7695 | // We have to populate the jump tables. |
| 7696 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7697 | |
| 7698 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7699 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7700 | } |
| 7701 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7702 | // TODO: target as memory. |
| 7703 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7704 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7705 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7706 | return; |
| 7707 | } |
| 7708 | |
| 7709 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7710 | |
| 7711 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7712 | if (target.Equals(return_loc)) { |
| 7713 | return; |
| 7714 | } |
| 7715 | |
| 7716 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7717 | // with the else branch. |
| 7718 | if (type == Primitive::kPrimLong) { |
| 7719 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7720 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7721 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7722 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7723 | } else { |
| 7724 | // Let the parallel move resolver take care of all of this. |
| 7725 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7726 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7727 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7728 | } |
| 7729 | } |
| 7730 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7731 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7732 | const uint8_t* roots_data, |
| 7733 | const PatchInfo<Label>& info, |
| 7734 | uint64_t index_in_table) const { |
| 7735 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7736 | uintptr_t address = |
| 7737 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7738 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7739 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7740 | dchecked_integral_cast<uint32_t>(address); |
| 7741 | } |
| 7742 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7743 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7744 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7745 | const auto& it = jit_string_roots_.find( |
| 7746 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7747 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7748 | PatchJitRootUse(code, roots_data, info, it->second); |
| 7749 | } |
| 7750 | |
| 7751 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| 7752 | const auto& it = jit_class_roots_.find( |
| 7753 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7754 | DCHECK(it != jit_class_roots_.end()); |
| 7755 | PatchJitRootUse(code, roots_data, info, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7756 | } |
| 7757 | } |
| 7758 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7759 | #undef __ |
| 7760 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7761 | } // namespace x86 |
| 7762 | } // namespace art |