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; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 228 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 229 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 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) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 257 | : SlowPathCode(at), cls_(cls), 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 { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 262 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 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; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 268 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 269 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 270 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 271 | : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 272 | instruction_, |
| 273 | dex_pc_, |
| 274 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 275 | if (do_clinit_) { |
| 276 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 277 | } else { |
| 278 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 279 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 280 | |
| 281 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 282 | Location out = locations->Out(); |
| 283 | if (out.IsValid()) { |
| 284 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 285 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 287 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 288 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 289 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 290 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 291 | DCHECK(out.IsValid()); |
| 292 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 293 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 294 | locations->Out().AsRegister<Register>()); |
| 295 | Label* fixup_label = x86_codegen->NewTypeBssEntryPatch(cls_); |
| 296 | __ Bind(fixup_label); |
| 297 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 298 | __ jmp(GetExitLabel()); |
| 299 | } |
| 300 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 301 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 302 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 303 | private: |
| 304 | // The class this slow path will load. |
| 305 | HLoadClass* const cls_; |
| 306 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 307 | // The dex PC of `at_`. |
| 308 | const uint32_t dex_pc_; |
| 309 | |
| 310 | // Whether to initialize the class. |
| 311 | const bool do_clinit_; |
| 312 | |
| 313 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 314 | }; |
| 315 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 316 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 318 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 319 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 321 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 322 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 323 | DCHECK(instruction_->IsCheckCast() |
| 324 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 325 | |
| 326 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 327 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 328 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 329 | if (!is_fatal_) { |
| 330 | SaveLiveRegisters(codegen, locations); |
| 331 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
| 333 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 334 | // move resolver. |
| 335 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 336 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 337 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 338 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 339 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 340 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 341 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 342 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 343 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 344 | instruction_, |
| 345 | instruction_->GetDexPc(), |
| 346 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 347 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 348 | } else { |
| 349 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 350 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 351 | instruction_, |
| 352 | instruction_->GetDexPc(), |
| 353 | this); |
| 354 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | if (!is_fatal_) { |
| 358 | if (instruction_->IsInstanceOf()) { |
| 359 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 360 | } |
| 361 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 362 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | __ jmp(GetExitLabel()); |
| 364 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 367 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 368 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 369 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 370 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 371 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 372 | |
| 373 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 374 | }; |
| 375 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 376 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 377 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 378 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 379 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 380 | |
| 381 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 382 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 384 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 385 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 388 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 389 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 392 | }; |
| 393 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 394 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 395 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 396 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 397 | |
| 398 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 399 | LocationSummary* locations = instruction_->GetLocations(); |
| 400 | __ Bind(GetEntryLabel()); |
| 401 | SaveLiveRegisters(codegen, locations); |
| 402 | |
| 403 | InvokeRuntimeCallingConvention calling_convention; |
| 404 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 405 | parallel_move.AddMove( |
| 406 | locations->InAt(0), |
| 407 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 408 | Primitive::kPrimNot, |
| 409 | nullptr); |
| 410 | parallel_move.AddMove( |
| 411 | locations->InAt(1), |
| 412 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 413 | Primitive::kPrimInt, |
| 414 | nullptr); |
| 415 | parallel_move.AddMove( |
| 416 | locations->InAt(2), |
| 417 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 418 | Primitive::kPrimNot, |
| 419 | nullptr); |
| 420 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 421 | |
| 422 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 423 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 424 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 425 | RestoreLiveRegisters(codegen, locations); |
| 426 | __ jmp(GetExitLabel()); |
| 427 | } |
| 428 | |
| 429 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 430 | |
| 431 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 432 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 433 | }; |
| 434 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 435 | // Slow path marking an object reference `ref` during a read |
| 436 | // barrier. The field `obj.field` in the object `obj` holding this |
| 437 | // reference does not get updated by this slow path after marking (see |
| 438 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 439 | // |
| 440 | // This means that after the execution of this slow path, `ref` will |
| 441 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 442 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 443 | // probably still be a from-space reference (unless it gets updated by |
| 444 | // another thread, or if another thread installed another object |
| 445 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 446 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 447 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 448 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 449 | Location ref, |
| 450 | bool unpoison_ref_before_marking) |
| 451 | : SlowPathCode(instruction), |
| 452 | ref_(ref), |
| 453 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 454 | DCHECK(kEmitCompilerReadBarrier); |
| 455 | } |
| 456 | |
| 457 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 458 | |
| 459 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 460 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 461 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 462 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 463 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 464 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 465 | instruction_->IsStaticFieldGet() || |
| 466 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 467 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 468 | instruction_->IsLoadClass() || |
| 469 | instruction_->IsLoadString() || |
| 470 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 471 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 472 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 473 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 474 | << "Unexpected instruction in read barrier marking slow path: " |
| 475 | << instruction_->DebugName(); |
| 476 | |
| 477 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 478 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 479 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 480 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 481 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 482 | // No need to save live registers; it's taken care of by the |
| 483 | // entrypoint. Also, there is no need to update the stack mask, |
| 484 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 485 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 486 | DCHECK_NE(ref_reg, ESP); |
| 487 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 488 | // "Compact" slow path, saving two moves. |
| 489 | // |
| 490 | // Instead of using the standard runtime calling convention (input |
| 491 | // and output in EAX): |
| 492 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 493 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 494 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 495 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 496 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 498 | // of a dedicated entrypoint: |
| 499 | // |
| 500 | // rX <- ReadBarrierMarkRegX(rX) |
| 501 | // |
| 502 | int32_t entry_point_offset = |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 504 | // This runtime call does not require a stack map. |
| 505 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 506 | __ jmp(GetExitLabel()); |
| 507 | } |
| 508 | |
| 509 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | // The location (register) of the marked object reference. |
| 511 | const Location ref_; |
| 512 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 513 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 514 | |
| 515 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 516 | }; |
| 517 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 518 | // Slow path marking an object reference `ref` during a read barrier, |
| 519 | // and if needed, atomically updating the field `obj.field` in the |
| 520 | // object `obj` holding this reference after marking (contrary to |
| 521 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 522 | // `obj.field`). |
| 523 | // |
| 524 | // This means that after the execution of this slow path, both `ref` |
| 525 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 526 | // hold the same to-space reference (unless another thread installed |
| 527 | // another object reference (different from `ref`) in `obj.field`). |
| 528 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 529 | public: |
| 530 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 531 | Location ref, |
| 532 | Register obj, |
| 533 | const Address& field_addr, |
| 534 | bool unpoison_ref_before_marking, |
| 535 | Register temp) |
| 536 | : SlowPathCode(instruction), |
| 537 | ref_(ref), |
| 538 | obj_(obj), |
| 539 | field_addr_(field_addr), |
| 540 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 541 | temp_(temp) { |
| 542 | DCHECK(kEmitCompilerReadBarrier); |
| 543 | } |
| 544 | |
| 545 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 546 | |
| 547 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 548 | LocationSummary* locations = instruction_->GetLocations(); |
| 549 | Register ref_reg = ref_.AsRegister<Register>(); |
| 550 | DCHECK(locations->CanCall()); |
| 551 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 552 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 553 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 554 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 555 | << instruction_->DebugName(); |
| 556 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 557 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 558 | |
| 559 | __ Bind(GetEntryLabel()); |
| 560 | if (unpoison_ref_before_marking_) { |
| 561 | // Object* ref = ref_addr->AsMirrorPtr() |
| 562 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 563 | } |
| 564 | |
| 565 | // Save the old (unpoisoned) reference. |
| 566 | __ movl(temp_, ref_reg); |
| 567 | |
| 568 | // No need to save live registers; it's taken care of by the |
| 569 | // entrypoint. Also, there is no need to update the stack mask, |
| 570 | // as this runtime call will not trigger a garbage collection. |
| 571 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 572 | DCHECK_NE(ref_reg, ESP); |
| 573 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 574 | // "Compact" slow path, saving two moves. |
| 575 | // |
| 576 | // Instead of using the standard runtime calling convention (input |
| 577 | // and output in EAX): |
| 578 | // |
| 579 | // EAX <- ref |
| 580 | // EAX <- ReadBarrierMark(EAX) |
| 581 | // ref <- EAX |
| 582 | // |
| 583 | // we just use rX (the register containing `ref`) as input and output |
| 584 | // of a dedicated entrypoint: |
| 585 | // |
| 586 | // rX <- ReadBarrierMarkRegX(rX) |
| 587 | // |
| 588 | int32_t entry_point_offset = |
| 589 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| 590 | // This runtime call does not require a stack map. |
| 591 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 592 | |
| 593 | // If the new reference is different from the old reference, |
| 594 | // update the field in the holder (`*field_addr`). |
| 595 | // |
| 596 | // Note that this field could also hold a different object, if |
| 597 | // another thread had concurrently changed it. In that case, the |
| 598 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 599 | // operation below would abort the CAS, leaving the field as-is. |
| 600 | NearLabel done; |
| 601 | __ cmpl(temp_, ref_reg); |
| 602 | __ j(kEqual, &done); |
| 603 | |
| 604 | // Update the the holder's field atomically. This may fail if |
| 605 | // mutator updates before us, but it's OK. This is achieved |
| 606 | // using a strong compare-and-set (CAS) operation with relaxed |
| 607 | // memory synchronization ordering, where the expected value is |
| 608 | // the old reference and the desired value is the new reference. |
| 609 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 610 | // instruction, which requires the expected value (the old |
| 611 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 612 | // expected value (stored in `temp_`) into EAX. |
| 613 | __ pushl(EAX); |
| 614 | __ movl(EAX, temp_); |
| 615 | |
| 616 | // Convenience aliases. |
| 617 | Register base = obj_; |
| 618 | Register expected = EAX; |
| 619 | Register value = ref_reg; |
| 620 | |
| 621 | bool base_equals_value = (base == value); |
| 622 | if (kPoisonHeapReferences) { |
| 623 | if (base_equals_value) { |
| 624 | // If `base` and `value` are the same register location, move |
| 625 | // `value` to a temporary register. This way, poisoning |
| 626 | // `value` won't invalidate `base`. |
| 627 | value = temp_; |
| 628 | __ movl(value, base); |
| 629 | } |
| 630 | |
| 631 | // Check that the register allocator did not assign the location |
| 632 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 633 | // poisoning (when enabled) works as intended below. |
| 634 | // - If `value` were equal to `expected`, both references would |
| 635 | // be poisoned twice, meaning they would not be poisoned at |
| 636 | // all, as heap poisoning uses address negation. |
| 637 | // - If `base` were equal to `expected`, poisoning `expected` |
| 638 | // would invalidate `base`. |
| 639 | DCHECK_NE(value, expected); |
| 640 | DCHECK_NE(base, expected); |
| 641 | |
| 642 | __ PoisonHeapReference(expected); |
| 643 | __ PoisonHeapReference(value); |
| 644 | } |
| 645 | |
| 646 | __ LockCmpxchgl(field_addr_, value); |
| 647 | |
| 648 | // If heap poisoning is enabled, we need to unpoison the values |
| 649 | // that were poisoned earlier. |
| 650 | if (kPoisonHeapReferences) { |
| 651 | if (base_equals_value) { |
| 652 | // `value` has been moved to a temporary register, no need |
| 653 | // to unpoison it. |
| 654 | } else { |
| 655 | __ UnpoisonHeapReference(value); |
| 656 | } |
| 657 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 658 | } |
| 659 | |
| 660 | // Restore EAX. |
| 661 | __ popl(EAX); |
| 662 | |
| 663 | __ Bind(&done); |
| 664 | __ jmp(GetExitLabel()); |
| 665 | } |
| 666 | |
| 667 | private: |
| 668 | // The location (register) of the marked object reference. |
| 669 | const Location ref_; |
| 670 | // The register containing the object holding the marked object reference field. |
| 671 | const Register obj_; |
| 672 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 673 | const Address field_addr_; |
| 674 | |
| 675 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 676 | const bool unpoison_ref_before_marking_; |
| 677 | |
| 678 | const Register temp_; |
| 679 | |
| 680 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 681 | }; |
| 682 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 683 | // Slow path generating a read barrier for a heap reference. |
| 684 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 685 | public: |
| 686 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 687 | Location out, |
| 688 | Location ref, |
| 689 | Location obj, |
| 690 | uint32_t offset, |
| 691 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 692 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 693 | out_(out), |
| 694 | ref_(ref), |
| 695 | obj_(obj), |
| 696 | offset_(offset), |
| 697 | index_(index) { |
| 698 | DCHECK(kEmitCompilerReadBarrier); |
| 699 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 700 | // has been overwritten by (or after) the heap object reference load |
| 701 | // to be instrumented, e.g.: |
| 702 | // |
| 703 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 704 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 705 | // |
| 706 | // In that case, we have lost the information about the original |
| 707 | // object, and the emitted read barrier cannot work properly. |
| 708 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 709 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 710 | } |
| 711 | |
| 712 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 713 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 714 | LocationSummary* locations = instruction_->GetLocations(); |
| 715 | Register reg_out = out_.AsRegister<Register>(); |
| 716 | DCHECK(locations->CanCall()); |
| 717 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 718 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 719 | instruction_->IsStaticFieldGet() || |
| 720 | instruction_->IsArrayGet() || |
| 721 | instruction_->IsInstanceOf() || |
| 722 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 723 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 724 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 725 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 726 | |
| 727 | __ Bind(GetEntryLabel()); |
| 728 | SaveLiveRegisters(codegen, locations); |
| 729 | |
| 730 | // We may have to change the index's value, but as `index_` is a |
| 731 | // constant member (like other "inputs" of this slow path), |
| 732 | // introduce a copy of it, `index`. |
| 733 | Location index = index_; |
| 734 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 735 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 736 | if (instruction_->IsArrayGet()) { |
| 737 | // Compute the actual memory offset and store it in `index`. |
| 738 | Register index_reg = index_.AsRegister<Register>(); |
| 739 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 740 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 741 | // We are about to change the value of `index_reg` (see the |
| 742 | // calls to art::x86::X86Assembler::shll and |
| 743 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 744 | // not been saved by the previous call to |
| 745 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 746 | // callee-save register -- |
| 747 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 748 | // callee-save registers, as it has been designed with the |
| 749 | // assumption that callee-save registers are supposed to be |
| 750 | // handled by the called function. So, as a callee-save |
| 751 | // register, `index_reg` _would_ eventually be saved onto |
| 752 | // the stack, but it would be too late: we would have |
| 753 | // changed its value earlier. Therefore, we manually save |
| 754 | // it here into another freely available register, |
| 755 | // `free_reg`, chosen of course among the caller-save |
| 756 | // registers (as a callee-save `free_reg` register would |
| 757 | // exhibit the same problem). |
| 758 | // |
| 759 | // Note we could have requested a temporary register from |
| 760 | // the register allocator instead; but we prefer not to, as |
| 761 | // this is a slow path, and we know we can find a |
| 762 | // caller-save register that is available. |
| 763 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 764 | __ movl(free_reg, index_reg); |
| 765 | index_reg = free_reg; |
| 766 | index = Location::RegisterLocation(index_reg); |
| 767 | } else { |
| 768 | // The initial register stored in `index_` has already been |
| 769 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 770 | // (as it is not a callee-save register), so we can freely |
| 771 | // use it. |
| 772 | } |
| 773 | // Shifting the index value contained in `index_reg` by the scale |
| 774 | // factor (2) cannot overflow in practice, as the runtime is |
| 775 | // unable to allocate object arrays with a size larger than |
| 776 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 777 | __ shll(index_reg, Immediate(TIMES_4)); |
| 778 | static_assert( |
| 779 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 780 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 781 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 782 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 783 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 784 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 785 | // (as in the case of ArrayGet), as it is actually an offset |
| 786 | // to an object field within an object. |
| 787 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 788 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 789 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 790 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 791 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 792 | DCHECK_EQ(offset_, 0U); |
| 793 | DCHECK(index_.IsRegisterPair()); |
| 794 | // UnsafeGet's offset location is a register pair, the low |
| 795 | // part contains the correct offset. |
| 796 | index = index_.ToLow(); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | // We're moving two or three locations to locations that could |
| 801 | // overlap, so we need a parallel move resolver. |
| 802 | InvokeRuntimeCallingConvention calling_convention; |
| 803 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 804 | parallel_move.AddMove(ref_, |
| 805 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 806 | Primitive::kPrimNot, |
| 807 | nullptr); |
| 808 | parallel_move.AddMove(obj_, |
| 809 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 810 | Primitive::kPrimNot, |
| 811 | nullptr); |
| 812 | if (index.IsValid()) { |
| 813 | parallel_move.AddMove(index, |
| 814 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 815 | Primitive::kPrimInt, |
| 816 | nullptr); |
| 817 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 818 | } else { |
| 819 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 820 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 821 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 822 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 823 | CheckEntrypointTypes< |
| 824 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 825 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 826 | |
| 827 | RestoreLiveRegisters(codegen, locations); |
| 828 | __ jmp(GetExitLabel()); |
| 829 | } |
| 830 | |
| 831 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 832 | |
| 833 | private: |
| 834 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 835 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 836 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 837 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 838 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 839 | return static_cast<Register>(i); |
| 840 | } |
| 841 | } |
| 842 | // We shall never fail to find a free caller-save register, as |
| 843 | // there are more than two core caller-save registers on x86 |
| 844 | // (meaning it is possible to find one which is different from |
| 845 | // `ref` and `obj`). |
| 846 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 847 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 848 | UNREACHABLE(); |
| 849 | } |
| 850 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 851 | const Location out_; |
| 852 | const Location ref_; |
| 853 | const Location obj_; |
| 854 | const uint32_t offset_; |
| 855 | // An additional location containing an index to an array. |
| 856 | // Only used for HArrayGet and the UnsafeGetObject & |
| 857 | // UnsafeGetObjectVolatile intrinsics. |
| 858 | const Location index_; |
| 859 | |
| 860 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 861 | }; |
| 862 | |
| 863 | // Slow path generating a read barrier for a GC root. |
| 864 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 865 | public: |
| 866 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 867 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 868 | DCHECK(kEmitCompilerReadBarrier); |
| 869 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 870 | |
| 871 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 872 | LocationSummary* locations = instruction_->GetLocations(); |
| 873 | Register reg_out = out_.AsRegister<Register>(); |
| 874 | DCHECK(locations->CanCall()); |
| 875 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 876 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 877 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 878 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 879 | |
| 880 | __ Bind(GetEntryLabel()); |
| 881 | SaveLiveRegisters(codegen, locations); |
| 882 | |
| 883 | InvokeRuntimeCallingConvention calling_convention; |
| 884 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 885 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 886 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 887 | instruction_, |
| 888 | instruction_->GetDexPc(), |
| 889 | this); |
| 890 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 891 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 892 | |
| 893 | RestoreLiveRegisters(codegen, locations); |
| 894 | __ jmp(GetExitLabel()); |
| 895 | } |
| 896 | |
| 897 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 898 | |
| 899 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 900 | const Location out_; |
| 901 | const Location root_; |
| 902 | |
| 903 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 904 | }; |
| 905 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 906 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 907 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 908 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 909 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 910 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 911 | switch (cond) { |
| 912 | case kCondEQ: return kEqual; |
| 913 | case kCondNE: return kNotEqual; |
| 914 | case kCondLT: return kLess; |
| 915 | case kCondLE: return kLessEqual; |
| 916 | case kCondGT: return kGreater; |
| 917 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 918 | case kCondB: return kBelow; |
| 919 | case kCondBE: return kBelowEqual; |
| 920 | case kCondA: return kAbove; |
| 921 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 922 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 923 | LOG(FATAL) << "Unreachable"; |
| 924 | UNREACHABLE(); |
| 925 | } |
| 926 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 927 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 928 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 929 | switch (cond) { |
| 930 | case kCondEQ: return kEqual; |
| 931 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 932 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 933 | case kCondLT: return kBelow; |
| 934 | case kCondLE: return kBelowEqual; |
| 935 | case kCondGT: return kAbove; |
| 936 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 937 | // Unsigned remain unchanged. |
| 938 | case kCondB: return kBelow; |
| 939 | case kCondBE: return kBelowEqual; |
| 940 | case kCondA: return kAbove; |
| 941 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 942 | } |
| 943 | LOG(FATAL) << "Unreachable"; |
| 944 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 947 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 948 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 952 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 953 | } |
| 954 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 955 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 956 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 957 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 958 | } |
| 959 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 960 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 961 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 962 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 965 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 966 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 967 | return GetFloatingPointSpillSlotSize(); |
| 968 | } |
| 969 | |
| 970 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 971 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 972 | return GetFloatingPointSpillSlotSize(); |
| 973 | } |
| 974 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 975 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 976 | HInstruction* instruction, |
| 977 | uint32_t dex_pc, |
| 978 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 979 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 980 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 981 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 982 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 983 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 984 | } |
| 985 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 986 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 987 | HInstruction* instruction, |
| 988 | SlowPathCode* slow_path) { |
| 989 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 990 | GenerateInvokeRuntime(entry_point_offset); |
| 991 | } |
| 992 | |
| 993 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 994 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 995 | } |
| 996 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 997 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 998 | const X86InstructionSetFeatures& isa_features, |
| 999 | const CompilerOptions& compiler_options, |
| 1000 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1001 | : CodeGenerator(graph, |
| 1002 | kNumberOfCpuRegisters, |
| 1003 | kNumberOfXmmRegisters, |
| 1004 | kNumberOfRegisterPairs, |
| 1005 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1006 | arraysize(kCoreCalleeSaves)) |
| 1007 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1008 | 0, |
| 1009 | compiler_options, |
| 1010 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1011 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1012 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1013 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1014 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1015 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1016 | isa_features_(isa_features), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1017 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1018 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1019 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1020 | boot_image_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1021 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1022 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1023 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1024 | constant_area_start_(-1), |
| 1025 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1026 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1027 | // Use a fake return address register to mimic Quick. |
| 1028 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1029 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1030 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1031 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1032 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1033 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1034 | } |
| 1035 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1036 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1037 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1038 | assembler_(codegen->GetAssembler()), |
| 1039 | codegen_(codegen) {} |
| 1040 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1041 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1042 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1045 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1046 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1047 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1048 | bool skip_overflow_check = |
| 1049 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1050 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1051 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1052 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1053 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1054 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1057 | if (HasEmptyFrame()) { |
| 1058 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1059 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1060 | |
| 1061 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1062 | Register reg = kCoreCalleeSaves[i]; |
| 1063 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1064 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1065 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1066 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1070 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1071 | // Initialize should_deoptimize flag to 0. |
| 1072 | __ movl(Address(ESP, -kShouldDeoptimizeFlagSize), Immediate(0)); |
| 1073 | } |
| 1074 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1075 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1076 | __ subl(ESP, Immediate(adjust)); |
| 1077 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1078 | // Save the current method if we need it. Note that we do not |
| 1079 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1080 | // in the SSA graph. |
| 1081 | if (RequiresCurrentMethod()) { |
| 1082 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1083 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1087 | __ cfi().RememberState(); |
| 1088 | if (!HasEmptyFrame()) { |
| 1089 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1090 | __ addl(ESP, Immediate(adjust)); |
| 1091 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1092 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1093 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1094 | Register reg = kCoreCalleeSaves[i]; |
| 1095 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1096 | __ popl(reg); |
| 1097 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1098 | __ cfi().Restore(DWARFReg(reg)); |
| 1099 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1100 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1101 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1102 | __ ret(); |
| 1103 | __ cfi().RestoreState(); |
| 1104 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1107 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1108 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1111 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 1112 | switch (type) { |
| 1113 | case Primitive::kPrimBoolean: |
| 1114 | case Primitive::kPrimByte: |
| 1115 | case Primitive::kPrimChar: |
| 1116 | case Primitive::kPrimShort: |
| 1117 | case Primitive::kPrimInt: |
| 1118 | case Primitive::kPrimNot: |
| 1119 | return Location::RegisterLocation(EAX); |
| 1120 | |
| 1121 | case Primitive::kPrimLong: |
| 1122 | return Location::RegisterPairLocation(EAX, EDX); |
| 1123 | |
| 1124 | case Primitive::kPrimVoid: |
| 1125 | return Location::NoLocation(); |
| 1126 | |
| 1127 | case Primitive::kPrimDouble: |
| 1128 | case Primitive::kPrimFloat: |
| 1129 | return Location::FpuRegisterLocation(XMM0); |
| 1130 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1131 | |
| 1132 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1136 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1137 | } |
| 1138 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1139 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1140 | switch (type) { |
| 1141 | case Primitive::kPrimBoolean: |
| 1142 | case Primitive::kPrimByte: |
| 1143 | case Primitive::kPrimChar: |
| 1144 | case Primitive::kPrimShort: |
| 1145 | case Primitive::kPrimInt: |
| 1146 | case Primitive::kPrimNot: { |
| 1147 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1148 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1149 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1150 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1151 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1152 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1153 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1154 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1155 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1156 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1157 | uint32_t index = gp_index_; |
| 1158 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1159 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1160 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1161 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1162 | calling_convention.GetRegisterPairAt(index)); |
| 1163 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1164 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1165 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1170 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1171 | stack_index_++; |
| 1172 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1173 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1174 | } else { |
| 1175 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1180 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1181 | stack_index_ += 2; |
| 1182 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1183 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1184 | } else { |
| 1185 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1189 | case Primitive::kPrimVoid: |
| 1190 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1191 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1192 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1193 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1194 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1195 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1196 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1197 | if (source.Equals(destination)) { |
| 1198 | return; |
| 1199 | } |
| 1200 | if (destination.IsRegister()) { |
| 1201 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1202 | __ movl(destination.AsRegister<Register>(), 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 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1205 | } else { |
| 1206 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1207 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1208 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1209 | } else if (destination.IsFpuRegister()) { |
| 1210 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1211 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1212 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1213 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1214 | } else { |
| 1215 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1216 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1217 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1218 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1219 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1220 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1221 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1222 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1223 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1224 | } else if (source.IsConstant()) { |
| 1225 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1226 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1227 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1228 | } else { |
| 1229 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1230 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1231 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1237 | if (source.Equals(destination)) { |
| 1238 | return; |
| 1239 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1240 | if (destination.IsRegisterPair()) { |
| 1241 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1242 | EmitParallelMoves( |
| 1243 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1244 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1245 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1246 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1247 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1248 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1249 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1250 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1251 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1252 | __ psrlq(src_reg, Immediate(32)); |
| 1253 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1254 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1255 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1256 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1257 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1258 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1259 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1260 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1261 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1262 | if (source.IsFpuRegister()) { |
| 1263 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1264 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1265 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1266 | } else if (source.IsRegisterPair()) { |
| 1267 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1268 | // Create stack space for 2 elements. |
| 1269 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1270 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1271 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1272 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1273 | // And remove the temporary stack space we allocated. |
| 1274 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1275 | } else { |
| 1276 | LOG(FATAL) << "Unimplemented"; |
| 1277 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1278 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1279 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1280 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1281 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1282 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1283 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1284 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1285 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1286 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1287 | } else if (source.IsConstant()) { |
| 1288 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1289 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1290 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1291 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1292 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1293 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1294 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1295 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1296 | EmitParallelMoves( |
| 1297 | Location::StackSlot(source.GetStackIndex()), |
| 1298 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1299 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1300 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1301 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1302 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1307 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1308 | DCHECK(location.IsRegister()); |
| 1309 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1310 | } |
| 1311 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1312 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1313 | HParallelMove move(GetGraph()->GetArena()); |
| 1314 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1315 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1316 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1317 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1318 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1319 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1320 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1324 | if (location.IsRegister()) { |
| 1325 | locations->AddTemp(location); |
| 1326 | } else if (location.IsRegisterPair()) { |
| 1327 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1328 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1329 | } else { |
| 1330 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1331 | } |
| 1332 | } |
| 1333 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1334 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1335 | DCHECK(!successor->IsExitBlock()); |
| 1336 | |
| 1337 | HBasicBlock* block = got->GetBlock(); |
| 1338 | HInstruction* previous = got->GetPrevious(); |
| 1339 | |
| 1340 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1341 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1342 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1343 | return; |
| 1344 | } |
| 1345 | |
| 1346 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1347 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1348 | } |
| 1349 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1350 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1351 | } |
| 1352 | } |
| 1353 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1354 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1355 | got->SetLocations(nullptr); |
| 1356 | } |
| 1357 | |
| 1358 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1359 | HandleGoto(got, got->GetSuccessor()); |
| 1360 | } |
| 1361 | |
| 1362 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1363 | try_boundary->SetLocations(nullptr); |
| 1364 | } |
| 1365 | |
| 1366 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1367 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1368 | if (!successor->IsExitBlock()) { |
| 1369 | HandleGoto(try_boundary, successor); |
| 1370 | } |
| 1371 | } |
| 1372 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1373 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1374 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1377 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1380 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1381 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1382 | LabelType* true_label, |
| 1383 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1384 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1385 | __ j(kUnordered, true_label); |
| 1386 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1387 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1388 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1389 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1390 | } |
| 1391 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1392 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1393 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1394 | LabelType* true_label, |
| 1395 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1396 | LocationSummary* locations = cond->GetLocations(); |
| 1397 | Location left = locations->InAt(0); |
| 1398 | Location right = locations->InAt(1); |
| 1399 | IfCondition if_cond = cond->GetCondition(); |
| 1400 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1401 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1402 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1403 | IfCondition true_high_cond = if_cond; |
| 1404 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1405 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1406 | |
| 1407 | // Set the conditions for the test, remembering that == needs to be |
| 1408 | // decided using the low words. |
| 1409 | switch (if_cond) { |
| 1410 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1411 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1412 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1413 | break; |
| 1414 | case kCondLT: |
| 1415 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1416 | break; |
| 1417 | case kCondLE: |
| 1418 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1419 | break; |
| 1420 | case kCondGT: |
| 1421 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1422 | break; |
| 1423 | case kCondGE: |
| 1424 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1425 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1426 | case kCondB: |
| 1427 | false_high_cond = kCondA; |
| 1428 | break; |
| 1429 | case kCondBE: |
| 1430 | true_high_cond = kCondB; |
| 1431 | break; |
| 1432 | case kCondA: |
| 1433 | false_high_cond = kCondB; |
| 1434 | break; |
| 1435 | case kCondAE: |
| 1436 | true_high_cond = kCondA; |
| 1437 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | if (right.IsConstant()) { |
| 1441 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1442 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1443 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1444 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1445 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1446 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1447 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1448 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1449 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1450 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1451 | __ j(X86Condition(true_high_cond), true_label); |
| 1452 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1453 | } |
| 1454 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1455 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1456 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1457 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1458 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1459 | |
| 1460 | __ cmpl(left_high, right_high); |
| 1461 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1462 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1463 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1464 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1465 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1466 | __ j(X86Condition(true_high_cond), true_label); |
| 1467 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1468 | } |
| 1469 | // Must be equal high, so compare the lows. |
| 1470 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1471 | } else { |
| 1472 | DCHECK(right.IsDoubleStackSlot()); |
| 1473 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1474 | if (if_cond == kCondNE) { |
| 1475 | __ j(X86Condition(true_high_cond), true_label); |
| 1476 | } else if (if_cond == kCondEQ) { |
| 1477 | __ j(X86Condition(false_high_cond), false_label); |
| 1478 | } else { |
| 1479 | __ j(X86Condition(true_high_cond), true_label); |
| 1480 | __ j(X86Condition(false_high_cond), false_label); |
| 1481 | } |
| 1482 | // Must be equal high, so compare the lows. |
| 1483 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1484 | } |
| 1485 | // The last comparison might be unsigned. |
| 1486 | __ j(final_condition, true_label); |
| 1487 | } |
| 1488 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1489 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1490 | Location rhs, |
| 1491 | HInstruction* insn, |
| 1492 | bool is_double) { |
| 1493 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1494 | if (is_double) { |
| 1495 | if (rhs.IsFpuRegister()) { |
| 1496 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1497 | } else if (const_area != nullptr) { |
| 1498 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1499 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1500 | codegen_->LiteralDoubleAddress( |
| 1501 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1502 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1503 | } else { |
| 1504 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1505 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1506 | } |
| 1507 | } else { |
| 1508 | if (rhs.IsFpuRegister()) { |
| 1509 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1510 | } else if (const_area != nullptr) { |
| 1511 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1512 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1513 | codegen_->LiteralFloatAddress( |
| 1514 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1515 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1516 | } else { |
| 1517 | DCHECK(rhs.IsStackSlot()); |
| 1518 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1519 | } |
| 1520 | } |
| 1521 | } |
| 1522 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1523 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1524 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1525 | LabelType* true_target_in, |
| 1526 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1527 | // Generated branching requires both targets to be explicit. If either of the |
| 1528 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1529 | LabelType fallthrough_target; |
| 1530 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1531 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1532 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1533 | LocationSummary* locations = condition->GetLocations(); |
| 1534 | Location left = locations->InAt(0); |
| 1535 | Location right = locations->InAt(1); |
| 1536 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1537 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1538 | switch (type) { |
| 1539 | case Primitive::kPrimLong: |
| 1540 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1541 | break; |
| 1542 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1543 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1544 | GenerateFPJumps(condition, true_target, false_target); |
| 1545 | break; |
| 1546 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1547 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1548 | GenerateFPJumps(condition, true_target, false_target); |
| 1549 | break; |
| 1550 | default: |
| 1551 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1552 | } |
| 1553 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1554 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1555 | __ jmp(false_target); |
| 1556 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1557 | |
| 1558 | if (fallthrough_target.IsLinked()) { |
| 1559 | __ Bind(&fallthrough_target); |
| 1560 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1561 | } |
| 1562 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1563 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1564 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1565 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1566 | // conditions if they are materialized due to the complex branching. |
| 1567 | return cond->IsCondition() && |
| 1568 | cond->GetNext() == branch && |
| 1569 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1570 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1571 | } |
| 1572 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1573 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1574 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1575 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1576 | LabelType* true_target, |
| 1577 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1578 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1579 | |
| 1580 | if (true_target == nullptr && false_target == nullptr) { |
| 1581 | // Nothing to do. The code always falls through. |
| 1582 | return; |
| 1583 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1584 | // Constant condition, statically compared against "true" (integer value 1). |
| 1585 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1586 | if (true_target != nullptr) { |
| 1587 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1588 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1589 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1590 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1591 | if (false_target != nullptr) { |
| 1592 | __ jmp(false_target); |
| 1593 | } |
| 1594 | } |
| 1595 | return; |
| 1596 | } |
| 1597 | |
| 1598 | // The following code generates these patterns: |
| 1599 | // (1) true_target == nullptr && false_target != nullptr |
| 1600 | // - opposite condition true => branch to false_target |
| 1601 | // (2) true_target != nullptr && false_target == nullptr |
| 1602 | // - condition true => branch to true_target |
| 1603 | // (3) true_target != nullptr && false_target != nullptr |
| 1604 | // - condition true => branch to true_target |
| 1605 | // - branch to false_target |
| 1606 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1607 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1608 | if (true_target == nullptr) { |
| 1609 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1610 | } else { |
| 1611 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1612 | } |
| 1613 | } else { |
| 1614 | // Materialized condition, compare against 0. |
| 1615 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1616 | if (lhs.IsRegister()) { |
| 1617 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1618 | } else { |
| 1619 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1620 | } |
| 1621 | if (true_target == nullptr) { |
| 1622 | __ j(kEqual, false_target); |
| 1623 | } else { |
| 1624 | __ j(kNotEqual, true_target); |
| 1625 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1626 | } |
| 1627 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1628 | // Condition has not been materialized, use its inputs as the comparison and |
| 1629 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1630 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1631 | |
| 1632 | // If this is a long or FP comparison that has been folded into |
| 1633 | // the HCondition, generate the comparison directly. |
| 1634 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1635 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1636 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1637 | return; |
| 1638 | } |
| 1639 | |
| 1640 | Location lhs = condition->GetLocations()->InAt(0); |
| 1641 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1642 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1643 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1644 | if (true_target == nullptr) { |
| 1645 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1646 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1647 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1648 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1649 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1650 | |
| 1651 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1652 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1653 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1654 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1655 | } |
| 1656 | } |
| 1657 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1658 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1659 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1660 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1661 | locations->SetInAt(0, Location::Any()); |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1666 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1667 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1668 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1669 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1670 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1671 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1672 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1676 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1677 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1678 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1679 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1680 | locations->SetInAt(0, Location::Any()); |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1685 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1686 | GenerateTestAndBranch<Label>(deoptimize, |
| 1687 | /* condition_input_index */ 0, |
| 1688 | slow_path->GetEntryLabel(), |
| 1689 | /* false_target */ nullptr); |
| 1690 | } |
| 1691 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1692 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1693 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1694 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1695 | locations->SetOut(Location::RequiresRegister()); |
| 1696 | } |
| 1697 | |
| 1698 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1699 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1700 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1701 | } |
| 1702 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1703 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1704 | // There are no conditional move instructions for XMMs. |
| 1705 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1706 | return false; |
| 1707 | } |
| 1708 | |
| 1709 | // A FP condition doesn't generate the single CC that we need. |
| 1710 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1711 | HInstruction* condition = select->GetCondition(); |
| 1712 | if (condition->IsCondition()) { |
| 1713 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1714 | if (compare_type == Primitive::kPrimLong || |
| 1715 | Primitive::IsFloatingPointType(compare_type)) { |
| 1716 | return false; |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | // We can generate a CMOV for this Select. |
| 1721 | return true; |
| 1722 | } |
| 1723 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1724 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1725 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1726 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1727 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1728 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1729 | } else { |
| 1730 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1731 | if (SelectCanUseCMOV(select)) { |
| 1732 | if (select->InputAt(1)->IsConstant()) { |
| 1733 | // Cmov can't handle a constant value. |
| 1734 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1735 | } else { |
| 1736 | locations->SetInAt(1, Location::Any()); |
| 1737 | } |
| 1738 | } else { |
| 1739 | locations->SetInAt(1, Location::Any()); |
| 1740 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1741 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1742 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1743 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1744 | } |
| 1745 | locations->SetOut(Location::SameAsFirstInput()); |
| 1746 | } |
| 1747 | |
| 1748 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1749 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1750 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1751 | if (SelectCanUseCMOV(select)) { |
| 1752 | // If both the condition and the source types are integer, we can generate |
| 1753 | // a CMOV to implement Select. |
| 1754 | |
| 1755 | HInstruction* select_condition = select->GetCondition(); |
| 1756 | Condition cond = kNotEqual; |
| 1757 | |
| 1758 | // Figure out how to test the 'condition'. |
| 1759 | if (select_condition->IsCondition()) { |
| 1760 | HCondition* condition = select_condition->AsCondition(); |
| 1761 | if (!condition->IsEmittedAtUseSite()) { |
| 1762 | // This was a previously materialized condition. |
| 1763 | // Can we use the existing condition code? |
| 1764 | if (AreEflagsSetFrom(condition, select)) { |
| 1765 | // Materialization was the previous instruction. Condition codes are right. |
| 1766 | cond = X86Condition(condition->GetCondition()); |
| 1767 | } else { |
| 1768 | // No, we have to recreate the condition code. |
| 1769 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1770 | __ testl(cond_reg, cond_reg); |
| 1771 | } |
| 1772 | } else { |
| 1773 | // We can't handle FP or long here. |
| 1774 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1775 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1776 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1777 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1778 | cond = X86Condition(condition->GetCondition()); |
| 1779 | } |
| 1780 | } else { |
| 1781 | // Must be a boolean condition, which needs to be compared to 0. |
| 1782 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1783 | __ testl(cond_reg, cond_reg); |
| 1784 | } |
| 1785 | |
| 1786 | // If the condition is true, overwrite the output, which already contains false. |
| 1787 | Location false_loc = locations->InAt(0); |
| 1788 | Location true_loc = locations->InAt(1); |
| 1789 | if (select->GetType() == Primitive::kPrimLong) { |
| 1790 | // 64 bit conditional move. |
| 1791 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1792 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1793 | if (true_loc.IsRegisterPair()) { |
| 1794 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1795 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1796 | } else { |
| 1797 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1798 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1799 | } |
| 1800 | } else { |
| 1801 | // 32 bit conditional move. |
| 1802 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1803 | if (true_loc.IsRegister()) { |
| 1804 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1805 | } else { |
| 1806 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1807 | } |
| 1808 | } |
| 1809 | } else { |
| 1810 | NearLabel false_target; |
| 1811 | GenerateTestAndBranch<NearLabel>( |
| 1812 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1813 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1814 | __ Bind(&false_target); |
| 1815 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1818 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1819 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1820 | } |
| 1821 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1822 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1823 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | void CodeGeneratorX86::GenerateNop() { |
| 1827 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1830 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1831 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1832 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1833 | // Handle the long/FP comparisons made in instruction simplification. |
| 1834 | switch (cond->InputAt(0)->GetType()) { |
| 1835 | case Primitive::kPrimLong: { |
| 1836 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1837 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1838 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1839 | locations->SetOut(Location::RequiresRegister()); |
| 1840 | } |
| 1841 | break; |
| 1842 | } |
| 1843 | case Primitive::kPrimFloat: |
| 1844 | case Primitive::kPrimDouble: { |
| 1845 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1846 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1847 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1848 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1849 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1850 | } else { |
| 1851 | locations->SetInAt(1, Location::Any()); |
| 1852 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1853 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1854 | locations->SetOut(Location::RequiresRegister()); |
| 1855 | } |
| 1856 | break; |
| 1857 | } |
| 1858 | default: |
| 1859 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1860 | locations->SetInAt(1, Location::Any()); |
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 | // We need a byte register. |
| 1863 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1864 | } |
| 1865 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1866 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1869 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1870 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1871 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1872 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1873 | |
| 1874 | LocationSummary* locations = cond->GetLocations(); |
| 1875 | Location lhs = locations->InAt(0); |
| 1876 | Location rhs = locations->InAt(1); |
| 1877 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1878 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1879 | |
| 1880 | switch (cond->InputAt(0)->GetType()) { |
| 1881 | default: { |
| 1882 | // Integer case. |
| 1883 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1884 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1885 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1886 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1887 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1888 | return; |
| 1889 | } |
| 1890 | case Primitive::kPrimLong: |
| 1891 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1892 | break; |
| 1893 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1894 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1895 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1896 | break; |
| 1897 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1898 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1899 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1900 | break; |
| 1901 | } |
| 1902 | |
| 1903 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1904 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1905 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1906 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1907 | __ Bind(&false_label); |
| 1908 | __ xorl(reg, reg); |
| 1909 | __ jmp(&done_label); |
| 1910 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1911 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1912 | __ Bind(&true_label); |
| 1913 | __ movl(reg, Immediate(1)); |
| 1914 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1918 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1922 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1926 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1930 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1934 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1938 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1942 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1946 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1950 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1954 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1958 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1962 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1965 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1966 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1970 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1974 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1978 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1982 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1986 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1990 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1994 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1997 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1998 | LocationSummary* locations = |
| 1999 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2000 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2003 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2004 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2005 | } |
| 2006 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2007 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2008 | LocationSummary* locations = |
| 2009 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2010 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2011 | } |
| 2012 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2013 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2014 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2017 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2018 | LocationSummary* locations = |
| 2019 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2020 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2021 | } |
| 2022 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2023 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2024 | // Will be generated at use site. |
| 2025 | } |
| 2026 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2027 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2028 | LocationSummary* locations = |
| 2029 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2030 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2031 | } |
| 2032 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2033 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2034 | // Will be generated at use site. |
| 2035 | } |
| 2036 | |
| 2037 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2038 | LocationSummary* locations = |
| 2039 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2040 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2041 | } |
| 2042 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2043 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2044 | // Will be generated at use site. |
| 2045 | } |
| 2046 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2047 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2048 | memory_barrier->SetLocations(nullptr); |
| 2049 | } |
| 2050 | |
| 2051 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2052 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2053 | } |
| 2054 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2055 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2056 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2059 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2060 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2063 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2064 | LocationSummary* locations = |
| 2065 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2066 | switch (ret->InputAt(0)->GetType()) { |
| 2067 | case Primitive::kPrimBoolean: |
| 2068 | case Primitive::kPrimByte: |
| 2069 | case Primitive::kPrimChar: |
| 2070 | case Primitive::kPrimShort: |
| 2071 | case Primitive::kPrimInt: |
| 2072 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2073 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2074 | break; |
| 2075 | |
| 2076 | case Primitive::kPrimLong: |
| 2077 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2078 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2079 | break; |
| 2080 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2081 | case Primitive::kPrimFloat: |
| 2082 | case Primitive::kPrimDouble: |
| 2083 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2084 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2085 | break; |
| 2086 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2087 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2088 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2089 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2092 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2093 | if (kIsDebugBuild) { |
| 2094 | switch (ret->InputAt(0)->GetType()) { |
| 2095 | case Primitive::kPrimBoolean: |
| 2096 | case Primitive::kPrimByte: |
| 2097 | case Primitive::kPrimChar: |
| 2098 | case Primitive::kPrimShort: |
| 2099 | case Primitive::kPrimInt: |
| 2100 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2101 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2102 | break; |
| 2103 | |
| 2104 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2105 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2106 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2107 | break; |
| 2108 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2109 | case Primitive::kPrimFloat: |
| 2110 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2111 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2112 | break; |
| 2113 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2114 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2115 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2116 | } |
| 2117 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2118 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2121 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2122 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2123 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2124 | // the method_idx. |
| 2125 | HandleInvoke(invoke); |
| 2126 | } |
| 2127 | |
| 2128 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2129 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2130 | } |
| 2131 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2132 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2133 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2134 | // art::PrepareForRegisterAllocation. |
| 2135 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2136 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2137 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2138 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2139 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2140 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2141 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2142 | return; |
| 2143 | } |
| 2144 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2145 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2146 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2147 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2148 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2149 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2150 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2151 | } |
| 2152 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2153 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2154 | if (invoke->GetLocations()->Intrinsified()) { |
| 2155 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2156 | intrinsic.Dispatch(invoke); |
| 2157 | return true; |
| 2158 | } |
| 2159 | return false; |
| 2160 | } |
| 2161 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2162 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2163 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2164 | // art::PrepareForRegisterAllocation. |
| 2165 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2166 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2167 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2168 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2169 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2170 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2171 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2172 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2173 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2174 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2178 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2179 | if (intrinsic.TryDispatch(invoke)) { |
| 2180 | return; |
| 2181 | } |
| 2182 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2183 | HandleInvoke(invoke); |
| 2184 | } |
| 2185 | |
| 2186 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2187 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2188 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2191 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2192 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2193 | return; |
| 2194 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2195 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2196 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2197 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2198 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2201 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2202 | // This call to HandleInvoke allocates a temporary (core) register |
| 2203 | // which is also used to transfer the hidden argument from FP to |
| 2204 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2205 | HandleInvoke(invoke); |
| 2206 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2207 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2211 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2212 | LocationSummary* locations = invoke->GetLocations(); |
| 2213 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2214 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2215 | Location receiver = locations->InAt(0); |
| 2216 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2217 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2218 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2219 | // won't be modified thereafter, before the `call` instruction. |
| 2220 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2221 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2222 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2223 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2224 | if (receiver.IsStackSlot()) { |
| 2225 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2226 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2227 | __ movl(temp, Address(temp, class_offset)); |
| 2228 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2229 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2230 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2231 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2232 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2233 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2234 | // emit a read barrier for the previous class reference load. |
| 2235 | // However this is not required in practice, as this is an |
| 2236 | // intermediate/temporary reference and because the current |
| 2237 | // concurrent copying collector keeps the from-space memory |
| 2238 | // intact/accessible until the end of the marking phase (the |
| 2239 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2240 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2241 | // temp = temp->GetAddressOfIMT() |
| 2242 | __ movl(temp, |
| 2243 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2244 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2245 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2246 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2247 | __ movl(temp, Address(temp, method_offset)); |
| 2248 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2249 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2250 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2251 | |
| 2252 | DCHECK(!codegen_->IsLeafMethod()); |
| 2253 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2254 | } |
| 2255 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2256 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2257 | HandleInvoke(invoke); |
| 2258 | } |
| 2259 | |
| 2260 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2261 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2262 | } |
| 2263 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2264 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2265 | LocationSummary* locations = |
| 2266 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2267 | switch (neg->GetResultType()) { |
| 2268 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2269 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2270 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2271 | locations->SetOut(Location::SameAsFirstInput()); |
| 2272 | break; |
| 2273 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2274 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2275 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2276 | locations->SetOut(Location::SameAsFirstInput()); |
| 2277 | locations->AddTemp(Location::RequiresRegister()); |
| 2278 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2279 | break; |
| 2280 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2281 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2282 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2283 | locations->SetOut(Location::SameAsFirstInput()); |
| 2284 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2285 | break; |
| 2286 | |
| 2287 | default: |
| 2288 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2293 | LocationSummary* locations = neg->GetLocations(); |
| 2294 | Location out = locations->Out(); |
| 2295 | Location in = locations->InAt(0); |
| 2296 | switch (neg->GetResultType()) { |
| 2297 | case Primitive::kPrimInt: |
| 2298 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2299 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2300 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2301 | break; |
| 2302 | |
| 2303 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2304 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2305 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2306 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2307 | // Negation is similar to subtraction from zero. The least |
| 2308 | // significant byte triggers a borrow when it is different from |
| 2309 | // zero; to take it into account, add 1 to the most significant |
| 2310 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2311 | // operation. |
| 2312 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2313 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2314 | break; |
| 2315 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimFloat: { |
| 2317 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2318 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2319 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2320 | // Implement float negation with an exclusive or with value |
| 2321 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2322 | // single-precision floating-point number). |
| 2323 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2324 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2325 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2326 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2327 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2328 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2329 | case Primitive::kPrimDouble: { |
| 2330 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2331 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2332 | // Implement double negation with an exclusive or with value |
| 2333 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2334 | // a double-precision floating-point number). |
| 2335 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2336 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2337 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2338 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2339 | |
| 2340 | default: |
| 2341 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2342 | } |
| 2343 | } |
| 2344 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2345 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2346 | LocationSummary* locations = |
| 2347 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2348 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2349 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2350 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2351 | locations->SetOut(Location::SameAsFirstInput()); |
| 2352 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2353 | } |
| 2354 | |
| 2355 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2356 | LocationSummary* locations = neg->GetLocations(); |
| 2357 | Location out = locations->Out(); |
| 2358 | DCHECK(locations->InAt(0).Equals(out)); |
| 2359 | |
| 2360 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2361 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2362 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2363 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2364 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2365 | } else { |
| 2366 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2367 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2368 | } |
| 2369 | } |
| 2370 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2371 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2372 | Primitive::Type result_type = conversion->GetResultType(); |
| 2373 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2374 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2375 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2376 | // The float-to-long and double-to-long type conversions rely on a |
| 2377 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2378 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2379 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2380 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2381 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2382 | : LocationSummary::kNoCall; |
| 2383 | LocationSummary* locations = |
| 2384 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2385 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2386 | // The Java language does not allow treating boolean as an integral type but |
| 2387 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2388 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2389 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2390 | case Primitive::kPrimByte: |
| 2391 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2392 | case Primitive::kPrimLong: { |
| 2393 | // Type conversion from long to byte is a result of code transformations. |
| 2394 | HInstruction* input = conversion->InputAt(0); |
| 2395 | Location input_location = input->IsConstant() |
| 2396 | ? Location::ConstantLocation(input->AsConstant()) |
| 2397 | : Location::RegisterPairLocation(EAX, EDX); |
| 2398 | locations->SetInAt(0, input_location); |
| 2399 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2400 | // the validation of the linear scan implementation |
| 2401 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2402 | break; |
| 2403 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2404 | case Primitive::kPrimBoolean: |
| 2405 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2406 | case Primitive::kPrimShort: |
| 2407 | case Primitive::kPrimInt: |
| 2408 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2409 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2410 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2411 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2412 | // the validation of the linear scan implementation |
| 2413 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2414 | break; |
| 2415 | |
| 2416 | default: |
| 2417 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2418 | << " to " << result_type; |
| 2419 | } |
| 2420 | break; |
| 2421 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2422 | case Primitive::kPrimShort: |
| 2423 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2424 | case Primitive::kPrimLong: |
| 2425 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2426 | case Primitive::kPrimBoolean: |
| 2427 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2428 | case Primitive::kPrimByte: |
| 2429 | case Primitive::kPrimInt: |
| 2430 | case Primitive::kPrimChar: |
| 2431 | // Processing a Dex `int-to-short' instruction. |
| 2432 | locations->SetInAt(0, Location::Any()); |
| 2433 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2434 | break; |
| 2435 | |
| 2436 | default: |
| 2437 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2438 | << " to " << result_type; |
| 2439 | } |
| 2440 | break; |
| 2441 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2442 | case Primitive::kPrimInt: |
| 2443 | switch (input_type) { |
| 2444 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2445 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2446 | locations->SetInAt(0, Location::Any()); |
| 2447 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2448 | break; |
| 2449 | |
| 2450 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2451 | // Processing a Dex `float-to-int' instruction. |
| 2452 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2453 | locations->SetOut(Location::RequiresRegister()); |
| 2454 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2455 | break; |
| 2456 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2457 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2458 | // Processing a Dex `double-to-int' instruction. |
| 2459 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2460 | locations->SetOut(Location::RequiresRegister()); |
| 2461 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2462 | break; |
| 2463 | |
| 2464 | default: |
| 2465 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2466 | << " to " << result_type; |
| 2467 | } |
| 2468 | break; |
| 2469 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2470 | case Primitive::kPrimLong: |
| 2471 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2472 | case Primitive::kPrimBoolean: |
| 2473 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2474 | case Primitive::kPrimByte: |
| 2475 | case Primitive::kPrimShort: |
| 2476 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2477 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2478 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2479 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2480 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2481 | break; |
| 2482 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2483 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2484 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2485 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2486 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2487 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2488 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2489 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2490 | // The runtime helper puts the result in EAX, EDX. |
| 2491 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2492 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2493 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2494 | |
| 2495 | default: |
| 2496 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2497 | << " to " << result_type; |
| 2498 | } |
| 2499 | break; |
| 2500 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2501 | case Primitive::kPrimChar: |
| 2502 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2503 | case Primitive::kPrimLong: |
| 2504 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2505 | case Primitive::kPrimBoolean: |
| 2506 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2507 | case Primitive::kPrimByte: |
| 2508 | case Primitive::kPrimShort: |
| 2509 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2510 | // Processing a Dex `int-to-char' instruction. |
| 2511 | locations->SetInAt(0, Location::Any()); |
| 2512 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2513 | break; |
| 2514 | |
| 2515 | default: |
| 2516 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2517 | << " to " << result_type; |
| 2518 | } |
| 2519 | break; |
| 2520 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2521 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2522 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2523 | case Primitive::kPrimBoolean: |
| 2524 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2525 | case Primitive::kPrimByte: |
| 2526 | case Primitive::kPrimShort: |
| 2527 | case Primitive::kPrimInt: |
| 2528 | case Primitive::kPrimChar: |
| 2529 | // Processing a Dex `int-to-float' instruction. |
| 2530 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2531 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2532 | break; |
| 2533 | |
| 2534 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2535 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2536 | locations->SetInAt(0, Location::Any()); |
| 2537 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2540 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2541 | // Processing a Dex `double-to-float' instruction. |
| 2542 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2543 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2544 | break; |
| 2545 | |
| 2546 | default: |
| 2547 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2548 | << " to " << result_type; |
| 2549 | }; |
| 2550 | break; |
| 2551 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2552 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2553 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2554 | case Primitive::kPrimBoolean: |
| 2555 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2556 | case Primitive::kPrimByte: |
| 2557 | case Primitive::kPrimShort: |
| 2558 | case Primitive::kPrimInt: |
| 2559 | case Primitive::kPrimChar: |
| 2560 | // Processing a Dex `int-to-double' instruction. |
| 2561 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2562 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2563 | break; |
| 2564 | |
| 2565 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2566 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2567 | locations->SetInAt(0, Location::Any()); |
| 2568 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2569 | break; |
| 2570 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2571 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2572 | // Processing a Dex `float-to-double' instruction. |
| 2573 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2574 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2575 | break; |
| 2576 | |
| 2577 | default: |
| 2578 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2579 | << " to " << result_type; |
| 2580 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2581 | break; |
| 2582 | |
| 2583 | default: |
| 2584 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2585 | << " to " << result_type; |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2590 | LocationSummary* locations = conversion->GetLocations(); |
| 2591 | Location out = locations->Out(); |
| 2592 | Location in = locations->InAt(0); |
| 2593 | Primitive::Type result_type = conversion->GetResultType(); |
| 2594 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2595 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2596 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2597 | case Primitive::kPrimByte: |
| 2598 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2599 | case Primitive::kPrimLong: |
| 2600 | // Type conversion from long to byte is a result of code transformations. |
| 2601 | if (in.IsRegisterPair()) { |
| 2602 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2603 | } else { |
| 2604 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2605 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2606 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2607 | } |
| 2608 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2609 | case Primitive::kPrimBoolean: |
| 2610 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2611 | case Primitive::kPrimShort: |
| 2612 | case Primitive::kPrimInt: |
| 2613 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2614 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2615 | if (in.IsRegister()) { |
| 2616 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2617 | } else { |
| 2618 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2619 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2620 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2621 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2622 | break; |
| 2623 | |
| 2624 | default: |
| 2625 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2626 | << " to " << result_type; |
| 2627 | } |
| 2628 | break; |
| 2629 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2630 | case Primitive::kPrimShort: |
| 2631 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2632 | case Primitive::kPrimLong: |
| 2633 | // Type conversion from long to short is a result of code transformations. |
| 2634 | if (in.IsRegisterPair()) { |
| 2635 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2636 | } else if (in.IsDoubleStackSlot()) { |
| 2637 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2638 | } else { |
| 2639 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2640 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2641 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2642 | } |
| 2643 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2644 | case Primitive::kPrimBoolean: |
| 2645 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2646 | case Primitive::kPrimByte: |
| 2647 | case Primitive::kPrimInt: |
| 2648 | case Primitive::kPrimChar: |
| 2649 | // Processing a Dex `int-to-short' instruction. |
| 2650 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2651 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2652 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2653 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2654 | } else { |
| 2655 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2656 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2657 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2658 | } |
| 2659 | break; |
| 2660 | |
| 2661 | default: |
| 2662 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2663 | << " to " << result_type; |
| 2664 | } |
| 2665 | break; |
| 2666 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2667 | case Primitive::kPrimInt: |
| 2668 | switch (input_type) { |
| 2669 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2670 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2671 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2672 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2673 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2674 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2675 | } else { |
| 2676 | DCHECK(in.IsConstant()); |
| 2677 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2678 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2679 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2680 | } |
| 2681 | break; |
| 2682 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2683 | case Primitive::kPrimFloat: { |
| 2684 | // Processing a Dex `float-to-int' instruction. |
| 2685 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2686 | Register output = out.AsRegister<Register>(); |
| 2687 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2688 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2689 | |
| 2690 | __ movl(output, Immediate(kPrimIntMax)); |
| 2691 | // temp = int-to-float(output) |
| 2692 | __ cvtsi2ss(temp, output); |
| 2693 | // if input >= temp goto done |
| 2694 | __ comiss(input, temp); |
| 2695 | __ j(kAboveEqual, &done); |
| 2696 | // if input == NaN goto nan |
| 2697 | __ j(kUnordered, &nan); |
| 2698 | // output = float-to-int-truncate(input) |
| 2699 | __ cvttss2si(output, input); |
| 2700 | __ jmp(&done); |
| 2701 | __ Bind(&nan); |
| 2702 | // output = 0 |
| 2703 | __ xorl(output, output); |
| 2704 | __ Bind(&done); |
| 2705 | break; |
| 2706 | } |
| 2707 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2708 | case Primitive::kPrimDouble: { |
| 2709 | // Processing a Dex `double-to-int' instruction. |
| 2710 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2711 | Register output = out.AsRegister<Register>(); |
| 2712 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2713 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2714 | |
| 2715 | __ movl(output, Immediate(kPrimIntMax)); |
| 2716 | // temp = int-to-double(output) |
| 2717 | __ cvtsi2sd(temp, output); |
| 2718 | // if input >= temp goto done |
| 2719 | __ comisd(input, temp); |
| 2720 | __ j(kAboveEqual, &done); |
| 2721 | // if input == NaN goto nan |
| 2722 | __ j(kUnordered, &nan); |
| 2723 | // output = double-to-int-truncate(input) |
| 2724 | __ cvttsd2si(output, input); |
| 2725 | __ jmp(&done); |
| 2726 | __ Bind(&nan); |
| 2727 | // output = 0 |
| 2728 | __ xorl(output, output); |
| 2729 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2730 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2731 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2732 | |
| 2733 | default: |
| 2734 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2735 | << " to " << result_type; |
| 2736 | } |
| 2737 | break; |
| 2738 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2739 | case Primitive::kPrimLong: |
| 2740 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2741 | case Primitive::kPrimBoolean: |
| 2742 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2743 | case Primitive::kPrimByte: |
| 2744 | case Primitive::kPrimShort: |
| 2745 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2746 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2747 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2748 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2749 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2750 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2751 | __ cdq(); |
| 2752 | break; |
| 2753 | |
| 2754 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2755 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2756 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2757 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2758 | break; |
| 2759 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2760 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2761 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2762 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2763 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2764 | break; |
| 2765 | |
| 2766 | default: |
| 2767 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2768 | << " to " << result_type; |
| 2769 | } |
| 2770 | break; |
| 2771 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2772 | case Primitive::kPrimChar: |
| 2773 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2774 | case Primitive::kPrimLong: |
| 2775 | // Type conversion from long to short is a result of code transformations. |
| 2776 | if (in.IsRegisterPair()) { |
| 2777 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2778 | } else if (in.IsDoubleStackSlot()) { |
| 2779 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2780 | } else { |
| 2781 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2782 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2783 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2784 | } |
| 2785 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2786 | case Primitive::kPrimBoolean: |
| 2787 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2788 | case Primitive::kPrimByte: |
| 2789 | case Primitive::kPrimShort: |
| 2790 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2791 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2792 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2793 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2794 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2795 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2796 | } else { |
| 2797 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2798 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2799 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2800 | } |
| 2801 | break; |
| 2802 | |
| 2803 | default: |
| 2804 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2805 | << " to " << result_type; |
| 2806 | } |
| 2807 | break; |
| 2808 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2809 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2810 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2811 | case Primitive::kPrimBoolean: |
| 2812 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2813 | case Primitive::kPrimByte: |
| 2814 | case Primitive::kPrimShort: |
| 2815 | case Primitive::kPrimInt: |
| 2816 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2817 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2818 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2819 | break; |
| 2820 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2821 | case Primitive::kPrimLong: { |
| 2822 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2823 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2824 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2825 | // Create stack space for the call to |
| 2826 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2827 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2828 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2829 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2830 | __ subl(ESP, Immediate(adjustment)); |
| 2831 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2832 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2833 | // Load the value to the FP stack, using temporaries if needed. |
| 2834 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2835 | |
| 2836 | if (out.IsStackSlot()) { |
| 2837 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2838 | } else { |
| 2839 | __ fstps(Address(ESP, 0)); |
| 2840 | Location stack_temp = Location::StackSlot(0); |
| 2841 | codegen_->Move32(out, stack_temp); |
| 2842 | } |
| 2843 | |
| 2844 | // Remove the temporary stack space we allocated. |
| 2845 | if (adjustment != 0) { |
| 2846 | __ addl(ESP, Immediate(adjustment)); |
| 2847 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2848 | break; |
| 2849 | } |
| 2850 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2851 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2852 | // Processing a Dex `double-to-float' instruction. |
| 2853 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2854 | break; |
| 2855 | |
| 2856 | default: |
| 2857 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2858 | << " to " << result_type; |
| 2859 | }; |
| 2860 | break; |
| 2861 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2862 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2863 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2864 | case Primitive::kPrimBoolean: |
| 2865 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2866 | case Primitive::kPrimByte: |
| 2867 | case Primitive::kPrimShort: |
| 2868 | case Primitive::kPrimInt: |
| 2869 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2870 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2871 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2872 | break; |
| 2873 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2874 | case Primitive::kPrimLong: { |
| 2875 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2876 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2877 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2878 | // Create stack space for the call to |
| 2879 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2880 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2881 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2882 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2883 | __ subl(ESP, Immediate(adjustment)); |
| 2884 | } |
| 2885 | |
| 2886 | // Load the value to the FP stack, using temporaries if needed. |
| 2887 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2888 | |
| 2889 | if (out.IsDoubleStackSlot()) { |
| 2890 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2891 | } else { |
| 2892 | __ fstpl(Address(ESP, 0)); |
| 2893 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2894 | codegen_->Move64(out, stack_temp); |
| 2895 | } |
| 2896 | |
| 2897 | // Remove the temporary stack space we allocated. |
| 2898 | if (adjustment != 0) { |
| 2899 | __ addl(ESP, Immediate(adjustment)); |
| 2900 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2901 | break; |
| 2902 | } |
| 2903 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2904 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2905 | // Processing a Dex `float-to-double' instruction. |
| 2906 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2907 | break; |
| 2908 | |
| 2909 | default: |
| 2910 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2911 | << " to " << result_type; |
| 2912 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2913 | break; |
| 2914 | |
| 2915 | default: |
| 2916 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2917 | << " to " << result_type; |
| 2918 | } |
| 2919 | } |
| 2920 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2921 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2922 | LocationSummary* locations = |
| 2923 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2924 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2925 | case Primitive::kPrimInt: { |
| 2926 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2927 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2928 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2929 | break; |
| 2930 | } |
| 2931 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2932 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2933 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2934 | locations->SetInAt(1, Location::Any()); |
| 2935 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2936 | break; |
| 2937 | } |
| 2938 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2939 | case Primitive::kPrimFloat: |
| 2940 | case Primitive::kPrimDouble: { |
| 2941 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2942 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2943 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2944 | } else if (add->InputAt(1)->IsConstant()) { |
| 2945 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2946 | } else { |
| 2947 | locations->SetInAt(1, Location::Any()); |
| 2948 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2949 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2950 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2951 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2952 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2953 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2954 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2955 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2956 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2960 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2961 | Location first = locations->InAt(0); |
| 2962 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2963 | Location out = locations->Out(); |
| 2964 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2965 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2966 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2967 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2968 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2969 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2970 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2971 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2972 | } else { |
| 2973 | __ leal(out.AsRegister<Register>(), Address( |
| 2974 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2975 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2976 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2977 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2978 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2979 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2980 | } else { |
| 2981 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2982 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2983 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2984 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2985 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2986 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2987 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2991 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2992 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2993 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2994 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2995 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2996 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2997 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2998 | } else { |
| 2999 | DCHECK(second.IsConstant()) << second; |
| 3000 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3001 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3002 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3003 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3004 | break; |
| 3005 | } |
| 3006 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3007 | case Primitive::kPrimFloat: { |
| 3008 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3009 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3010 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3011 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3012 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3013 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3014 | codegen_->LiteralFloatAddress( |
| 3015 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3016 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3017 | } else { |
| 3018 | DCHECK(second.IsStackSlot()); |
| 3019 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3020 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3021 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | case Primitive::kPrimDouble: { |
| 3025 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3026 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3027 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3028 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3029 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3030 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3031 | codegen_->LiteralDoubleAddress( |
| 3032 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3033 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3034 | } else { |
| 3035 | DCHECK(second.IsDoubleStackSlot()); |
| 3036 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3037 | } |
| 3038 | break; |
| 3039 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3040 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3041 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3042 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3043 | } |
| 3044 | } |
| 3045 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3046 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3047 | LocationSummary* locations = |
| 3048 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3049 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3050 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3051 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3052 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3053 | locations->SetInAt(1, Location::Any()); |
| 3054 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3055 | break; |
| 3056 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3057 | case Primitive::kPrimFloat: |
| 3058 | case Primitive::kPrimDouble: { |
| 3059 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3060 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3061 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3062 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3063 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3064 | } else { |
| 3065 | locations->SetInAt(1, Location::Any()); |
| 3066 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3067 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3068 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3069 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3070 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3071 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3072 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3073 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3077 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3078 | Location first = locations->InAt(0); |
| 3079 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3080 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3081 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3082 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3083 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3084 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3085 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3086 | __ subl(first.AsRegister<Register>(), |
| 3087 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3088 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3089 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3090 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3091 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3095 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3096 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3097 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3098 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3099 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3100 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3101 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3102 | } else { |
| 3103 | DCHECK(second.IsConstant()) << second; |
| 3104 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3105 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3106 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3107 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3108 | break; |
| 3109 | } |
| 3110 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3111 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3112 | if (second.IsFpuRegister()) { |
| 3113 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3114 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3115 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3116 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3117 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3118 | codegen_->LiteralFloatAddress( |
| 3119 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3120 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3121 | } else { |
| 3122 | DCHECK(second.IsStackSlot()); |
| 3123 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3124 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3125 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3129 | if (second.IsFpuRegister()) { |
| 3130 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3131 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3132 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3133 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3134 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3135 | codegen_->LiteralDoubleAddress( |
| 3136 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3137 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3138 | } else { |
| 3139 | DCHECK(second.IsDoubleStackSlot()); |
| 3140 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3141 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3142 | break; |
| 3143 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3144 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3145 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3146 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3147 | } |
| 3148 | } |
| 3149 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3150 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3151 | LocationSummary* locations = |
| 3152 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3153 | switch (mul->GetResultType()) { |
| 3154 | case Primitive::kPrimInt: |
| 3155 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3156 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3157 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3158 | // Can use 3 operand multiply. |
| 3159 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3160 | } else { |
| 3161 | locations->SetOut(Location::SameAsFirstInput()); |
| 3162 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3163 | break; |
| 3164 | case Primitive::kPrimLong: { |
| 3165 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3166 | locations->SetInAt(1, Location::Any()); |
| 3167 | locations->SetOut(Location::SameAsFirstInput()); |
| 3168 | // Needed for imul on 32bits with 64bits output. |
| 3169 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3170 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3171 | break; |
| 3172 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3173 | case Primitive::kPrimFloat: |
| 3174 | case Primitive::kPrimDouble: { |
| 3175 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3176 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3177 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3178 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3179 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3180 | } else { |
| 3181 | locations->SetInAt(1, Location::Any()); |
| 3182 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3183 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3184 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3185 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3186 | |
| 3187 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3188 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3193 | LocationSummary* locations = mul->GetLocations(); |
| 3194 | Location first = locations->InAt(0); |
| 3195 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3196 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3197 | |
| 3198 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3199 | case Primitive::kPrimInt: |
| 3200 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3201 | // problems where the output may not be the same as the first operand. |
| 3202 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3203 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3204 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3205 | } else if (second.IsRegister()) { |
| 3206 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3207 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3208 | } else { |
| 3209 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3210 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3211 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3212 | } |
| 3213 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3214 | |
| 3215 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3216 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3217 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3218 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3219 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3220 | |
| 3221 | DCHECK_EQ(EAX, eax); |
| 3222 | DCHECK_EQ(EDX, edx); |
| 3223 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3224 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3225 | // output: in1 |
| 3226 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3227 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3228 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3229 | if (second.IsConstant()) { |
| 3230 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3231 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3232 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3233 | int32_t low_value = Low32Bits(value); |
| 3234 | int32_t high_value = High32Bits(value); |
| 3235 | Immediate low(low_value); |
| 3236 | Immediate high(high_value); |
| 3237 | |
| 3238 | __ movl(eax, high); |
| 3239 | // eax <- in1.lo * in2.hi |
| 3240 | __ imull(eax, in1_lo); |
| 3241 | // in1.hi <- in1.hi * in2.lo |
| 3242 | __ imull(in1_hi, low); |
| 3243 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3244 | __ addl(in1_hi, eax); |
| 3245 | // move in2_lo to eax to prepare for double precision |
| 3246 | __ movl(eax, low); |
| 3247 | // edx:eax <- in1.lo * in2.lo |
| 3248 | __ mull(in1_lo); |
| 3249 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3250 | __ addl(in1_hi, edx); |
| 3251 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3252 | __ movl(in1_lo, eax); |
| 3253 | } else if (second.IsRegisterPair()) { |
| 3254 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3255 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3256 | |
| 3257 | __ movl(eax, in2_hi); |
| 3258 | // eax <- in1.lo * in2.hi |
| 3259 | __ imull(eax, in1_lo); |
| 3260 | // in1.hi <- in1.hi * in2.lo |
| 3261 | __ imull(in1_hi, in2_lo); |
| 3262 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3263 | __ addl(in1_hi, eax); |
| 3264 | // move in1_lo to eax to prepare for double precision |
| 3265 | __ movl(eax, in1_lo); |
| 3266 | // edx:eax <- in1.lo * in2.lo |
| 3267 | __ mull(in2_lo); |
| 3268 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3269 | __ addl(in1_hi, edx); |
| 3270 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3271 | __ movl(in1_lo, eax); |
| 3272 | } else { |
| 3273 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3274 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3275 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3276 | |
| 3277 | __ movl(eax, in2_hi); |
| 3278 | // eax <- in1.lo * in2.hi |
| 3279 | __ imull(eax, in1_lo); |
| 3280 | // in1.hi <- in1.hi * in2.lo |
| 3281 | __ imull(in1_hi, in2_lo); |
| 3282 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3283 | __ addl(in1_hi, eax); |
| 3284 | // move in1_lo to eax to prepare for double precision |
| 3285 | __ movl(eax, in1_lo); |
| 3286 | // edx:eax <- in1.lo * in2.lo |
| 3287 | __ mull(in2_lo); |
| 3288 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3289 | __ addl(in1_hi, edx); |
| 3290 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3291 | __ movl(in1_lo, eax); |
| 3292 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3293 | |
| 3294 | break; |
| 3295 | } |
| 3296 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3297 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3298 | DCHECK(first.Equals(locations->Out())); |
| 3299 | if (second.IsFpuRegister()) { |
| 3300 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3301 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3302 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3303 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3304 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3305 | codegen_->LiteralFloatAddress( |
| 3306 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3307 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3308 | } else { |
| 3309 | DCHECK(second.IsStackSlot()); |
| 3310 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3311 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3312 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3316 | DCHECK(first.Equals(locations->Out())); |
| 3317 | if (second.IsFpuRegister()) { |
| 3318 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3319 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3320 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3321 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3322 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3323 | codegen_->LiteralDoubleAddress( |
| 3324 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3325 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3326 | } else { |
| 3327 | DCHECK(second.IsDoubleStackSlot()); |
| 3328 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3329 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3330 | break; |
| 3331 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3332 | |
| 3333 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3334 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3335 | } |
| 3336 | } |
| 3337 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3338 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3339 | uint32_t temp_offset, |
| 3340 | uint32_t stack_adjustment, |
| 3341 | bool is_fp, |
| 3342 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3343 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3344 | DCHECK(!is_wide); |
| 3345 | if (is_fp) { |
| 3346 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3347 | } else { |
| 3348 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3349 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3350 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3351 | DCHECK(is_wide); |
| 3352 | if (is_fp) { |
| 3353 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3354 | } else { |
| 3355 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3356 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3357 | } else { |
| 3358 | // 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] | 3359 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3360 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3361 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3362 | if (is_fp) { |
| 3363 | __ flds(Address(ESP, temp_offset)); |
| 3364 | } else { |
| 3365 | __ filds(Address(ESP, temp_offset)); |
| 3366 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3367 | } else { |
| 3368 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3369 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3370 | if (is_fp) { |
| 3371 | __ fldl(Address(ESP, temp_offset)); |
| 3372 | } else { |
| 3373 | __ fildl(Address(ESP, temp_offset)); |
| 3374 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3375 | } |
| 3376 | } |
| 3377 | } |
| 3378 | |
| 3379 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3380 | Primitive::Type type = rem->GetResultType(); |
| 3381 | bool is_float = type == Primitive::kPrimFloat; |
| 3382 | size_t elem_size = Primitive::ComponentSize(type); |
| 3383 | LocationSummary* locations = rem->GetLocations(); |
| 3384 | Location first = locations->InAt(0); |
| 3385 | Location second = locations->InAt(1); |
| 3386 | Location out = locations->Out(); |
| 3387 | |
| 3388 | // Create stack space for 2 elements. |
| 3389 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3390 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3391 | |
| 3392 | // 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] | 3393 | const bool is_wide = !is_float; |
| 3394 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3395 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3396 | |
| 3397 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3398 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3399 | __ Bind(&retry); |
| 3400 | __ fprem(); |
| 3401 | |
| 3402 | // Move FP status to AX. |
| 3403 | __ fstsw(); |
| 3404 | |
| 3405 | // And see if the argument reduction is complete. This is signaled by the |
| 3406 | // C2 FPU flag bit set to 0. |
| 3407 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3408 | __ j(kNotEqual, &retry); |
| 3409 | |
| 3410 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3411 | // Store FP top of stack to real stack. |
| 3412 | if (is_float) { |
| 3413 | __ fsts(Address(ESP, 0)); |
| 3414 | } else { |
| 3415 | __ fstl(Address(ESP, 0)); |
| 3416 | } |
| 3417 | |
| 3418 | // Pop the 2 items from the FP stack. |
| 3419 | __ fucompp(); |
| 3420 | |
| 3421 | // Load the value from the stack into an XMM register. |
| 3422 | DCHECK(out.IsFpuRegister()) << out; |
| 3423 | if (is_float) { |
| 3424 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3425 | } else { |
| 3426 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3427 | } |
| 3428 | |
| 3429 | // And remove the temporary stack space we allocated. |
| 3430 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3431 | } |
| 3432 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3433 | |
| 3434 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3435 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3436 | |
| 3437 | LocationSummary* locations = instruction->GetLocations(); |
| 3438 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3439 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3440 | |
| 3441 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3442 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3443 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3444 | |
| 3445 | DCHECK(imm == 1 || imm == -1); |
| 3446 | |
| 3447 | if (instruction->IsRem()) { |
| 3448 | __ xorl(out_register, out_register); |
| 3449 | } else { |
| 3450 | __ movl(out_register, input_register); |
| 3451 | if (imm == -1) { |
| 3452 | __ negl(out_register); |
| 3453 | } |
| 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3458 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3459 | LocationSummary* locations = instruction->GetLocations(); |
| 3460 | |
| 3461 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3462 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3463 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3464 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3465 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3466 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3467 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3468 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3469 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3470 | __ testl(input_register, input_register); |
| 3471 | __ cmovl(kGreaterEqual, num, input_register); |
| 3472 | int shift = CTZ(imm); |
| 3473 | __ sarl(num, Immediate(shift)); |
| 3474 | |
| 3475 | if (imm < 0) { |
| 3476 | __ negl(num); |
| 3477 | } |
| 3478 | |
| 3479 | __ movl(out_register, num); |
| 3480 | } |
| 3481 | |
| 3482 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3483 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3484 | |
| 3485 | LocationSummary* locations = instruction->GetLocations(); |
| 3486 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3487 | |
| 3488 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3489 | Register out = locations->Out().AsRegister<Register>(); |
| 3490 | Register num; |
| 3491 | Register edx; |
| 3492 | |
| 3493 | if (instruction->IsDiv()) { |
| 3494 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3495 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3496 | } else { |
| 3497 | edx = locations->Out().AsRegister<Register>(); |
| 3498 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3499 | } |
| 3500 | |
| 3501 | DCHECK_EQ(EAX, eax); |
| 3502 | DCHECK_EQ(EDX, edx); |
| 3503 | if (instruction->IsDiv()) { |
| 3504 | DCHECK_EQ(EAX, out); |
| 3505 | } else { |
| 3506 | DCHECK_EQ(EDX, out); |
| 3507 | } |
| 3508 | |
| 3509 | int64_t magic; |
| 3510 | int shift; |
| 3511 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3512 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3513 | // Save the numerator. |
| 3514 | __ movl(num, eax); |
| 3515 | |
| 3516 | // EAX = magic |
| 3517 | __ movl(eax, Immediate(magic)); |
| 3518 | |
| 3519 | // EDX:EAX = magic * numerator |
| 3520 | __ imull(num); |
| 3521 | |
| 3522 | if (imm > 0 && magic < 0) { |
| 3523 | // EDX += num |
| 3524 | __ addl(edx, num); |
| 3525 | } else if (imm < 0 && magic > 0) { |
| 3526 | __ subl(edx, num); |
| 3527 | } |
| 3528 | |
| 3529 | // Shift if needed. |
| 3530 | if (shift != 0) { |
| 3531 | __ sarl(edx, Immediate(shift)); |
| 3532 | } |
| 3533 | |
| 3534 | // EDX += 1 if EDX < 0 |
| 3535 | __ movl(eax, edx); |
| 3536 | __ shrl(edx, Immediate(31)); |
| 3537 | __ addl(edx, eax); |
| 3538 | |
| 3539 | if (instruction->IsRem()) { |
| 3540 | __ movl(eax, num); |
| 3541 | __ imull(edx, Immediate(imm)); |
| 3542 | __ subl(eax, edx); |
| 3543 | __ movl(edx, eax); |
| 3544 | } else { |
| 3545 | __ movl(eax, edx); |
| 3546 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3547 | } |
| 3548 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3549 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3550 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3551 | |
| 3552 | LocationSummary* locations = instruction->GetLocations(); |
| 3553 | Location out = locations->Out(); |
| 3554 | Location first = locations->InAt(0); |
| 3555 | Location second = locations->InAt(1); |
| 3556 | bool is_div = instruction->IsDiv(); |
| 3557 | |
| 3558 | switch (instruction->GetResultType()) { |
| 3559 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3560 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3561 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3562 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3563 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3564 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3565 | |
| 3566 | if (imm == 0) { |
| 3567 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3568 | } else if (imm == 1 || imm == -1) { |
| 3569 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3570 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3571 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3572 | } else { |
| 3573 | DCHECK(imm <= -2 || imm >= 2); |
| 3574 | GenerateDivRemWithAnyConstant(instruction); |
| 3575 | } |
| 3576 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3577 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3578 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3579 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3580 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3581 | Register second_reg = second.AsRegister<Register>(); |
| 3582 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3583 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3584 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3585 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3586 | __ cmpl(second_reg, Immediate(-1)); |
| 3587 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3588 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3589 | // edx:eax <- sign-extended of eax |
| 3590 | __ cdq(); |
| 3591 | // eax = quotient, edx = remainder |
| 3592 | __ idivl(second_reg); |
| 3593 | __ Bind(slow_path->GetExitLabel()); |
| 3594 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | } |
| 3597 | |
| 3598 | case Primitive::kPrimLong: { |
| 3599 | InvokeRuntimeCallingConvention calling_convention; |
| 3600 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3601 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3602 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3603 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3604 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3605 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3606 | |
| 3607 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3608 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3609 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3610 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3611 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3612 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3613 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | } |
| 3616 | |
| 3617 | default: |
| 3618 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3619 | } |
| 3620 | } |
| 3621 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3622 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3623 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3624 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3625 | : LocationSummary::kNoCall; |
| 3626 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3627 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3628 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3629 | case Primitive::kPrimInt: { |
| 3630 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3631 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3632 | locations->SetOut(Location::SameAsFirstInput()); |
| 3633 | // Intel uses edx:eax as the dividend. |
| 3634 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3635 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3636 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3637 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3638 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3639 | locations->AddTemp(Location::RequiresRegister()); |
| 3640 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3641 | break; |
| 3642 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3643 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3644 | InvokeRuntimeCallingConvention calling_convention; |
| 3645 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3646 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3647 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3648 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3649 | // Runtime helper puts the result in EAX, EDX. |
| 3650 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3651 | break; |
| 3652 | } |
| 3653 | case Primitive::kPrimFloat: |
| 3654 | case Primitive::kPrimDouble: { |
| 3655 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3656 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3657 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3658 | } else if (div->InputAt(1)->IsConstant()) { |
| 3659 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3660 | } else { |
| 3661 | locations->SetInAt(1, Location::Any()); |
| 3662 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3663 | locations->SetOut(Location::SameAsFirstInput()); |
| 3664 | break; |
| 3665 | } |
| 3666 | |
| 3667 | default: |
| 3668 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3669 | } |
| 3670 | } |
| 3671 | |
| 3672 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3673 | LocationSummary* locations = div->GetLocations(); |
| 3674 | Location first = locations->InAt(0); |
| 3675 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3676 | |
| 3677 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3678 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3679 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3680 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3681 | break; |
| 3682 | } |
| 3683 | |
| 3684 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3685 | if (second.IsFpuRegister()) { |
| 3686 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3687 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3688 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3689 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3690 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3691 | codegen_->LiteralFloatAddress( |
| 3692 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3693 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3694 | } else { |
| 3695 | DCHECK(second.IsStackSlot()); |
| 3696 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3697 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3698 | break; |
| 3699 | } |
| 3700 | |
| 3701 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3702 | if (second.IsFpuRegister()) { |
| 3703 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3704 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3705 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3706 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3707 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3708 | codegen_->LiteralDoubleAddress( |
| 3709 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3710 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3711 | } else { |
| 3712 | DCHECK(second.IsDoubleStackSlot()); |
| 3713 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3714 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3715 | break; |
| 3716 | } |
| 3717 | |
| 3718 | default: |
| 3719 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3720 | } |
| 3721 | } |
| 3722 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3723 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3724 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3725 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3726 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3727 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3728 | : LocationSummary::kNoCall; |
| 3729 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3730 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3731 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3732 | case Primitive::kPrimInt: { |
| 3733 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3734 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3735 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3736 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3737 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3738 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3739 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3740 | locations->AddTemp(Location::RequiresRegister()); |
| 3741 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3742 | break; |
| 3743 | } |
| 3744 | case Primitive::kPrimLong: { |
| 3745 | InvokeRuntimeCallingConvention calling_convention; |
| 3746 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3747 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3748 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3749 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3750 | // Runtime helper puts the result in EAX, EDX. |
| 3751 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3752 | break; |
| 3753 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3754 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3755 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3756 | locations->SetInAt(0, Location::Any()); |
| 3757 | locations->SetInAt(1, Location::Any()); |
| 3758 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3759 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3760 | break; |
| 3761 | } |
| 3762 | |
| 3763 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3764 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3765 | } |
| 3766 | } |
| 3767 | |
| 3768 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3769 | Primitive::Type type = rem->GetResultType(); |
| 3770 | switch (type) { |
| 3771 | case Primitive::kPrimInt: |
| 3772 | case Primitive::kPrimLong: { |
| 3773 | GenerateDivRemIntegral(rem); |
| 3774 | break; |
| 3775 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3776 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3777 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3778 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3779 | break; |
| 3780 | } |
| 3781 | default: |
| 3782 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3783 | } |
| 3784 | } |
| 3785 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3786 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3787 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3788 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3789 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3790 | case Primitive::kPrimByte: |
| 3791 | case Primitive::kPrimChar: |
| 3792 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3793 | case Primitive::kPrimInt: { |
| 3794 | locations->SetInAt(0, Location::Any()); |
| 3795 | break; |
| 3796 | } |
| 3797 | case Primitive::kPrimLong: { |
| 3798 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3799 | if (!instruction->IsConstant()) { |
| 3800 | locations->AddTemp(Location::RequiresRegister()); |
| 3801 | } |
| 3802 | break; |
| 3803 | } |
| 3804 | default: |
| 3805 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3806 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3810 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3811 | codegen_->AddSlowPath(slow_path); |
| 3812 | |
| 3813 | LocationSummary* locations = instruction->GetLocations(); |
| 3814 | Location value = locations->InAt(0); |
| 3815 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3816 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3817 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3818 | case Primitive::kPrimByte: |
| 3819 | case Primitive::kPrimChar: |
| 3820 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3821 | case Primitive::kPrimInt: { |
| 3822 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3823 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3824 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3825 | } else if (value.IsStackSlot()) { |
| 3826 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3827 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3828 | } else { |
| 3829 | DCHECK(value.IsConstant()) << value; |
| 3830 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3831 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3832 | } |
| 3833 | } |
| 3834 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3835 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3836 | case Primitive::kPrimLong: { |
| 3837 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3838 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3839 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3840 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3841 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3842 | } else { |
| 3843 | DCHECK(value.IsConstant()) << value; |
| 3844 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3845 | __ jmp(slow_path->GetEntryLabel()); |
| 3846 | } |
| 3847 | } |
| 3848 | break; |
| 3849 | } |
| 3850 | default: |
| 3851 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3852 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3853 | } |
| 3854 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3855 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3856 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3857 | |
| 3858 | LocationSummary* locations = |
| 3859 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3860 | |
| 3861 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3862 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3863 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3864 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3865 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3866 | // The shift count needs to be in CL or a constant. |
| 3867 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3868 | locations->SetOut(Location::SameAsFirstInput()); |
| 3869 | break; |
| 3870 | } |
| 3871 | default: |
| 3872 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3873 | } |
| 3874 | } |
| 3875 | |
| 3876 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3877 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3878 | |
| 3879 | LocationSummary* locations = op->GetLocations(); |
| 3880 | Location first = locations->InAt(0); |
| 3881 | Location second = locations->InAt(1); |
| 3882 | DCHECK(first.Equals(locations->Out())); |
| 3883 | |
| 3884 | switch (op->GetResultType()) { |
| 3885 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3886 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3887 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3888 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3889 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3890 | DCHECK_EQ(ECX, second_reg); |
| 3891 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3892 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3893 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3894 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3895 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3896 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3897 | } |
| 3898 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3899 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3900 | if (shift == 0) { |
| 3901 | return; |
| 3902 | } |
| 3903 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3904 | if (op->IsShl()) { |
| 3905 | __ shll(first_reg, imm); |
| 3906 | } else if (op->IsShr()) { |
| 3907 | __ sarl(first_reg, imm); |
| 3908 | } else { |
| 3909 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | break; |
| 3913 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3914 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3915 | if (second.IsRegister()) { |
| 3916 | Register second_reg = second.AsRegister<Register>(); |
| 3917 | DCHECK_EQ(ECX, second_reg); |
| 3918 | if (op->IsShl()) { |
| 3919 | GenerateShlLong(first, second_reg); |
| 3920 | } else if (op->IsShr()) { |
| 3921 | GenerateShrLong(first, second_reg); |
| 3922 | } else { |
| 3923 | GenerateUShrLong(first, second_reg); |
| 3924 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3925 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3926 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3927 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3928 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3929 | if (shift != 0) { |
| 3930 | if (op->IsShl()) { |
| 3931 | GenerateShlLong(first, shift); |
| 3932 | } else if (op->IsShr()) { |
| 3933 | GenerateShrLong(first, shift); |
| 3934 | } else { |
| 3935 | GenerateUShrLong(first, shift); |
| 3936 | } |
| 3937 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3938 | } |
| 3939 | break; |
| 3940 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3941 | default: |
| 3942 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3943 | } |
| 3944 | } |
| 3945 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3946 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3947 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3948 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3949 | if (shift == 1) { |
| 3950 | // This is just an addition. |
| 3951 | __ addl(low, low); |
| 3952 | __ adcl(high, high); |
| 3953 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3954 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3955 | codegen_->EmitParallelMoves( |
| 3956 | loc.ToLow(), |
| 3957 | loc.ToHigh(), |
| 3958 | Primitive::kPrimInt, |
| 3959 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3960 | loc.ToLow(), |
| 3961 | Primitive::kPrimInt); |
| 3962 | } else if (shift > 32) { |
| 3963 | // Low part becomes 0. High part is low part << (shift-32). |
| 3964 | __ movl(high, low); |
| 3965 | __ shll(high, Immediate(shift - 32)); |
| 3966 | __ xorl(low, low); |
| 3967 | } else { |
| 3968 | // Between 1 and 31. |
| 3969 | __ shld(high, low, Immediate(shift)); |
| 3970 | __ shll(low, Immediate(shift)); |
| 3971 | } |
| 3972 | } |
| 3973 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3974 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3975 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3976 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3977 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3978 | __ testl(shifter, Immediate(32)); |
| 3979 | __ j(kEqual, &done); |
| 3980 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3981 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3982 | __ Bind(&done); |
| 3983 | } |
| 3984 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3985 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3986 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3987 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3988 | if (shift == 32) { |
| 3989 | // Need to copy the sign. |
| 3990 | DCHECK_NE(low, high); |
| 3991 | __ movl(low, high); |
| 3992 | __ sarl(high, Immediate(31)); |
| 3993 | } else if (shift > 32) { |
| 3994 | DCHECK_NE(low, high); |
| 3995 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3996 | __ movl(low, high); |
| 3997 | __ sarl(high, Immediate(31)); |
| 3998 | __ sarl(low, Immediate(shift - 32)); |
| 3999 | } else { |
| 4000 | // Between 1 and 31. |
| 4001 | __ shrd(low, high, Immediate(shift)); |
| 4002 | __ sarl(high, Immediate(shift)); |
| 4003 | } |
| 4004 | } |
| 4005 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4006 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4007 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4008 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4009 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4010 | __ testl(shifter, Immediate(32)); |
| 4011 | __ j(kEqual, &done); |
| 4012 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4013 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4014 | __ Bind(&done); |
| 4015 | } |
| 4016 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4017 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4018 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4019 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4020 | if (shift == 32) { |
| 4021 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4022 | codegen_->EmitParallelMoves( |
| 4023 | loc.ToHigh(), |
| 4024 | loc.ToLow(), |
| 4025 | Primitive::kPrimInt, |
| 4026 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4027 | loc.ToHigh(), |
| 4028 | Primitive::kPrimInt); |
| 4029 | } else if (shift > 32) { |
| 4030 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4031 | __ movl(low, high); |
| 4032 | __ shrl(low, Immediate(shift - 32)); |
| 4033 | __ xorl(high, high); |
| 4034 | } else { |
| 4035 | // Between 1 and 31. |
| 4036 | __ shrd(low, high, Immediate(shift)); |
| 4037 | __ shrl(high, Immediate(shift)); |
| 4038 | } |
| 4039 | } |
| 4040 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4041 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4042 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4043 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4044 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4045 | __ testl(shifter, Immediate(32)); |
| 4046 | __ j(kEqual, &done); |
| 4047 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4048 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4049 | __ Bind(&done); |
| 4050 | } |
| 4051 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4052 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4053 | LocationSummary* locations = |
| 4054 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4055 | |
| 4056 | switch (ror->GetResultType()) { |
| 4057 | case Primitive::kPrimLong: |
| 4058 | // Add the temporary needed. |
| 4059 | locations->AddTemp(Location::RequiresRegister()); |
| 4060 | FALLTHROUGH_INTENDED; |
| 4061 | case Primitive::kPrimInt: |
| 4062 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4063 | // The shift count needs to be in CL (unless it is a constant). |
| 4064 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4065 | locations->SetOut(Location::SameAsFirstInput()); |
| 4066 | break; |
| 4067 | default: |
| 4068 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4069 | UNREACHABLE(); |
| 4070 | } |
| 4071 | } |
| 4072 | |
| 4073 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4074 | LocationSummary* locations = ror->GetLocations(); |
| 4075 | Location first = locations->InAt(0); |
| 4076 | Location second = locations->InAt(1); |
| 4077 | |
| 4078 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 4079 | Register first_reg = first.AsRegister<Register>(); |
| 4080 | if (second.IsRegister()) { |
| 4081 | Register second_reg = second.AsRegister<Register>(); |
| 4082 | __ rorl(first_reg, second_reg); |
| 4083 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4084 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4085 | __ rorl(first_reg, imm); |
| 4086 | } |
| 4087 | return; |
| 4088 | } |
| 4089 | |
| 4090 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 4091 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4092 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4093 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4094 | if (second.IsRegister()) { |
| 4095 | Register second_reg = second.AsRegister<Register>(); |
| 4096 | DCHECK_EQ(second_reg, ECX); |
| 4097 | __ movl(temp_reg, first_reg_hi); |
| 4098 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4099 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4100 | __ movl(temp_reg, first_reg_hi); |
| 4101 | __ testl(second_reg, Immediate(32)); |
| 4102 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4103 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4104 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4105 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4106 | if (shift_amt == 0) { |
| 4107 | // Already fine. |
| 4108 | return; |
| 4109 | } |
| 4110 | if (shift_amt == 32) { |
| 4111 | // Just swap. |
| 4112 | __ movl(temp_reg, first_reg_lo); |
| 4113 | __ movl(first_reg_lo, first_reg_hi); |
| 4114 | __ movl(first_reg_hi, temp_reg); |
| 4115 | return; |
| 4116 | } |
| 4117 | |
| 4118 | Immediate imm(shift_amt); |
| 4119 | // Save the constents of the low value. |
| 4120 | __ movl(temp_reg, first_reg_lo); |
| 4121 | |
| 4122 | // Shift right into low, feeding bits from high. |
| 4123 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4124 | |
| 4125 | // Shift right into high, feeding bits from the original low. |
| 4126 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4127 | |
| 4128 | // Swap if needed. |
| 4129 | if (shift_amt > 32) { |
| 4130 | __ movl(temp_reg, first_reg_lo); |
| 4131 | __ movl(first_reg_lo, first_reg_hi); |
| 4132 | __ movl(first_reg_hi, temp_reg); |
| 4133 | } |
| 4134 | } |
| 4135 | } |
| 4136 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4137 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4138 | HandleShift(shl); |
| 4139 | } |
| 4140 | |
| 4141 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4142 | HandleShift(shl); |
| 4143 | } |
| 4144 | |
| 4145 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4146 | HandleShift(shr); |
| 4147 | } |
| 4148 | |
| 4149 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4150 | HandleShift(shr); |
| 4151 | } |
| 4152 | |
| 4153 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4154 | HandleShift(ushr); |
| 4155 | } |
| 4156 | |
| 4157 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4158 | HandleShift(ushr); |
| 4159 | } |
| 4160 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4161 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4162 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4163 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4164 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4165 | if (instruction->IsStringAlloc()) { |
| 4166 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4167 | } else { |
| 4168 | InvokeRuntimeCallingConvention calling_convention; |
| 4169 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4170 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4174 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4175 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4176 | if (instruction->IsStringAlloc()) { |
| 4177 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4178 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4179 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4180 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4181 | __ call(Address(temp, code_offset.Int32Value())); |
| 4182 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4183 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4184 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4185 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4186 | DCHECK(!codegen_->IsLeafMethod()); |
| 4187 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4188 | } |
| 4189 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4190 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4191 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4192 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4193 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4194 | InvokeRuntimeCallingConvention calling_convention; |
| 4195 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4196 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4197 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4201 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4202 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex().index_)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4203 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4204 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4205 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4206 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4207 | DCHECK(!codegen_->IsLeafMethod()); |
| 4208 | } |
| 4209 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4210 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4211 | LocationSummary* locations = |
| 4212 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4213 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4214 | if (location.IsStackSlot()) { |
| 4215 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4216 | } else if (location.IsDoubleStackSlot()) { |
| 4217 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4218 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4219 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4220 | } |
| 4221 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4222 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4223 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4224 | } |
| 4225 | |
| 4226 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4227 | LocationSummary* locations = |
| 4228 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4229 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4230 | } |
| 4231 | |
| 4232 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4233 | } |
| 4234 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4235 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4236 | LocationSummary* locations = |
| 4237 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4238 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4239 | locations->SetOut(Location::RequiresRegister()); |
| 4240 | } |
| 4241 | |
| 4242 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4243 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4244 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4245 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4246 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4247 | __ movl(locations->Out().AsRegister<Register>(), |
| 4248 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4249 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4250 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4251 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4252 | __ movl(locations->Out().AsRegister<Register>(), |
| 4253 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4254 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4255 | // temp = temp->GetImtEntryAt(method_offset); |
| 4256 | __ movl(locations->Out().AsRegister<Register>(), |
| 4257 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4258 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4259 | } |
| 4260 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4261 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4262 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4263 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4264 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4265 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4266 | } |
| 4267 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4268 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4269 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4270 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4271 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4272 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4273 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4274 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4275 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4276 | break; |
| 4277 | |
| 4278 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4279 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4280 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4281 | break; |
| 4282 | |
| 4283 | default: |
| 4284 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4285 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4286 | } |
| 4287 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4288 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4289 | LocationSummary* locations = |
| 4290 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4291 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4292 | locations->SetOut(Location::SameAsFirstInput()); |
| 4293 | } |
| 4294 | |
| 4295 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4296 | LocationSummary* locations = bool_not->GetLocations(); |
| 4297 | Location in = locations->InAt(0); |
| 4298 | Location out = locations->Out(); |
| 4299 | DCHECK(in.Equals(out)); |
| 4300 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4301 | } |
| 4302 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4303 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4304 | LocationSummary* locations = |
| 4305 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4306 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4307 | case Primitive::kPrimBoolean: |
| 4308 | case Primitive::kPrimByte: |
| 4309 | case Primitive::kPrimShort: |
| 4310 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4311 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4312 | case Primitive::kPrimLong: { |
| 4313 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4314 | locations->SetInAt(1, Location::Any()); |
| 4315 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4316 | break; |
| 4317 | } |
| 4318 | case Primitive::kPrimFloat: |
| 4319 | case Primitive::kPrimDouble: { |
| 4320 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4321 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4322 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4323 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4324 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4325 | } else { |
| 4326 | locations->SetInAt(1, Location::Any()); |
| 4327 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4328 | locations->SetOut(Location::RequiresRegister()); |
| 4329 | break; |
| 4330 | } |
| 4331 | default: |
| 4332 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4333 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4334 | } |
| 4335 | |
| 4336 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4337 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4338 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4339 | Location left = locations->InAt(0); |
| 4340 | Location right = locations->InAt(1); |
| 4341 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4342 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4343 | Condition less_cond = kLess; |
| 4344 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4345 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4346 | case Primitive::kPrimBoolean: |
| 4347 | case Primitive::kPrimByte: |
| 4348 | case Primitive::kPrimShort: |
| 4349 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4350 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4351 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4352 | break; |
| 4353 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4354 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4355 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4356 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4357 | int32_t val_low = 0; |
| 4358 | int32_t val_high = 0; |
| 4359 | bool right_is_const = false; |
| 4360 | |
| 4361 | if (right.IsConstant()) { |
| 4362 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4363 | right_is_const = true; |
| 4364 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4365 | val_low = Low32Bits(val); |
| 4366 | val_high = High32Bits(val); |
| 4367 | } |
| 4368 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4369 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4370 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4371 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4372 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4373 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4374 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4375 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4376 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4377 | __ j(kLess, &less); // Signed compare. |
| 4378 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4379 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4380 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4381 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4382 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4383 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4384 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4385 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4386 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4387 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4388 | break; |
| 4389 | } |
| 4390 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4391 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4392 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4393 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4394 | break; |
| 4395 | } |
| 4396 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4397 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4398 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4399 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4400 | break; |
| 4401 | } |
| 4402 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4403 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4404 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4405 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4406 | __ movl(out, Immediate(0)); |
| 4407 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4408 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4409 | |
| 4410 | __ Bind(&greater); |
| 4411 | __ movl(out, Immediate(1)); |
| 4412 | __ jmp(&done); |
| 4413 | |
| 4414 | __ Bind(&less); |
| 4415 | __ movl(out, Immediate(-1)); |
| 4416 | |
| 4417 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4418 | } |
| 4419 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4420 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4421 | LocationSummary* locations = |
| 4422 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4423 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4424 | locations->SetInAt(i, Location::Any()); |
| 4425 | } |
| 4426 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4427 | } |
| 4428 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4429 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4430 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4431 | } |
| 4432 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4433 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4434 | /* |
| 4435 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4436 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4437 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4438 | */ |
| 4439 | switch (kind) { |
| 4440 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4441 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4442 | break; |
| 4443 | } |
| 4444 | case MemBarrierKind::kAnyStore: |
| 4445 | case MemBarrierKind::kLoadAny: |
| 4446 | case MemBarrierKind::kStoreStore: { |
| 4447 | // nop |
| 4448 | break; |
| 4449 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4450 | case MemBarrierKind::kNTStoreStore: |
| 4451 | // Non-Temporal Store/Store needs an explicit fence. |
| 4452 | MemoryFence(/* non-temporal */ true); |
| 4453 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4454 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4455 | } |
| 4456 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4457 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4458 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4459 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4460 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4461 | |
| 4462 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4463 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4464 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4465 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4466 | if (GetGraph()->HasIrreducibleLoops() && |
| 4467 | (dispatch_info.method_load_kind == |
| 4468 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4469 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4470 | } |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 4471 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4472 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4473 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4474 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4475 | Register temp) { |
| 4476 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4477 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4478 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4479 | return location.AsRegister<Register>(); |
| 4480 | } |
| 4481 | // For intrinsics we allow any location, so it may be on the stack. |
| 4482 | if (!location.IsRegister()) { |
| 4483 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4484 | return temp; |
| 4485 | } |
| 4486 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4487 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4488 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4489 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4490 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4491 | if (slow_path != nullptr) { |
| 4492 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4493 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4494 | __ movl(temp, Address(ESP, stack_offset)); |
| 4495 | return temp; |
| 4496 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4497 | } |
| 4498 | return location.AsRegister<Register>(); |
| 4499 | } |
| 4500 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4501 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4502 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4504 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4505 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4506 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4507 | uint32_t offset = |
| 4508 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4509 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4510 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4511 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4512 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4513 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4514 | break; |
| 4515 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4516 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4517 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4518 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4519 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4520 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4521 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4522 | // Bind a new fixup label at the end of the "movl" insn. |
| 4523 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4524 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4525 | break; |
| 4526 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4527 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4528 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4529 | Register method_reg; |
| 4530 | Register reg = temp.AsRegister<Register>(); |
| 4531 | if (current_method.IsRegister()) { |
| 4532 | method_reg = current_method.AsRegister<Register>(); |
| 4533 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4534 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4535 | DCHECK(!current_method.IsValid()); |
| 4536 | method_reg = reg; |
| 4537 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4538 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4539 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4540 | __ movl(reg, Address(method_reg, |
| 4541 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4542 | // temp = temp[index_in_cache]; |
| 4543 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4544 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4545 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4546 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4547 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4548 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4549 | return callee_method; |
| 4550 | } |
| 4551 | |
| 4552 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4553 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4554 | |
| 4555 | switch (invoke->GetCodePtrLocation()) { |
| 4556 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4557 | __ call(GetFrameEntryLabel()); |
| 4558 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4559 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4560 | // (callee_method + offset_of_quick_compiled_code)() |
| 4561 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4562 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4563 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4564 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4565 | } |
| 4566 | |
| 4567 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4568 | } |
| 4569 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4570 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4571 | Register temp = temp_in.AsRegister<Register>(); |
| 4572 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4573 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4574 | |
| 4575 | // Use the calling convention instead of the location of the receiver, as |
| 4576 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4577 | // slow path, the arguments have been moved to the right place, so here we are |
| 4578 | // guaranteed that the receiver is the first register of the calling convention. |
| 4579 | InvokeDexCallingConvention calling_convention; |
| 4580 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4581 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4582 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4583 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4584 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4585 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4586 | // emit a read barrier for the previous class reference load. |
| 4587 | // However this is not required in practice, as this is an |
| 4588 | // intermediate/temporary reference and because the current |
| 4589 | // concurrent copying collector keeps the from-space memory |
| 4590 | // intact/accessible until the end of the marking phase (the |
| 4591 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4592 | __ MaybeUnpoisonHeapReference(temp); |
| 4593 | // temp = temp->GetMethodAt(method_offset); |
| 4594 | __ movl(temp, Address(temp, method_offset)); |
| 4595 | // call temp->GetEntryPoint(); |
| 4596 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4597 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4598 | } |
| 4599 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4600 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4601 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4602 | simple_patches_.emplace_back(); |
| 4603 | __ Bind(&simple_patches_.back()); |
| 4604 | } |
| 4605 | } |
| 4606 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4607 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
| 4608 | DCHECK(GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4609 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4610 | __ Bind(&string_patches_.back().label); |
| 4611 | } |
| 4612 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4613 | void CodeGeneratorX86::RecordBootTypePatch(HLoadClass* load_class) { |
| 4614 | boot_image_type_patches_.emplace_back(load_class->GetDexFile(), |
| 4615 | load_class->GetTypeIndex().index_); |
| 4616 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4617 | } |
| 4618 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4619 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4620 | type_bss_entry_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| 4621 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4622 | } |
| 4623 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4624 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4625 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4626 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4627 | return &string_patches_.back().label; |
| 4628 | } |
| 4629 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4630 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4631 | uint32_t element_offset) { |
| 4632 | // Add the patch entry and bind its label at the end of the instruction. |
| 4633 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4634 | return &pc_relative_dex_cache_patches_.back().label; |
| 4635 | } |
| 4636 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4637 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4638 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4639 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4640 | |
| 4641 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4642 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| 4643 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 4644 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4645 | for (const PatchInfo<Label>& info : infos) { |
| 4646 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4647 | linker_patches->push_back( |
| 4648 | Factory(literal_offset, &info.dex_file, GetMethodAddressOffset(), info.index)); |
| 4649 | } |
| 4650 | } |
| 4651 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4652 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4653 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4654 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4655 | pc_relative_dex_cache_patches_.size() + |
| 4656 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4657 | string_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4658 | boot_image_type_patches_.size() + |
| 4659 | type_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4660 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4661 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 4662 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4663 | for (const Label& label : simple_patches_) { |
| 4664 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4665 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4666 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4667 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4668 | DCHECK(boot_image_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4669 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 4670 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4671 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(boot_image_type_patches_, |
| 4672 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4673 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4674 | } else { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4675 | for (const PatchInfo<Label>& info : boot_image_type_patches_) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4676 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4677 | 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] | 4678 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4679 | for (const PatchInfo<Label>& info : string_patches_) { |
| 4680 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4681 | linker_patches->push_back( |
| 4682 | LinkerPatch::StringPatch(literal_offset, &info.dex_file, info.index)); |
| 4683 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4684 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4685 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4686 | linker_patches); |
| 4687 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4688 | } |
| 4689 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4690 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4691 | Register card, |
| 4692 | Register object, |
| 4693 | Register value, |
| 4694 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4695 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4696 | if (value_can_be_null) { |
| 4697 | __ testl(value, value); |
| 4698 | __ j(kEqual, &is_null); |
| 4699 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4700 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4701 | __ movl(temp, object); |
| 4702 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4703 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4704 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4705 | if (value_can_be_null) { |
| 4706 | __ Bind(&is_null); |
| 4707 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4708 | } |
| 4709 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4710 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4711 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4712 | |
| 4713 | bool object_field_get_with_read_barrier = |
| 4714 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4715 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4716 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4717 | kEmitCompilerReadBarrier ? |
| 4718 | LocationSummary::kCallOnSlowPath : |
| 4719 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4720 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4721 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4722 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4723 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4724 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4725 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4726 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4727 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4728 | // The output overlaps in case of long: we don't want the low move |
| 4729 | // to overwrite the object's location. Likewise, in the case of |
| 4730 | // an object field get with read barriers enabled, we do not want |
| 4731 | // the move to overwrite the object's location, as we need it to emit |
| 4732 | // the read barrier. |
| 4733 | locations->SetOut( |
| 4734 | Location::RequiresRegister(), |
| 4735 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4736 | Location::kOutputOverlap : |
| 4737 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4738 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4739 | |
| 4740 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4741 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4742 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4743 | // load the temp into the XMM and then copy the XMM into the |
| 4744 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4745 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4746 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4747 | } |
| 4748 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4749 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4750 | const FieldInfo& field_info) { |
| 4751 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4752 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4753 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4754 | Location base_loc = locations->InAt(0); |
| 4755 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4756 | Location out = locations->Out(); |
| 4757 | bool is_volatile = field_info.IsVolatile(); |
| 4758 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4759 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4760 | |
| 4761 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4762 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4763 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4764 | break; |
| 4765 | } |
| 4766 | |
| 4767 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4768 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4769 | break; |
| 4770 | } |
| 4771 | |
| 4772 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4773 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4774 | break; |
| 4775 | } |
| 4776 | |
| 4777 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4778 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4779 | break; |
| 4780 | } |
| 4781 | |
| 4782 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4783 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4784 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4785 | |
| 4786 | case Primitive::kPrimNot: { |
| 4787 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4788 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4789 | // Note that a potential implicit null check is handled in this |
| 4790 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4791 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4792 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4793 | if (is_volatile) { |
| 4794 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4795 | } |
| 4796 | } else { |
| 4797 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4798 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4799 | if (is_volatile) { |
| 4800 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4801 | } |
| 4802 | // If read barriers are enabled, emit read barriers other than |
| 4803 | // Baker's using a slow path (and also unpoison the loaded |
| 4804 | // reference, if heap poisoning is enabled). |
| 4805 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4806 | } |
| 4807 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4811 | if (is_volatile) { |
| 4812 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4813 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4814 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4815 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4816 | __ psrlq(temp, Immediate(32)); |
| 4817 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4818 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4819 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4820 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4821 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4822 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4823 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4824 | break; |
| 4825 | } |
| 4826 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4827 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4828 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4829 | break; |
| 4830 | } |
| 4831 | |
| 4832 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4833 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4834 | break; |
| 4835 | } |
| 4836 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4837 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4838 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4839 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4840 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4841 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4842 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4843 | // Potential implicit null checks, in the case of reference or |
| 4844 | // long fields, are handled in the previous switch statement. |
| 4845 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4846 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4847 | } |
| 4848 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4849 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4850 | if (field_type == Primitive::kPrimNot) { |
| 4851 | // Memory barriers, in the case of references, are also handled |
| 4852 | // in the previous switch statement. |
| 4853 | } else { |
| 4854 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4855 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4856 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4857 | } |
| 4858 | |
| 4859 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4860 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4861 | |
| 4862 | LocationSummary* locations = |
| 4863 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4864 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4865 | bool is_volatile = field_info.IsVolatile(); |
| 4866 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4867 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4868 | || (field_type == Primitive::kPrimByte); |
| 4869 | |
| 4870 | // The register allocator does not support multiple |
| 4871 | // inputs that die at entry with one in a specific register. |
| 4872 | if (is_byte_type) { |
| 4873 | // Ensure the value is in a byte register. |
| 4874 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4875 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4876 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4877 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4878 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4879 | } else { |
| 4880 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4881 | } |
| 4882 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4883 | // 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] | 4884 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4885 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4886 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4887 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4888 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4889 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4890 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4891 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4892 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4893 | } else { |
| 4894 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4895 | |
| 4896 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4897 | // Temporary registers for the write barrier. |
| 4898 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4899 | // Ensure the card is in a byte register. |
| 4900 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4901 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4902 | } |
| 4903 | } |
| 4904 | |
| 4905 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4906 | const FieldInfo& field_info, |
| 4907 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4908 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4909 | |
| 4910 | LocationSummary* locations = instruction->GetLocations(); |
| 4911 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4912 | Location value = locations->InAt(1); |
| 4913 | bool is_volatile = field_info.IsVolatile(); |
| 4914 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4915 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4916 | bool needs_write_barrier = |
| 4917 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4918 | |
| 4919 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4920 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4921 | } |
| 4922 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4923 | bool maybe_record_implicit_null_check_done = false; |
| 4924 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4925 | switch (field_type) { |
| 4926 | case Primitive::kPrimBoolean: |
| 4927 | case Primitive::kPrimByte: { |
| 4928 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4929 | break; |
| 4930 | } |
| 4931 | |
| 4932 | case Primitive::kPrimShort: |
| 4933 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4934 | if (value.IsConstant()) { |
| 4935 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4936 | __ movw(Address(base, offset), Immediate(v)); |
| 4937 | } else { |
| 4938 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4939 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4940 | break; |
| 4941 | } |
| 4942 | |
| 4943 | case Primitive::kPrimInt: |
| 4944 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4945 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4946 | // Note that in the case where `value` is a null reference, |
| 4947 | // we do not enter this block, as the reference does not |
| 4948 | // need poisoning. |
| 4949 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4950 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4951 | __ movl(temp, value.AsRegister<Register>()); |
| 4952 | __ PoisonHeapReference(temp); |
| 4953 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4954 | } else if (value.IsConstant()) { |
| 4955 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4956 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4957 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4958 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4959 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4960 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4961 | break; |
| 4962 | } |
| 4963 | |
| 4964 | case Primitive::kPrimLong: { |
| 4965 | if (is_volatile) { |
| 4966 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4967 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4968 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4969 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4970 | __ punpckldq(temp1, temp2); |
| 4971 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4972 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4973 | } else if (value.IsConstant()) { |
| 4974 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4975 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4976 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4977 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4978 | } else { |
| 4979 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4980 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4981 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4982 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4983 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4984 | break; |
| 4985 | } |
| 4986 | |
| 4987 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4988 | if (value.IsConstant()) { |
| 4989 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4990 | __ movl(Address(base, offset), Immediate(v)); |
| 4991 | } else { |
| 4992 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4993 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4994 | break; |
| 4995 | } |
| 4996 | |
| 4997 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4998 | if (value.IsConstant()) { |
| 4999 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5000 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5001 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5002 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5003 | maybe_record_implicit_null_check_done = true; |
| 5004 | } else { |
| 5005 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5006 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5007 | break; |
| 5008 | } |
| 5009 | |
| 5010 | case Primitive::kPrimVoid: |
| 5011 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5012 | UNREACHABLE(); |
| 5013 | } |
| 5014 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5015 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5016 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5017 | } |
| 5018 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5019 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5020 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5021 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5022 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5023 | } |
| 5024 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5025 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5026 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5027 | } |
| 5028 | } |
| 5029 | |
| 5030 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5031 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5032 | } |
| 5033 | |
| 5034 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5035 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5036 | } |
| 5037 | |
| 5038 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5039 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5040 | } |
| 5041 | |
| 5042 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5043 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5047 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5048 | } |
| 5049 | |
| 5050 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5051 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5052 | } |
| 5053 | |
| 5054 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5055 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5056 | } |
| 5057 | |
| 5058 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5059 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5060 | } |
| 5061 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5062 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5063 | HUnresolvedInstanceFieldGet* instruction) { |
| 5064 | FieldAccessCallingConventionX86 calling_convention; |
| 5065 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5066 | instruction, instruction->GetFieldType(), calling_convention); |
| 5067 | } |
| 5068 | |
| 5069 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5070 | HUnresolvedInstanceFieldGet* instruction) { |
| 5071 | FieldAccessCallingConventionX86 calling_convention; |
| 5072 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5073 | instruction->GetFieldType(), |
| 5074 | instruction->GetFieldIndex(), |
| 5075 | instruction->GetDexPc(), |
| 5076 | calling_convention); |
| 5077 | } |
| 5078 | |
| 5079 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5080 | HUnresolvedInstanceFieldSet* instruction) { |
| 5081 | FieldAccessCallingConventionX86 calling_convention; |
| 5082 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5083 | instruction, instruction->GetFieldType(), calling_convention); |
| 5084 | } |
| 5085 | |
| 5086 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5087 | HUnresolvedInstanceFieldSet* instruction) { |
| 5088 | FieldAccessCallingConventionX86 calling_convention; |
| 5089 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5090 | instruction->GetFieldType(), |
| 5091 | instruction->GetFieldIndex(), |
| 5092 | instruction->GetDexPc(), |
| 5093 | calling_convention); |
| 5094 | } |
| 5095 | |
| 5096 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5097 | HUnresolvedStaticFieldGet* instruction) { |
| 5098 | FieldAccessCallingConventionX86 calling_convention; |
| 5099 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5100 | instruction, instruction->GetFieldType(), calling_convention); |
| 5101 | } |
| 5102 | |
| 5103 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5104 | HUnresolvedStaticFieldGet* instruction) { |
| 5105 | FieldAccessCallingConventionX86 calling_convention; |
| 5106 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5107 | instruction->GetFieldType(), |
| 5108 | instruction->GetFieldIndex(), |
| 5109 | instruction->GetDexPc(), |
| 5110 | calling_convention); |
| 5111 | } |
| 5112 | |
| 5113 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5114 | HUnresolvedStaticFieldSet* instruction) { |
| 5115 | FieldAccessCallingConventionX86 calling_convention; |
| 5116 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5117 | instruction, instruction->GetFieldType(), calling_convention); |
| 5118 | } |
| 5119 | |
| 5120 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5121 | HUnresolvedStaticFieldSet* instruction) { |
| 5122 | FieldAccessCallingConventionX86 calling_convention; |
| 5123 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5124 | instruction->GetFieldType(), |
| 5125 | instruction->GetFieldIndex(), |
| 5126 | instruction->GetDexPc(), |
| 5127 | calling_convention); |
| 5128 | } |
| 5129 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5130 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5131 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5132 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5133 | ? Location::RequiresRegister() |
| 5134 | : Location::Any(); |
| 5135 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5136 | } |
| 5137 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5138 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5139 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5140 | return; |
| 5141 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5142 | LocationSummary* locations = instruction->GetLocations(); |
| 5143 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5144 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5145 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5146 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5147 | } |
| 5148 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5149 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5150 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5151 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5152 | |
| 5153 | LocationSummary* locations = instruction->GetLocations(); |
| 5154 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5155 | |
| 5156 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5157 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5158 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5159 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5160 | } else { |
| 5161 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5162 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5163 | __ jmp(slow_path->GetEntryLabel()); |
| 5164 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5165 | } |
| 5166 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5167 | } |
| 5168 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5169 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5170 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5171 | } |
| 5172 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5173 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5174 | bool object_array_get_with_read_barrier = |
| 5175 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5176 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5177 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5178 | object_array_get_with_read_barrier ? |
| 5179 | LocationSummary::kCallOnSlowPath : |
| 5180 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5181 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5182 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5183 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5184 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5185 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5186 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5187 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5188 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5189 | // The output overlaps in case of long: we don't want the low move |
| 5190 | // to overwrite the array's location. Likewise, in the case of an |
| 5191 | // object array get with read barriers enabled, we do not want the |
| 5192 | // move to overwrite the array's location, as we need it to emit |
| 5193 | // the read barrier. |
| 5194 | locations->SetOut( |
| 5195 | Location::RequiresRegister(), |
| 5196 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5197 | Location::kOutputOverlap : |
| 5198 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5199 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5203 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5204 | Location obj_loc = locations->InAt(0); |
| 5205 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5206 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5207 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5208 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5209 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5210 | Primitive::Type type = instruction->GetType(); |
| 5211 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5212 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5213 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5214 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5215 | break; |
| 5216 | } |
| 5217 | |
| 5218 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5219 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5220 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5221 | break; |
| 5222 | } |
| 5223 | |
| 5224 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5225 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5226 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5227 | break; |
| 5228 | } |
| 5229 | |
| 5230 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5231 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5232 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5233 | // Branch cases into compressed and uncompressed for each index's type. |
| 5234 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5235 | NearLabel done, not_compressed; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5236 | __ testl(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5237 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5238 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5239 | "Expecting 0=compressed, 1=uncompressed"); |
| 5240 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5241 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5242 | __ jmp(&done); |
| 5243 | __ Bind(¬_compressed); |
| 5244 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5245 | __ Bind(&done); |
| 5246 | } else { |
| 5247 | // Common case for charAt of array of char or when string compression's |
| 5248 | // feature is turned off. |
| 5249 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5250 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5251 | break; |
| 5252 | } |
| 5253 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5254 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5255 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5256 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5257 | break; |
| 5258 | } |
| 5259 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5260 | case Primitive::kPrimNot: { |
| 5261 | static_assert( |
| 5262 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5263 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5264 | // /* HeapReference<Object> */ out = |
| 5265 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5266 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5267 | // Note that a potential implicit null check is handled in this |
| 5268 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5269 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5270 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5271 | } else { |
| 5272 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5273 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5274 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5275 | // If read barriers are enabled, emit read barriers other than |
| 5276 | // Baker's using a slow path (and also unpoison the loaded |
| 5277 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5278 | if (index.IsConstant()) { |
| 5279 | uint32_t offset = |
| 5280 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5281 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5282 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5283 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5284 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5285 | } |
| 5286 | } |
| 5287 | break; |
| 5288 | } |
| 5289 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5290 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5291 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5292 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5293 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5294 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5295 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5296 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5297 | break; |
| 5298 | } |
| 5299 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5300 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5301 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5302 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5303 | break; |
| 5304 | } |
| 5305 | |
| 5306 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5307 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5308 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5309 | break; |
| 5310 | } |
| 5311 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5312 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5313 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5314 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5315 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5316 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5317 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5318 | // Potential implicit null checks, in the case of reference or |
| 5319 | // long arrays, are handled in the previous switch statement. |
| 5320 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5321 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5322 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5326 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5327 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5328 | bool needs_write_barrier = |
| 5329 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5330 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5331 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5332 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5333 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5334 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5335 | LocationSummary::kCallOnSlowPath : |
| 5336 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5337 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5338 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5339 | || (value_type == Primitive::kPrimByte); |
| 5340 | // We need the inputs to be different than the output in case of long operation. |
| 5341 | // In case of a byte operation, the register allocator does not support multiple |
| 5342 | // inputs that die at entry with one in a specific register. |
| 5343 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5344 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5345 | if (is_byte_type) { |
| 5346 | // Ensure the value is in a byte register. |
| 5347 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5348 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5349 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5350 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5351 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5352 | } |
| 5353 | if (needs_write_barrier) { |
| 5354 | // Temporary registers for the write barrier. |
| 5355 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5356 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5357 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5358 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5362 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5363 | Location array_loc = locations->InAt(0); |
| 5364 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5365 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5366 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5367 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5368 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5369 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5370 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5371 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5372 | bool needs_write_barrier = |
| 5373 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5374 | |
| 5375 | switch (value_type) { |
| 5376 | case Primitive::kPrimBoolean: |
| 5377 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5378 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5379 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5380 | if (value.IsRegister()) { |
| 5381 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5382 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5383 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5384 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5385 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5386 | break; |
| 5387 | } |
| 5388 | |
| 5389 | case Primitive::kPrimShort: |
| 5390 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5391 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5392 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5393 | if (value.IsRegister()) { |
| 5394 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5395 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5396 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5397 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5398 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5399 | break; |
| 5400 | } |
| 5401 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5402 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5403 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5404 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5405 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5406 | if (!value.IsRegister()) { |
| 5407 | // Just setting null. |
| 5408 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5409 | DCHECK(value.IsConstant()) << value; |
| 5410 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5411 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5412 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5413 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5414 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5415 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5416 | |
| 5417 | DCHECK(needs_write_barrier); |
| 5418 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5419 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5420 | // short when Baker read barriers are enabled. |
| 5421 | Label done; |
| 5422 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5423 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5424 | Location temp_loc = locations->GetTemp(0); |
| 5425 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5426 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5427 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5428 | codegen_->AddSlowPath(slow_path); |
| 5429 | if (instruction->GetValueCanBeNull()) { |
| 5430 | __ testl(register_value, register_value); |
| 5431 | __ j(kNotEqual, ¬_null); |
| 5432 | __ movl(address, Immediate(0)); |
| 5433 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5434 | __ jmp(&done); |
| 5435 | __ Bind(¬_null); |
| 5436 | } |
| 5437 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5438 | // Note that when Baker read barriers are enabled, the type |
| 5439 | // checks are performed without read barriers. This is fine, |
| 5440 | // even in the case where a class object is in the from-space |
| 5441 | // after the flip, as a comparison involving such a type would |
| 5442 | // not produce a false positive; it may of course produce a |
| 5443 | // false negative, in which case we would take the ArraySet |
| 5444 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5445 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5446 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5447 | __ movl(temp, Address(array, class_offset)); |
| 5448 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5449 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5450 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5451 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5452 | __ movl(temp, Address(temp, component_offset)); |
| 5453 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5454 | // nor the object reference in `register_value->klass`, as |
| 5455 | // we are comparing two poisoned references. |
| 5456 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5457 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5458 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5459 | __ j(kEqual, &do_put); |
| 5460 | // If heap poisoning is enabled, the `temp` reference has |
| 5461 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5462 | __ MaybeUnpoisonHeapReference(temp); |
| 5463 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5464 | // If heap poisoning is enabled, no need to unpoison the |
| 5465 | // heap reference loaded below, as it is only used for a |
| 5466 | // comparison with null. |
| 5467 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5468 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5469 | __ Bind(&do_put); |
| 5470 | } else { |
| 5471 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5472 | } |
| 5473 | } |
| 5474 | |
| 5475 | if (kPoisonHeapReferences) { |
| 5476 | __ movl(temp, register_value); |
| 5477 | __ PoisonHeapReference(temp); |
| 5478 | __ movl(address, temp); |
| 5479 | } else { |
| 5480 | __ movl(address, register_value); |
| 5481 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5482 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5483 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5484 | } |
| 5485 | |
| 5486 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5487 | codegen_->MarkGCCard( |
| 5488 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5489 | __ Bind(&done); |
| 5490 | |
| 5491 | if (slow_path != nullptr) { |
| 5492 | __ Bind(slow_path->GetExitLabel()); |
| 5493 | } |
| 5494 | |
| 5495 | break; |
| 5496 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5497 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5498 | case Primitive::kPrimInt: { |
| 5499 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5500 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5501 | if (value.IsRegister()) { |
| 5502 | __ movl(address, value.AsRegister<Register>()); |
| 5503 | } else { |
| 5504 | DCHECK(value.IsConstant()) << value; |
| 5505 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5506 | __ movl(address, Immediate(v)); |
| 5507 | } |
| 5508 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5509 | break; |
| 5510 | } |
| 5511 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5512 | case Primitive::kPrimLong: { |
| 5513 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5514 | if (value.IsRegisterPair()) { |
| 5515 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5516 | value.AsRegisterPairLow<Register>()); |
| 5517 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5518 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5519 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5520 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5521 | DCHECK(value.IsConstant()); |
| 5522 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5523 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5524 | Immediate(Low32Bits(val))); |
| 5525 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5526 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5527 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5528 | } |
| 5529 | break; |
| 5530 | } |
| 5531 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5532 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5533 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5534 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5535 | if (value.IsFpuRegister()) { |
| 5536 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5537 | } else { |
| 5538 | DCHECK(value.IsConstant()); |
| 5539 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5540 | __ movl(address, Immediate(v)); |
| 5541 | } |
| 5542 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5543 | break; |
| 5544 | } |
| 5545 | |
| 5546 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5547 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5548 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5549 | if (value.IsFpuRegister()) { |
| 5550 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5551 | } else { |
| 5552 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5553 | Address address_hi = |
| 5554 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5555 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5556 | __ movl(address, Immediate(Low32Bits(v))); |
| 5557 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5558 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5559 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5560 | break; |
| 5561 | } |
| 5562 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5563 | case Primitive::kPrimVoid: |
| 5564 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5565 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5566 | } |
| 5567 | } |
| 5568 | |
| 5569 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5570 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5571 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5572 | if (!instruction->IsEmittedAtUseSite()) { |
| 5573 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5574 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5575 | } |
| 5576 | |
| 5577 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5578 | if (instruction->IsEmittedAtUseSite()) { |
| 5579 | return; |
| 5580 | } |
| 5581 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5582 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5583 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5584 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5585 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5586 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5587 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5588 | // Mask out most significant bit in case the array is String's array of char. |
| 5589 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5590 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5591 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5595 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5596 | InvokeRuntimeCallingConvention calling_convention; |
| 5597 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5598 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5599 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5600 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5601 | HInstruction* length = instruction->InputAt(1); |
| 5602 | if (!length->IsEmittedAtUseSite()) { |
| 5603 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5604 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5605 | // Need register to see array's length. |
| 5606 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5607 | locations->AddTemp(Location::RequiresRegister()); |
| 5608 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5612 | const bool is_string_compressed_char_at = |
| 5613 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5614 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5615 | Location index_loc = locations->InAt(0); |
| 5616 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5617 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5618 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5619 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5620 | if (length_loc.IsConstant()) { |
| 5621 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5622 | if (index_loc.IsConstant()) { |
| 5623 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5624 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5625 | if (index < 0 || index >= length) { |
| 5626 | codegen_->AddSlowPath(slow_path); |
| 5627 | __ jmp(slow_path->GetEntryLabel()); |
| 5628 | } else { |
| 5629 | // Some optimization after BCE may have generated this, and we should not |
| 5630 | // generate a bounds check if it is a valid range. |
| 5631 | } |
| 5632 | return; |
| 5633 | } |
| 5634 | |
| 5635 | // We have to reverse the jump condition because the length is the constant. |
| 5636 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5637 | __ cmpl(index_reg, Immediate(length)); |
| 5638 | codegen_->AddSlowPath(slow_path); |
| 5639 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5640 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5641 | HInstruction* array_length = instruction->InputAt(1); |
| 5642 | if (array_length->IsEmittedAtUseSite()) { |
| 5643 | // Address the length field in the array. |
| 5644 | DCHECK(array_length->IsArrayLength()); |
| 5645 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5646 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5647 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5648 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5649 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5650 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5651 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5652 | __ movl(length_reg, array_len); |
| 5653 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5654 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5655 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5656 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5657 | // Checking bounds for general case: |
| 5658 | // Array of char or string's array with feature compression off. |
| 5659 | if (index_loc.IsConstant()) { |
| 5660 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5661 | __ cmpl(array_len, Immediate(value)); |
| 5662 | } else { |
| 5663 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5664 | } |
| 5665 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5666 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5667 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5668 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5669 | } |
| 5670 | codegen_->AddSlowPath(slow_path); |
| 5671 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5672 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5673 | } |
| 5674 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5675 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5676 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5677 | } |
| 5678 | |
| 5679 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5680 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5681 | } |
| 5682 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5683 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5684 | LocationSummary* locations = |
| 5685 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5686 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5687 | } |
| 5688 | |
| 5689 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5690 | HBasicBlock* block = instruction->GetBlock(); |
| 5691 | if (block->GetLoopInformation() != nullptr) { |
| 5692 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5693 | // The back edge will generate the suspend check. |
| 5694 | return; |
| 5695 | } |
| 5696 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5697 | // The goto will generate the suspend check. |
| 5698 | return; |
| 5699 | } |
| 5700 | GenerateSuspendCheck(instruction, nullptr); |
| 5701 | } |
| 5702 | |
| 5703 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5704 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5705 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5706 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5707 | if (slow_path == nullptr) { |
| 5708 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5709 | instruction->SetSlowPath(slow_path); |
| 5710 | codegen_->AddSlowPath(slow_path); |
| 5711 | if (successor != nullptr) { |
| 5712 | DCHECK(successor->IsLoopHeader()); |
| 5713 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5714 | } |
| 5715 | } else { |
| 5716 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5717 | } |
| 5718 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5719 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5720 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5721 | if (successor == nullptr) { |
| 5722 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5723 | __ Bind(slow_path->GetReturnLabel()); |
| 5724 | } else { |
| 5725 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5726 | __ jmp(slow_path->GetEntryLabel()); |
| 5727 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5730 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5731 | return codegen_->GetAssembler(); |
| 5732 | } |
| 5733 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5734 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5735 | ScratchRegisterScope ensure_scratch( |
| 5736 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5737 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5738 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5739 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5740 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5744 | ScratchRegisterScope ensure_scratch( |
| 5745 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5746 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5747 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5748 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5749 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5750 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5751 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5752 | } |
| 5753 | |
| 5754 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5755 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5756 | Location source = move->GetSource(); |
| 5757 | Location destination = move->GetDestination(); |
| 5758 | |
| 5759 | if (source.IsRegister()) { |
| 5760 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5761 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5762 | } else if (destination.IsFpuRegister()) { |
| 5763 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5764 | } else { |
| 5765 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5766 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5767 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5768 | } else if (source.IsRegisterPair()) { |
| 5769 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5770 | // Create stack space for 2 elements. |
| 5771 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5772 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5773 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5774 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5775 | // And remove the temporary stack space we allocated. |
| 5776 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5777 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5778 | if (destination.IsRegister()) { |
| 5779 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5780 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5781 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5782 | } else if (destination.IsRegisterPair()) { |
| 5783 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5784 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5785 | __ psrlq(src_reg, Immediate(32)); |
| 5786 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5787 | } else if (destination.IsStackSlot()) { |
| 5788 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5789 | } else { |
| 5790 | DCHECK(destination.IsDoubleStackSlot()); |
| 5791 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5792 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5793 | } else if (source.IsStackSlot()) { |
| 5794 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5795 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5796 | } else if (destination.IsFpuRegister()) { |
| 5797 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5798 | } else { |
| 5799 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5800 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5801 | } |
| 5802 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5803 | if (destination.IsRegisterPair()) { |
| 5804 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5805 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5806 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5807 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5808 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5809 | } else { |
| 5810 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5811 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5812 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5813 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5814 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5815 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5816 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5817 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5818 | if (value == 0) { |
| 5819 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5820 | } else { |
| 5821 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5822 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5823 | } else { |
| 5824 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5825 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5826 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5827 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5828 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5829 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5830 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5831 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5832 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5833 | if (value == 0) { |
| 5834 | // Easy handling of 0.0. |
| 5835 | __ xorps(dest, dest); |
| 5836 | } else { |
| 5837 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5838 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5839 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5840 | __ movl(temp, Immediate(value)); |
| 5841 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5842 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5843 | } else { |
| 5844 | DCHECK(destination.IsStackSlot()) << destination; |
| 5845 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5846 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5847 | } else if (constant->IsLongConstant()) { |
| 5848 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5849 | int32_t low_value = Low32Bits(value); |
| 5850 | int32_t high_value = High32Bits(value); |
| 5851 | Immediate low(low_value); |
| 5852 | Immediate high(high_value); |
| 5853 | if (destination.IsDoubleStackSlot()) { |
| 5854 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5855 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5856 | } else { |
| 5857 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5858 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5859 | } |
| 5860 | } else { |
| 5861 | DCHECK(constant->IsDoubleConstant()); |
| 5862 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5863 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5864 | int32_t low_value = Low32Bits(value); |
| 5865 | int32_t high_value = High32Bits(value); |
| 5866 | Immediate low(low_value); |
| 5867 | Immediate high(high_value); |
| 5868 | if (destination.IsFpuRegister()) { |
| 5869 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5870 | if (value == 0) { |
| 5871 | // Easy handling of 0.0. |
| 5872 | __ xorpd(dest, dest); |
| 5873 | } else { |
| 5874 | __ pushl(high); |
| 5875 | __ pushl(low); |
| 5876 | __ movsd(dest, Address(ESP, 0)); |
| 5877 | __ addl(ESP, Immediate(8)); |
| 5878 | } |
| 5879 | } else { |
| 5880 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5881 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5882 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5883 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5884 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5885 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5886 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5887 | } |
| 5888 | } |
| 5889 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5890 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5891 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5892 | ScratchRegisterScope ensure_scratch( |
| 5893 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5894 | |
| 5895 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5896 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5897 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5898 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5899 | } |
| 5900 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5901 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5902 | ScratchRegisterScope ensure_scratch( |
| 5903 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5904 | |
| 5905 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5906 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5907 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5908 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5909 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5910 | } |
| 5911 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5912 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5913 | ScratchRegisterScope ensure_scratch1( |
| 5914 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5915 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5916 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5917 | ScratchRegisterScope ensure_scratch2( |
| 5918 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5919 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5920 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5921 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5922 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5923 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5924 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5925 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5926 | } |
| 5927 | |
| 5928 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5929 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5930 | Location source = move->GetSource(); |
| 5931 | Location destination = move->GetDestination(); |
| 5932 | |
| 5933 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5934 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5935 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5936 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5937 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5938 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5939 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5940 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5941 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5942 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5943 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5944 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5945 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5946 | // Use XOR Swap algorithm to avoid a temporary. |
| 5947 | DCHECK_NE(source.reg(), destination.reg()); |
| 5948 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5949 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5950 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5951 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5952 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5953 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5954 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5955 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5956 | // Take advantage of the 16 bytes in the XMM register. |
| 5957 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5958 | Address stack(ESP, destination.GetStackIndex()); |
| 5959 | // Load the double into the high doubleword. |
| 5960 | __ movhpd(reg, stack); |
| 5961 | |
| 5962 | // Store the low double into the destination. |
| 5963 | __ movsd(stack, reg); |
| 5964 | |
| 5965 | // Move the high double to the low double. |
| 5966 | __ psrldq(reg, Immediate(8)); |
| 5967 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5968 | // Take advantage of the 16 bytes in the XMM register. |
| 5969 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5970 | Address stack(ESP, source.GetStackIndex()); |
| 5971 | // Load the double into the high doubleword. |
| 5972 | __ movhpd(reg, stack); |
| 5973 | |
| 5974 | // Store the low double into the destination. |
| 5975 | __ movsd(stack, reg); |
| 5976 | |
| 5977 | // Move the high double to the low double. |
| 5978 | __ psrldq(reg, Immediate(8)); |
| 5979 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5980 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5981 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5982 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5983 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5984 | } |
| 5985 | } |
| 5986 | |
| 5987 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5988 | __ pushl(static_cast<Register>(reg)); |
| 5989 | } |
| 5990 | |
| 5991 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5992 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5993 | } |
| 5994 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5995 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 5996 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5997 | switch (desired_class_load_kind) { |
| 5998 | case HLoadClass::LoadKind::kReferrersClass: |
| 5999 | break; |
| 6000 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6001 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6002 | break; |
| 6003 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6004 | DCHECK(GetCompilerOptions().GetCompilePic()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6005 | FALLTHROUGH_INTENDED; |
| 6006 | case HLoadClass::LoadKind::kBssEntry: |
| 6007 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6008 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6009 | // is incompatible with it. |
| 6010 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6011 | // with irreducible loops. |
| 6012 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6013 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 6014 | } |
| 6015 | break; |
| 6016 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6017 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6018 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6019 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6020 | break; |
| 6021 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6022 | break; |
| 6023 | } |
| 6024 | return desired_class_load_kind; |
| 6025 | } |
| 6026 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6027 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6028 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6029 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6030 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6031 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6032 | cls, |
| 6033 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6034 | Location::RegisterLocation(EAX)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6035 | return; |
| 6036 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6037 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6038 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6039 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6040 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6041 | ? LocationSummary::kCallOnSlowPath |
| 6042 | : LocationSummary::kNoCall; |
| 6043 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6044 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6045 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6046 | } |
| 6047 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6048 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6049 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 6050 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6051 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6052 | } |
| 6053 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6054 | } |
| 6055 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6056 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| 6057 | dex::TypeIndex dex_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame^] | 6058 | Handle<mirror::Class> handle) { |
| 6059 | jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index), |
| 6060 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6061 | // Add a patch entry and return the label. |
| 6062 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 6063 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6064 | return &info->label; |
| 6065 | } |
| 6066 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame^] | 6067 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6068 | // move. |
| 6069 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6070 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6071 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6072 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6073 | return; |
| 6074 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6075 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6076 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6077 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6078 | Location out_loc = locations->Out(); |
| 6079 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6080 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6081 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6082 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6083 | ? kWithoutReadBarrier |
| 6084 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6085 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6086 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6087 | DCHECK(!cls->CanCallRuntime()); |
| 6088 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6089 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6090 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6091 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6092 | cls, |
| 6093 | out_loc, |
| 6094 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6095 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6096 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6097 | break; |
| 6098 | } |
| 6099 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6100 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6101 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6102 | __ movl(out, Immediate(/* placeholder */ 0)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6103 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6104 | break; |
| 6105 | } |
| 6106 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6107 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6108 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6109 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6110 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6111 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6112 | break; |
| 6113 | } |
| 6114 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6115 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame^] | 6116 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6117 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6118 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6119 | __ movl(out, Immediate(address)); |
| 6120 | codegen_->RecordSimplePatch(); |
| 6121 | break; |
| 6122 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6123 | case HLoadClass::LoadKind::kBssEntry: { |
| 6124 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6125 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6126 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6127 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6128 | generate_null_check = true; |
| 6129 | break; |
| 6130 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6131 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6132 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6133 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame^] | 6134 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6135 | // /* GcRoot<mirror::Class> */ out = *address |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6136 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6137 | break; |
| 6138 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6139 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6140 | LOG(FATAL) << "UNREACHABLE"; |
| 6141 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6142 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6143 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6144 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6145 | DCHECK(cls->CanCallRuntime()); |
| 6146 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6147 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6148 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6149 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6150 | if (generate_null_check) { |
| 6151 | __ testl(out, out); |
| 6152 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6153 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6154 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6155 | if (cls->MustGenerateClinitCheck()) { |
| 6156 | GenerateClassInitializationCheck(slow_path, out); |
| 6157 | } else { |
| 6158 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6159 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6160 | } |
| 6161 | } |
| 6162 | |
| 6163 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6164 | LocationSummary* locations = |
| 6165 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6166 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6167 | if (check->HasUses()) { |
| 6168 | locations->SetOut(Location::SameAsFirstInput()); |
| 6169 | } |
| 6170 | } |
| 6171 | |
| 6172 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6173 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6174 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6175 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6176 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6177 | GenerateClassInitializationCheck(slow_path, |
| 6178 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6179 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6180 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6181 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6182 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6183 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6184 | Immediate(mirror::Class::kStatusInitialized)); |
| 6185 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6186 | __ Bind(slow_path->GetExitLabel()); |
| 6187 | // No need for memory fence, thanks to the X86 memory model. |
| 6188 | } |
| 6189 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6190 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6191 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6192 | switch (desired_string_load_kind) { |
| 6193 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6194 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6195 | break; |
| 6196 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6197 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6198 | FALLTHROUGH_INTENDED; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6199 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6200 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6201 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6202 | // is incompatible with it. |
| 6203 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6204 | // with irreducible loops. |
| 6205 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6206 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6207 | } |
| 6208 | break; |
| 6209 | case HLoadString::LoadKind::kBootImageAddress: |
| 6210 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6211 | case HLoadString::LoadKind::kJitTableAddress: |
| 6212 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6213 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6214 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6215 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6216 | } |
| 6217 | return desired_string_load_kind; |
| 6218 | } |
| 6219 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6220 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6221 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6222 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6223 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6224 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6225 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6226 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6227 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6228 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 6229 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6230 | } else { |
| 6231 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6232 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6233 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6234 | // Rely on the pResolveString and/or marking to save everything. |
| 6235 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6236 | InvokeRuntimeCallingConvention calling_convention; |
| 6237 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6238 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6239 | } else { |
| 6240 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6241 | } |
| 6242 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6243 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6244 | } |
| 6245 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6246 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6247 | dex::StringIndex dex_index, |
| 6248 | Handle<mirror::String> handle) { |
| 6249 | jit_string_roots_.Overwrite( |
| 6250 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6251 | // Add a patch entry and return the label. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6252 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6253 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6254 | return &info->label; |
| 6255 | } |
| 6256 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6257 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6258 | // move. |
| 6259 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6260 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6261 | Location out_loc = locations->Out(); |
| 6262 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6263 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6264 | switch (load->GetLoadKind()) { |
| 6265 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6266 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6267 | __ movl(out, Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6268 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6269 | return; // No dex cache slow path. |
| 6270 | } |
| 6271 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6272 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6273 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6274 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6275 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6276 | return; // No dex cache slow path. |
| 6277 | } |
| 6278 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6279 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6280 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6281 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6282 | __ movl(out, Immediate(address)); |
| 6283 | codegen_->RecordSimplePatch(); |
| 6284 | return; // No dex cache slow path. |
| 6285 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6286 | case HLoadString::LoadKind::kBssEntry: { |
| 6287 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6288 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6289 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6290 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6291 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6292 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6293 | codegen_->AddSlowPath(slow_path); |
| 6294 | __ testl(out, out); |
| 6295 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6296 | __ Bind(slow_path->GetExitLabel()); |
| 6297 | return; |
| 6298 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6299 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6300 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6301 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6302 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6303 | // /* GcRoot<mirror::String> */ out = *address |
| 6304 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6305 | return; |
| 6306 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6307 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6308 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6309 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6310 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6311 | // 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] | 6312 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6313 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6314 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6315 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6316 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6317 | } |
| 6318 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6319 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6320 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6321 | } |
| 6322 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6323 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6324 | LocationSummary* locations = |
| 6325 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6326 | locations->SetOut(Location::RequiresRegister()); |
| 6327 | } |
| 6328 | |
| 6329 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6330 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6331 | } |
| 6332 | |
| 6333 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6334 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6335 | } |
| 6336 | |
| 6337 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6338 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6339 | } |
| 6340 | |
| 6341 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6342 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6343 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6344 | InvokeRuntimeCallingConvention calling_convention; |
| 6345 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6346 | } |
| 6347 | |
| 6348 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6349 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6350 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6351 | } |
| 6352 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6353 | // Temp is used for read barrier. |
| 6354 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6355 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6356 | !kUseBakerReadBarrier && |
| 6357 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6358 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6359 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6360 | return 1; |
| 6361 | } |
| 6362 | return 0; |
| 6363 | } |
| 6364 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6365 | // 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] | 6366 | // interface pointer, one for loading the current interface. |
| 6367 | // The other checks have one temp for loading the object's class. |
| 6368 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6369 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6370 | return 2; |
| 6371 | } |
| 6372 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6373 | } |
| 6374 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6375 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6376 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6377 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6378 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6379 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6380 | case TypeCheckKind::kExactCheck: |
| 6381 | case TypeCheckKind::kAbstractClassCheck: |
| 6382 | case TypeCheckKind::kClassHierarchyCheck: |
| 6383 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6384 | call_kind = |
| 6385 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6386 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6387 | break; |
| 6388 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6389 | case TypeCheckKind::kUnresolvedCheck: |
| 6390 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6391 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6392 | break; |
| 6393 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6394 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6395 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6396 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6397 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6398 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6399 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6400 | locations->SetInAt(1, Location::Any()); |
| 6401 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6402 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6403 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6404 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6405 | } |
| 6406 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6407 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6408 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6409 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6410 | Location obj_loc = locations->InAt(0); |
| 6411 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6412 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6413 | Location out_loc = locations->Out(); |
| 6414 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6415 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6416 | DCHECK_LE(num_temps, 1u); |
| 6417 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6418 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6419 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6420 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6421 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6422 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6423 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6424 | |
| 6425 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6426 | // Avoid null check if we know obj is not null. |
| 6427 | if (instruction->MustDoNullCheck()) { |
| 6428 | __ testl(obj, obj); |
| 6429 | __ j(kEqual, &zero); |
| 6430 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6431 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6432 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6433 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6434 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6435 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6436 | out_loc, |
| 6437 | obj_loc, |
| 6438 | class_offset, |
| 6439 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6440 | if (cls.IsRegister()) { |
| 6441 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6442 | } else { |
| 6443 | DCHECK(cls.IsStackSlot()) << cls; |
| 6444 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6445 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6446 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6447 | // Classes must be equal for the instanceof to succeed. |
| 6448 | __ j(kNotEqual, &zero); |
| 6449 | __ movl(out, Immediate(1)); |
| 6450 | __ jmp(&done); |
| 6451 | break; |
| 6452 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6453 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6454 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6455 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6456 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6457 | out_loc, |
| 6458 | obj_loc, |
| 6459 | class_offset, |
| 6460 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6461 | // If the class is abstract, we eagerly fetch the super class of the |
| 6462 | // object to avoid doing a comparison we know will fail. |
| 6463 | NearLabel loop; |
| 6464 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6465 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6466 | GenerateReferenceLoadOneRegister(instruction, |
| 6467 | out_loc, |
| 6468 | super_offset, |
| 6469 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6470 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6471 | __ testl(out, out); |
| 6472 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6473 | __ j(kEqual, &done); |
| 6474 | if (cls.IsRegister()) { |
| 6475 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6476 | } else { |
| 6477 | DCHECK(cls.IsStackSlot()) << cls; |
| 6478 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6479 | } |
| 6480 | __ j(kNotEqual, &loop); |
| 6481 | __ movl(out, Immediate(1)); |
| 6482 | if (zero.IsLinked()) { |
| 6483 | __ jmp(&done); |
| 6484 | } |
| 6485 | break; |
| 6486 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6487 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6488 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6489 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6490 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6491 | out_loc, |
| 6492 | obj_loc, |
| 6493 | class_offset, |
| 6494 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6495 | // Walk over the class hierarchy to find a match. |
| 6496 | NearLabel loop, success; |
| 6497 | __ Bind(&loop); |
| 6498 | if (cls.IsRegister()) { |
| 6499 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6500 | } else { |
| 6501 | DCHECK(cls.IsStackSlot()) << cls; |
| 6502 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6503 | } |
| 6504 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6505 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6506 | GenerateReferenceLoadOneRegister(instruction, |
| 6507 | out_loc, |
| 6508 | super_offset, |
| 6509 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6510 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6511 | __ testl(out, out); |
| 6512 | __ j(kNotEqual, &loop); |
| 6513 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6514 | __ jmp(&done); |
| 6515 | __ Bind(&success); |
| 6516 | __ movl(out, Immediate(1)); |
| 6517 | if (zero.IsLinked()) { |
| 6518 | __ jmp(&done); |
| 6519 | } |
| 6520 | break; |
| 6521 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6522 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6523 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6524 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6525 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6526 | out_loc, |
| 6527 | obj_loc, |
| 6528 | class_offset, |
| 6529 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6530 | // Do an exact check. |
| 6531 | NearLabel exact_check; |
| 6532 | if (cls.IsRegister()) { |
| 6533 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6534 | } else { |
| 6535 | DCHECK(cls.IsStackSlot()) << cls; |
| 6536 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6537 | } |
| 6538 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6539 | // 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] | 6540 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6541 | GenerateReferenceLoadOneRegister(instruction, |
| 6542 | out_loc, |
| 6543 | component_offset, |
| 6544 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6545 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6546 | __ testl(out, out); |
| 6547 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6548 | __ j(kEqual, &done); |
| 6549 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6550 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6551 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6552 | __ movl(out, Immediate(1)); |
| 6553 | __ jmp(&done); |
| 6554 | break; |
| 6555 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6556 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6557 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6558 | // No read barrier since the slow path will retry upon failure. |
| 6559 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6560 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6561 | out_loc, |
| 6562 | obj_loc, |
| 6563 | class_offset, |
| 6564 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6565 | if (cls.IsRegister()) { |
| 6566 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6567 | } else { |
| 6568 | DCHECK(cls.IsStackSlot()) << cls; |
| 6569 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6570 | } |
| 6571 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6572 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6573 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6574 | codegen_->AddSlowPath(slow_path); |
| 6575 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6576 | __ movl(out, Immediate(1)); |
| 6577 | if (zero.IsLinked()) { |
| 6578 | __ jmp(&done); |
| 6579 | } |
| 6580 | break; |
| 6581 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6582 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6583 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6584 | case TypeCheckKind::kInterfaceCheck: { |
| 6585 | // 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] | 6586 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6587 | // cases. |
| 6588 | // |
| 6589 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6590 | // entry point without resorting to a type checking slow path |
| 6591 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6592 | // require to assign fixed registers for the inputs of this |
| 6593 | // HInstanceOf instruction (following the runtime calling |
| 6594 | // convention), which might be cluttered by the potential first |
| 6595 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6596 | // |
| 6597 | // TODO: Introduce a new runtime entry point taking the object |
| 6598 | // to test (instead of its class) as argument, and let it deal |
| 6599 | // with the read barrier issues. This will let us refactor this |
| 6600 | // case of the `switch` code as it was previously (with a direct |
| 6601 | // call to the runtime not using a type checking slow path). |
| 6602 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6603 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6604 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6605 | /* is_fatal */ false); |
| 6606 | codegen_->AddSlowPath(slow_path); |
| 6607 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6608 | if (zero.IsLinked()) { |
| 6609 | __ jmp(&done); |
| 6610 | } |
| 6611 | break; |
| 6612 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6613 | } |
| 6614 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6615 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6616 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6617 | __ xorl(out, out); |
| 6618 | } |
| 6619 | |
| 6620 | if (done.IsLinked()) { |
| 6621 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6622 | } |
| 6623 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6624 | if (slow_path != nullptr) { |
| 6625 | __ Bind(slow_path->GetExitLabel()); |
| 6626 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6627 | } |
| 6628 | |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6629 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6630 | switch (type_check_kind) { |
| 6631 | case TypeCheckKind::kExactCheck: |
| 6632 | case TypeCheckKind::kAbstractClassCheck: |
| 6633 | case TypeCheckKind::kClassHierarchyCheck: |
| 6634 | case TypeCheckKind::kArrayObjectCheck: |
| 6635 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6636 | case TypeCheckKind::kInterfaceCheck: |
| 6637 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6638 | case TypeCheckKind::kArrayCheck: |
| 6639 | case TypeCheckKind::kUnresolvedCheck: |
| 6640 | return false; |
| 6641 | } |
| 6642 | LOG(FATAL) << "Unreachable"; |
| 6643 | UNREACHABLE(); |
| 6644 | } |
| 6645 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6646 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6647 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6648 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6649 | LocationSummary::CallKind call_kind = |
| 6650 | IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch) |
| 6651 | ? LocationSummary::kNoCall |
| 6652 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6653 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6654 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6655 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6656 | // Require a register for the interface check since there is a loop that compares the class to |
| 6657 | // a memory address. |
| 6658 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6659 | } else { |
| 6660 | locations->SetInAt(1, Location::Any()); |
| 6661 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6662 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6663 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6664 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6665 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6666 | } |
| 6667 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6668 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6669 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6670 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6671 | Location obj_loc = locations->InAt(0); |
| 6672 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6673 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6674 | Location temp_loc = locations->GetTemp(0); |
| 6675 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6676 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6677 | DCHECK_GE(num_temps, 1u); |
| 6678 | DCHECK_LE(num_temps, 2u); |
| 6679 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6680 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6681 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6682 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6683 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6684 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6685 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6686 | const uint32_t object_array_data_offset = |
| 6687 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6688 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6689 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6690 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6691 | // read barriers is done for performance and code size reasons. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6692 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6693 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6694 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6695 | SlowPathCode* type_check_slow_path = |
| 6696 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6697 | is_type_check_slow_path_fatal); |
| 6698 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6699 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6700 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6701 | // Avoid null check if we know obj is not null. |
| 6702 | if (instruction->MustDoNullCheck()) { |
| 6703 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6704 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6705 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6706 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6707 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6708 | case TypeCheckKind::kExactCheck: |
| 6709 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6710 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6711 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6712 | temp_loc, |
| 6713 | obj_loc, |
| 6714 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6715 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6716 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6717 | if (cls.IsRegister()) { |
| 6718 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6719 | } else { |
| 6720 | DCHECK(cls.IsStackSlot()) << cls; |
| 6721 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6722 | } |
| 6723 | // Jump to slow path for throwing the exception or doing a |
| 6724 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6725 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6726 | break; |
| 6727 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6728 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6729 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6730 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6731 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6732 | temp_loc, |
| 6733 | obj_loc, |
| 6734 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6735 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6736 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6737 | // If the class is abstract, we eagerly fetch the super class of the |
| 6738 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6739 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6740 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6741 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6742 | GenerateReferenceLoadOneRegister(instruction, |
| 6743 | temp_loc, |
| 6744 | super_offset, |
| 6745 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6746 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6747 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6748 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6749 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6750 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6751 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6752 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6753 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6754 | if (cls.IsRegister()) { |
| 6755 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6756 | } else { |
| 6757 | DCHECK(cls.IsStackSlot()) << cls; |
| 6758 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6759 | } |
| 6760 | __ j(kNotEqual, &loop); |
| 6761 | break; |
| 6762 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6763 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6764 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6765 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6766 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6767 | temp_loc, |
| 6768 | obj_loc, |
| 6769 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6770 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6771 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6772 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6773 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6774 | __ Bind(&loop); |
| 6775 | if (cls.IsRegister()) { |
| 6776 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6777 | } else { |
| 6778 | DCHECK(cls.IsStackSlot()) << cls; |
| 6779 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6780 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6781 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6782 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6783 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6784 | GenerateReferenceLoadOneRegister(instruction, |
| 6785 | temp_loc, |
| 6786 | super_offset, |
| 6787 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6788 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6789 | |
| 6790 | // If the class reference currently in `temp` is not null, jump |
| 6791 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6792 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6793 | __ j(kNotZero, &loop); |
| 6794 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6795 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6796 | break; |
| 6797 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6798 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6799 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6800 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6801 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6802 | temp_loc, |
| 6803 | obj_loc, |
| 6804 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6805 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6806 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6807 | // Do an exact check. |
| 6808 | if (cls.IsRegister()) { |
| 6809 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6810 | } else { |
| 6811 | DCHECK(cls.IsStackSlot()) << cls; |
| 6812 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6813 | } |
| 6814 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6815 | |
| 6816 | // 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] | 6817 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6818 | GenerateReferenceLoadOneRegister(instruction, |
| 6819 | temp_loc, |
| 6820 | component_offset, |
| 6821 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6822 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6823 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6824 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6825 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6826 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6827 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6828 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6829 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6830 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6831 | break; |
| 6832 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6833 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6834 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6835 | // 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] | 6836 | // We cannot directly call the CheckCast runtime entry point |
| 6837 | // without resorting to a type checking slow path here (i.e. by |
| 6838 | // calling InvokeRuntime directly), as it would require to |
| 6839 | // assign fixed registers for the inputs of this HInstanceOf |
| 6840 | // instruction (following the runtime calling convention), which |
| 6841 | // might be cluttered by the potential first read barrier |
| 6842 | // emission at the beginning of this method. |
| 6843 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6844 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6845 | |
| 6846 | case TypeCheckKind::kInterfaceCheck: { |
| 6847 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6848 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6849 | // 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] | 6850 | // to the slow path if we are running under poisoning. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6851 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6852 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6853 | // doing this. |
| 6854 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6855 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6856 | temp_loc, |
| 6857 | obj_loc, |
| 6858 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6859 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6860 | |
| 6861 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6862 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6863 | temp_loc, |
| 6864 | temp_loc, |
| 6865 | iftable_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6866 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6867 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6868 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6869 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6870 | NearLabel start_loop; |
| 6871 | __ Bind(&start_loop); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6872 | // Need to subtract first to handle the empty array case. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6873 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6874 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6875 | // Go to next interface if the classes do not match. |
| 6876 | __ cmpl(cls.AsRegister<Register>(), |
| 6877 | CodeGeneratorX86::ArrayAddress(temp, |
| 6878 | maybe_temp2_loc, |
| 6879 | TIMES_4, |
| 6880 | object_array_data_offset)); |
| 6881 | __ j(kNotEqual, &start_loop); |
| 6882 | } else { |
| 6883 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6884 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6885 | break; |
| 6886 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6887 | } |
| 6888 | __ Bind(&done); |
| 6889 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6890 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6891 | } |
| 6892 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6893 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6894 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6895 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6896 | InvokeRuntimeCallingConvention calling_convention; |
| 6897 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6898 | } |
| 6899 | |
| 6900 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6901 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6902 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6903 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6904 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6905 | if (instruction->IsEnter()) { |
| 6906 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6907 | } else { |
| 6908 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6909 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6910 | } |
| 6911 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6912 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6913 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6914 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6915 | |
| 6916 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6917 | LocationSummary* locations = |
| 6918 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6919 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6920 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6921 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6922 | locations->SetInAt(1, Location::Any()); |
| 6923 | locations->SetOut(Location::SameAsFirstInput()); |
| 6924 | } |
| 6925 | |
| 6926 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6927 | HandleBitwiseOperation(instruction); |
| 6928 | } |
| 6929 | |
| 6930 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6931 | HandleBitwiseOperation(instruction); |
| 6932 | } |
| 6933 | |
| 6934 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6935 | HandleBitwiseOperation(instruction); |
| 6936 | } |
| 6937 | |
| 6938 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6939 | LocationSummary* locations = instruction->GetLocations(); |
| 6940 | Location first = locations->InAt(0); |
| 6941 | Location second = locations->InAt(1); |
| 6942 | DCHECK(first.Equals(locations->Out())); |
| 6943 | |
| 6944 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6945 | if (second.IsRegister()) { |
| 6946 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6947 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6948 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6949 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6950 | } else { |
| 6951 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6952 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6953 | } |
| 6954 | } else if (second.IsConstant()) { |
| 6955 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6956 | __ andl(first.AsRegister<Register>(), |
| 6957 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6958 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6959 | __ orl(first.AsRegister<Register>(), |
| 6960 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6961 | } else { |
| 6962 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6963 | __ xorl(first.AsRegister<Register>(), |
| 6964 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6965 | } |
| 6966 | } else { |
| 6967 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6968 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6969 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6970 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6971 | } else { |
| 6972 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6973 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6974 | } |
| 6975 | } |
| 6976 | } else { |
| 6977 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6978 | if (second.IsRegisterPair()) { |
| 6979 | if (instruction->IsAnd()) { |
| 6980 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6981 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6982 | } else if (instruction->IsOr()) { |
| 6983 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6984 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6985 | } else { |
| 6986 | DCHECK(instruction->IsXor()); |
| 6987 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6988 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6989 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6990 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6991 | if (instruction->IsAnd()) { |
| 6992 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6993 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6994 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6995 | } else if (instruction->IsOr()) { |
| 6996 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6997 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6998 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6999 | } else { |
| 7000 | DCHECK(instruction->IsXor()); |
| 7001 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7002 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7003 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7004 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7005 | } else { |
| 7006 | DCHECK(second.IsConstant()) << second; |
| 7007 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7008 | int32_t low_value = Low32Bits(value); |
| 7009 | int32_t high_value = High32Bits(value); |
| 7010 | Immediate low(low_value); |
| 7011 | Immediate high(high_value); |
| 7012 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7013 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7014 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7015 | if (low_value == 0) { |
| 7016 | __ xorl(first_low, first_low); |
| 7017 | } else if (low_value != -1) { |
| 7018 | __ andl(first_low, low); |
| 7019 | } |
| 7020 | if (high_value == 0) { |
| 7021 | __ xorl(first_high, first_high); |
| 7022 | } else if (high_value != -1) { |
| 7023 | __ andl(first_high, high); |
| 7024 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7025 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7026 | if (low_value != 0) { |
| 7027 | __ orl(first_low, low); |
| 7028 | } |
| 7029 | if (high_value != 0) { |
| 7030 | __ orl(first_high, high); |
| 7031 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7032 | } else { |
| 7033 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7034 | if (low_value != 0) { |
| 7035 | __ xorl(first_low, low); |
| 7036 | } |
| 7037 | if (high_value != 0) { |
| 7038 | __ xorl(first_high, high); |
| 7039 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7040 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7041 | } |
| 7042 | } |
| 7043 | } |
| 7044 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7045 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7046 | HInstruction* instruction, |
| 7047 | Location out, |
| 7048 | uint32_t offset, |
| 7049 | Location maybe_temp, |
| 7050 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7051 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7052 | if (read_barrier_option == kWithReadBarrier) { |
| 7053 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7054 | if (kUseBakerReadBarrier) { |
| 7055 | // Load with fast path based Baker's read barrier. |
| 7056 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7057 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7058 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7059 | } else { |
| 7060 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7061 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7062 | // in the following move operation, as we will need it for the |
| 7063 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7064 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7065 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7066 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7067 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7068 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7069 | } |
| 7070 | } else { |
| 7071 | // Plain load with no read barrier. |
| 7072 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7073 | __ movl(out_reg, Address(out_reg, offset)); |
| 7074 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7075 | } |
| 7076 | } |
| 7077 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7078 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7079 | HInstruction* instruction, |
| 7080 | Location out, |
| 7081 | Location obj, |
| 7082 | uint32_t offset, |
| 7083 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7084 | Register out_reg = out.AsRegister<Register>(); |
| 7085 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7086 | if (read_barrier_option == kWithReadBarrier) { |
| 7087 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7088 | if (kUseBakerReadBarrier) { |
| 7089 | // Load with fast path based Baker's read barrier. |
| 7090 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7091 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7092 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7093 | } else { |
| 7094 | // Load with slow path based read barrier. |
| 7095 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7096 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7097 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7098 | } |
| 7099 | } else { |
| 7100 | // Plain load with no read barrier. |
| 7101 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7102 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7103 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7104 | } |
| 7105 | } |
| 7106 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7107 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7108 | HInstruction* instruction, |
| 7109 | Location root, |
| 7110 | const Address& address, |
| 7111 | Label* fixup_label, |
| 7112 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7113 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7114 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7115 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7116 | if (kUseBakerReadBarrier) { |
| 7117 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7118 | // Baker's read barrier are used: |
| 7119 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7120 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7121 | // if (Thread::Current()->GetIsGcMarking()) { |
| 7122 | // root = ReadBarrier::Mark(root) |
| 7123 | // } |
| 7124 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7125 | // /* GcRoot<mirror::Object> */ root = *address |
| 7126 | __ movl(root_reg, address); |
| 7127 | if (fixup_label != nullptr) { |
| 7128 | __ Bind(fixup_label); |
| 7129 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7130 | static_assert( |
| 7131 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7132 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7133 | "have different sizes."); |
| 7134 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7135 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7136 | "have different sizes."); |
| 7137 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7138 | // Slow path marking the GC root `root`. |
| 7139 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7140 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7141 | codegen_->AddSlowPath(slow_path); |
| 7142 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7143 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7144 | Immediate(0)); |
| 7145 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7146 | __ Bind(slow_path->GetExitLabel()); |
| 7147 | } else { |
| 7148 | // GC root loaded through a slow path for read barriers other |
| 7149 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7150 | // /* GcRoot<mirror::Object>* */ root = address |
| 7151 | __ leal(root_reg, address); |
| 7152 | if (fixup_label != nullptr) { |
| 7153 | __ Bind(fixup_label); |
| 7154 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7155 | // /* mirror::Object* */ root = root->Read() |
| 7156 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7157 | } |
| 7158 | } else { |
| 7159 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7160 | // /* GcRoot<mirror::Object> */ root = *address |
| 7161 | __ movl(root_reg, address); |
| 7162 | if (fixup_label != nullptr) { |
| 7163 | __ Bind(fixup_label); |
| 7164 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7165 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7166 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7167 | } |
| 7168 | } |
| 7169 | |
| 7170 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7171 | Location ref, |
| 7172 | Register obj, |
| 7173 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7174 | bool needs_null_check) { |
| 7175 | DCHECK(kEmitCompilerReadBarrier); |
| 7176 | DCHECK(kUseBakerReadBarrier); |
| 7177 | |
| 7178 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7179 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7180 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7184 | Location ref, |
| 7185 | Register obj, |
| 7186 | uint32_t data_offset, |
| 7187 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7188 | bool needs_null_check) { |
| 7189 | DCHECK(kEmitCompilerReadBarrier); |
| 7190 | DCHECK(kUseBakerReadBarrier); |
| 7191 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7192 | static_assert( |
| 7193 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7194 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7195 | // /* HeapReference<Object> */ ref = |
| 7196 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7197 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7198 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7199 | } |
| 7200 | |
| 7201 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7202 | Location ref, |
| 7203 | Register obj, |
| 7204 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7205 | bool needs_null_check, |
| 7206 | bool always_update_field, |
| 7207 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7208 | DCHECK(kEmitCompilerReadBarrier); |
| 7209 | DCHECK(kUseBakerReadBarrier); |
| 7210 | |
| 7211 | // In slow path based read barriers, the read barrier call is |
| 7212 | // inserted after the original load. However, in fast path based |
| 7213 | // Baker's read barriers, we need to perform the load of |
| 7214 | // mirror::Object::monitor_ *before* the original reference load. |
| 7215 | // This load-load ordering is required by the read barrier. |
| 7216 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7217 | // |
| 7218 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7219 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7220 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7221 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7222 | // if (is_gray) { |
| 7223 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7224 | // } |
| 7225 | // |
| 7226 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7227 | // slightly more complex as: |
| 7228 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7229 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7230 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7231 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7232 | // - it performs additional checks that we do not do here for |
| 7233 | // performance reasons. |
| 7234 | |
| 7235 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7236 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7237 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7238 | // 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] | 7239 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7240 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7241 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7242 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7243 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7244 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7245 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7246 | // ref = ReadBarrier::Mark(ref); |
| 7247 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7248 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7249 | if (needs_null_check) { |
| 7250 | MaybeRecordImplicitNullCheck(instruction); |
| 7251 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7252 | |
| 7253 | // Load fence to prevent load-load reordering. |
| 7254 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7255 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7256 | |
| 7257 | // The actual reference load. |
| 7258 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7259 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7260 | |
| 7261 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7262 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7263 | SlowPathCode* slow_path; |
| 7264 | if (always_update_field) { |
| 7265 | DCHECK(temp != nullptr); |
| 7266 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| 7267 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7268 | } else { |
| 7269 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 7270 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7271 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7272 | AddSlowPath(slow_path); |
| 7273 | |
| 7274 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7275 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7276 | |
| 7277 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7278 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7279 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7280 | __ Bind(slow_path->GetExitLabel()); |
| 7281 | } |
| 7282 | |
| 7283 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7284 | Location out, |
| 7285 | Location ref, |
| 7286 | Location obj, |
| 7287 | uint32_t offset, |
| 7288 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7289 | DCHECK(kEmitCompilerReadBarrier); |
| 7290 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7291 | // Insert a slow path based read barrier *after* the reference load. |
| 7292 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7293 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7294 | // reference will be carried out by the runtime within the slow |
| 7295 | // path. |
| 7296 | // |
| 7297 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7298 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7299 | // not used by the artReadBarrierSlow entry point. |
| 7300 | // |
| 7301 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7302 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7303 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7304 | AddSlowPath(slow_path); |
| 7305 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7306 | __ jmp(slow_path->GetEntryLabel()); |
| 7307 | __ Bind(slow_path->GetExitLabel()); |
| 7308 | } |
| 7309 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7310 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7311 | Location out, |
| 7312 | Location ref, |
| 7313 | Location obj, |
| 7314 | uint32_t offset, |
| 7315 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7316 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7317 | // Baker's read barriers shall be handled by the fast path |
| 7318 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7319 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7320 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7321 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7322 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7323 | } else if (kPoisonHeapReferences) { |
| 7324 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7325 | } |
| 7326 | } |
| 7327 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7328 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7329 | Location out, |
| 7330 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7331 | DCHECK(kEmitCompilerReadBarrier); |
| 7332 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7333 | // Insert a slow path based read barrier *after* the GC root load. |
| 7334 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7335 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7336 | // not need to do anything special for this here. |
| 7337 | SlowPathCode* slow_path = |
| 7338 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7339 | AddSlowPath(slow_path); |
| 7340 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7341 | __ jmp(slow_path->GetEntryLabel()); |
| 7342 | __ Bind(slow_path->GetExitLabel()); |
| 7343 | } |
| 7344 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7345 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7346 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7347 | LOG(FATAL) << "Unreachable"; |
| 7348 | } |
| 7349 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7350 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7351 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7352 | LOG(FATAL) << "Unreachable"; |
| 7353 | } |
| 7354 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7355 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7356 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7357 | LocationSummary* locations = |
| 7358 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7359 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7360 | } |
| 7361 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7362 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7363 | int32_t lower_bound, |
| 7364 | uint32_t num_entries, |
| 7365 | HBasicBlock* switch_block, |
| 7366 | HBasicBlock* default_block) { |
| 7367 | // Figure out the correct compare values and jump conditions. |
| 7368 | // Handle the first compare/branch as a special case because it might |
| 7369 | // jump to the default case. |
| 7370 | DCHECK_GT(num_entries, 2u); |
| 7371 | Condition first_condition; |
| 7372 | uint32_t index; |
| 7373 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7374 | if (lower_bound != 0) { |
| 7375 | first_condition = kLess; |
| 7376 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7377 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7378 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7379 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7380 | index = 1; |
| 7381 | } else { |
| 7382 | // Handle all the compare/jumps below. |
| 7383 | first_condition = kBelow; |
| 7384 | index = 0; |
| 7385 | } |
| 7386 | |
| 7387 | // Handle the rest of the compare/jumps. |
| 7388 | for (; index + 1 < num_entries; index += 2) { |
| 7389 | int32_t compare_to_value = lower_bound + index + 1; |
| 7390 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7391 | // Jump to successors[index] if value < case_value[index]. |
| 7392 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7393 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7394 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7395 | } |
| 7396 | |
| 7397 | if (index != num_entries) { |
| 7398 | // There are an odd number of entries. Handle the last one. |
| 7399 | DCHECK_EQ(index + 1, num_entries); |
| 7400 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7401 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7402 | } |
| 7403 | |
| 7404 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7405 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7406 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7407 | } |
| 7408 | } |
| 7409 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7410 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7411 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7412 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7413 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7414 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7415 | |
| 7416 | GenPackedSwitchWithCompares(value_reg, |
| 7417 | lower_bound, |
| 7418 | num_entries, |
| 7419 | switch_instr->GetBlock(), |
| 7420 | switch_instr->GetDefaultBlock()); |
| 7421 | } |
| 7422 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7423 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7424 | LocationSummary* locations = |
| 7425 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7426 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7427 | |
| 7428 | // Constant area pointer. |
| 7429 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7430 | |
| 7431 | // And the temporary we need. |
| 7432 | locations->AddTemp(Location::RequiresRegister()); |
| 7433 | } |
| 7434 | |
| 7435 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7436 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7437 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7438 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7439 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7440 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7441 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7442 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7443 | GenPackedSwitchWithCompares(value_reg, |
| 7444 | lower_bound, |
| 7445 | num_entries, |
| 7446 | switch_instr->GetBlock(), |
| 7447 | default_block); |
| 7448 | return; |
| 7449 | } |
| 7450 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7451 | // Optimizing has a jump area. |
| 7452 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7453 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7454 | |
| 7455 | // Remove the bias, if needed. |
| 7456 | if (lower_bound != 0) { |
| 7457 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7458 | value_reg = temp_reg; |
| 7459 | } |
| 7460 | |
| 7461 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7462 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7463 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7464 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7465 | |
| 7466 | // We are in the range of the table. |
| 7467 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7468 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7469 | |
| 7470 | // Compute the actual target address by adding in constant_area. |
| 7471 | __ addl(temp_reg, constant_area); |
| 7472 | |
| 7473 | // And jump. |
| 7474 | __ jmp(temp_reg); |
| 7475 | } |
| 7476 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7477 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7478 | HX86ComputeBaseMethodAddress* insn) { |
| 7479 | LocationSummary* locations = |
| 7480 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7481 | locations->SetOut(Location::RequiresRegister()); |
| 7482 | } |
| 7483 | |
| 7484 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7485 | HX86ComputeBaseMethodAddress* insn) { |
| 7486 | LocationSummary* locations = insn->GetLocations(); |
| 7487 | Register reg = locations->Out().AsRegister<Register>(); |
| 7488 | |
| 7489 | // Generate call to next instruction. |
| 7490 | Label next_instruction; |
| 7491 | __ call(&next_instruction); |
| 7492 | __ Bind(&next_instruction); |
| 7493 | |
| 7494 | // Remember this offset for later use with constant area. |
| 7495 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7496 | |
| 7497 | // Grab the return address off the stack. |
| 7498 | __ popl(reg); |
| 7499 | } |
| 7500 | |
| 7501 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7502 | HX86LoadFromConstantTable* insn) { |
| 7503 | LocationSummary* locations = |
| 7504 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7505 | |
| 7506 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7507 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7508 | |
| 7509 | // 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] | 7510 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7511 | return; |
| 7512 | } |
| 7513 | |
| 7514 | switch (insn->GetType()) { |
| 7515 | case Primitive::kPrimFloat: |
| 7516 | case Primitive::kPrimDouble: |
| 7517 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7518 | break; |
| 7519 | |
| 7520 | case Primitive::kPrimInt: |
| 7521 | locations->SetOut(Location::RequiresRegister()); |
| 7522 | break; |
| 7523 | |
| 7524 | default: |
| 7525 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7526 | } |
| 7527 | } |
| 7528 | |
| 7529 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7530 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7531 | return; |
| 7532 | } |
| 7533 | |
| 7534 | LocationSummary* locations = insn->GetLocations(); |
| 7535 | Location out = locations->Out(); |
| 7536 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7537 | HConstant *value = insn->GetConstant(); |
| 7538 | |
| 7539 | switch (insn->GetType()) { |
| 7540 | case Primitive::kPrimFloat: |
| 7541 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7542 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7543 | break; |
| 7544 | |
| 7545 | case Primitive::kPrimDouble: |
| 7546 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7547 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7548 | break; |
| 7549 | |
| 7550 | case Primitive::kPrimInt: |
| 7551 | __ movl(out.AsRegister<Register>(), |
| 7552 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7553 | break; |
| 7554 | |
| 7555 | default: |
| 7556 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7557 | } |
| 7558 | } |
| 7559 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7560 | /** |
| 7561 | * Class to handle late fixup of offsets into constant area. |
| 7562 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7563 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7564 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7565 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7566 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7567 | |
| 7568 | protected: |
| 7569 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7570 | |
| 7571 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7572 | |
| 7573 | private: |
| 7574 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7575 | // Patch the correct offset for the instruction. The place to patch is the |
| 7576 | // last 4 bytes of the instruction. |
| 7577 | // The value to patch is the distance from the offset in the constant area |
| 7578 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7579 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7580 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset(); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7581 | |
| 7582 | // Patch in the right value. |
| 7583 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7584 | } |
| 7585 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7586 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7587 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7588 | }; |
| 7589 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7590 | /** |
| 7591 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7592 | * constant area. |
| 7593 | */ |
| 7594 | class JumpTableRIPFixup : public RIPFixup { |
| 7595 | public: |
| 7596 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7597 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7598 | |
| 7599 | void CreateJumpTable() { |
| 7600 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7601 | |
| 7602 | // Ensure that the reference to the jump table has the correct offset. |
| 7603 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7604 | SetOffset(offset_in_constant_table); |
| 7605 | |
| 7606 | // The label values in the jump table are computed relative to the |
| 7607 | // instruction addressing the constant area. |
| 7608 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7609 | |
| 7610 | // Populate the jump table with the correct values for the jump table. |
| 7611 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7612 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7613 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7614 | // The value that we want is the target offset - the position of the table. |
| 7615 | for (int32_t i = 0; i < num_entries; i++) { |
| 7616 | HBasicBlock* b = successors[i]; |
| 7617 | Label* l = codegen_->GetLabelOf(b); |
| 7618 | DCHECK(l->IsBound()); |
| 7619 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7620 | assembler->AppendInt32(offset_to_block); |
| 7621 | } |
| 7622 | } |
| 7623 | |
| 7624 | private: |
| 7625 | const HX86PackedSwitch* switch_instr_; |
| 7626 | }; |
| 7627 | |
| 7628 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7629 | // Generate the constant area if needed. |
| 7630 | X86Assembler* assembler = GetAssembler(); |
| 7631 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7632 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7633 | // byte values. |
| 7634 | assembler->Align(4, 0); |
| 7635 | constant_area_start_ = assembler->CodeSize(); |
| 7636 | |
| 7637 | // Populate any jump tables. |
| 7638 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7639 | jump_table->CreateJumpTable(); |
| 7640 | } |
| 7641 | |
| 7642 | // And now add the constant area to the generated code. |
| 7643 | assembler->AddConstantArea(); |
| 7644 | } |
| 7645 | |
| 7646 | // And finish up. |
| 7647 | CodeGenerator::Finalize(allocator); |
| 7648 | } |
| 7649 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7650 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7651 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7652 | return Address(reg, kDummy32BitOffset, fixup); |
| 7653 | } |
| 7654 | |
| 7655 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7656 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7657 | return Address(reg, kDummy32BitOffset, fixup); |
| 7658 | } |
| 7659 | |
| 7660 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7661 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7662 | return Address(reg, kDummy32BitOffset, fixup); |
| 7663 | } |
| 7664 | |
| 7665 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7666 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7667 | return Address(reg, kDummy32BitOffset, fixup); |
| 7668 | } |
| 7669 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7670 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7671 | if (value == 0) { |
| 7672 | __ xorl(dest, dest); |
| 7673 | } else { |
| 7674 | __ movl(dest, Immediate(value)); |
| 7675 | } |
| 7676 | } |
| 7677 | |
| 7678 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7679 | if (value == 0) { |
| 7680 | __ testl(dest, dest); |
| 7681 | } else { |
| 7682 | __ cmpl(dest, Immediate(value)); |
| 7683 | } |
| 7684 | } |
| 7685 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7686 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7687 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7688 | GenerateIntCompare(lhs_reg, rhs); |
| 7689 | } |
| 7690 | |
| 7691 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7692 | if (rhs.IsConstant()) { |
| 7693 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7694 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7695 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7696 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7697 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7698 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7699 | } |
| 7700 | } |
| 7701 | |
| 7702 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7703 | Location index, |
| 7704 | ScaleFactor scale, |
| 7705 | uint32_t data_offset) { |
| 7706 | return index.IsConstant() ? |
| 7707 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7708 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7709 | } |
| 7710 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7711 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7712 | Register reg, |
| 7713 | Register value) { |
| 7714 | // Create a fixup to be used to create and address the jump table. |
| 7715 | JumpTableRIPFixup* table_fixup = |
| 7716 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7717 | |
| 7718 | // We have to populate the jump tables. |
| 7719 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7720 | |
| 7721 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7722 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7723 | } |
| 7724 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7725 | // TODO: target as memory. |
| 7726 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7727 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7728 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7729 | return; |
| 7730 | } |
| 7731 | |
| 7732 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7733 | |
| 7734 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7735 | if (target.Equals(return_loc)) { |
| 7736 | return; |
| 7737 | } |
| 7738 | |
| 7739 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7740 | // with the else branch. |
| 7741 | if (type == Primitive::kPrimLong) { |
| 7742 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7743 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7744 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7745 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7746 | } else { |
| 7747 | // Let the parallel move resolver take care of all of this. |
| 7748 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7749 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7750 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7751 | } |
| 7752 | } |
| 7753 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7754 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7755 | const uint8_t* roots_data, |
| 7756 | const PatchInfo<Label>& info, |
| 7757 | uint64_t index_in_table) const { |
| 7758 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7759 | uintptr_t address = |
| 7760 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7761 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7762 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7763 | dchecked_integral_cast<uint32_t>(address); |
| 7764 | } |
| 7765 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7766 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7767 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7768 | const auto& it = jit_string_roots_.find( |
| 7769 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7770 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7771 | PatchJitRootUse(code, roots_data, info, it->second); |
| 7772 | } |
| 7773 | |
| 7774 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| 7775 | const auto& it = jit_class_roots_.find( |
| 7776 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7777 | DCHECK(it != jit_class_roots_.end()); |
| 7778 | PatchJitRootUse(code, roots_data, info, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7779 | } |
| 7780 | } |
| 7781 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7782 | #undef __ |
| 7783 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7784 | } // namespace x86 |
| 7785 | } // namespace art |