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" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 27 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 34 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 38 | template<class MirrorType> |
| 39 | class GcRoot; |
| 40 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | namespace x86 { |
| 42 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 43 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 45 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 46 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 47 | static constexpr int kC2ConditionMask = 0x400; |
| 48 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 49 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 50 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 51 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 52 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 53 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 55 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 57 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 59 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 60 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 62 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 63 | // Live registers will be restored in the catch block if caught. |
| 64 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 65 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 66 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 67 | instruction_, |
| 68 | instruction_->GetDexPc(), |
| 69 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 70 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 73 | bool IsFatal() const OVERRIDE { return true; } |
| 74 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 75 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 76 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 79 | }; |
| 80 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 81 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 82 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 83 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 84 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 85 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 86 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 88 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 89 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 92 | bool IsFatal() const OVERRIDE { return true; } |
| 93 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 94 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 95 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 98 | }; |
| 99 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 100 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 102 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 103 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 105 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 107 | if (is_div_) { |
| 108 | __ negl(reg_); |
| 109 | } else { |
| 110 | __ movl(reg_, Immediate(0)); |
| 111 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | __ jmp(GetExitLabel()); |
| 113 | } |
| 114 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 115 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 116 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 117 | private: |
| 118 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 119 | bool is_div_; |
| 120 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 123 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 124 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 125 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 126 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 127 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 128 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 129 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 130 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 131 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 132 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 133 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 134 | // Live registers will be restored in the catch block if caught. |
| 135 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 136 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 137 | |
| 138 | // Are we using an array length from memory? |
| 139 | HInstruction* array_length = instruction_->InputAt(1); |
| 140 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 141 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 142 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 143 | // Load the array length into our temporary. |
| 144 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 145 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 146 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 147 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 148 | // Check for conflicts with index. |
| 149 | if (length_loc.Equals(locations->InAt(0))) { |
| 150 | // We know we aren't using parameter 2. |
| 151 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 152 | } |
| 153 | __ movl(length_loc.AsRegister<Register>(), array_len); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 154 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 155 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 156 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 157 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 158 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 159 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 160 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 161 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 162 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 163 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 164 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 165 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 166 | ? kQuickThrowStringBounds |
| 167 | : kQuickThrowArrayBounds; |
| 168 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 169 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 170 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 171 | } |
| 172 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 173 | bool IsFatal() const OVERRIDE { return true; } |
| 174 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 175 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 176 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 178 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 179 | }; |
| 180 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 181 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 182 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 183 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 184 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 185 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 186 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 187 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 188 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 190 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 191 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 192 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 193 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 194 | if (successor_ == nullptr) { |
| 195 | __ jmp(GetReturnLabel()); |
| 196 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 197 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 198 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 201 | Label* GetReturnLabel() { |
| 202 | DCHECK(successor_ == nullptr); |
| 203 | return &return_label_; |
| 204 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 205 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 206 | HBasicBlock* GetSuccessor() const { |
| 207 | return successor_; |
| 208 | } |
| 209 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 210 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 211 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 212 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 213 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 214 | Label return_label_; |
| 215 | |
| 216 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 217 | }; |
| 218 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 219 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 220 | public: |
| 221 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 222 | |
| 223 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 224 | LocationSummary* locations = instruction_->GetLocations(); |
| 225 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 226 | |
| 227 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 228 | __ Bind(GetEntryLabel()); |
| 229 | SaveLiveRegisters(codegen, locations); |
| 230 | |
| 231 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 232 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 233 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 234 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 235 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 236 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 237 | RestoreLiveRegisters(codegen, locations); |
| 238 | |
| 239 | // Store the resolved String to the BSS entry. |
| 240 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 241 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 242 | locations->Out().AsRegister<Register>()); |
| 243 | Label* fixup_label = x86_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 244 | __ Bind(fixup_label); |
| 245 | |
| 246 | __ jmp(GetExitLabel()); |
| 247 | } |
| 248 | |
| 249 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 250 | |
| 251 | private: |
| 252 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 253 | }; |
| 254 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 255 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 256 | public: |
| 257 | LoadClassSlowPathX86(HLoadClass* cls, |
| 258 | HInstruction* at, |
| 259 | uint32_t dex_pc, |
| 260 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 261 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 262 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 263 | } |
| 264 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 265 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 266 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 267 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 268 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 269 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | |
| 271 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 272 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 273 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 274 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 275 | : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 276 | instruction_, |
| 277 | dex_pc_, |
| 278 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 279 | if (do_clinit_) { |
| 280 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 281 | } else { |
| 282 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 283 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 284 | |
| 285 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 286 | Location out = locations->Out(); |
| 287 | if (out.IsValid()) { |
| 288 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 289 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 290 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 291 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 292 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 293 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 294 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 295 | DCHECK(out.IsValid()); |
| 296 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 297 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 298 | locations->Out().AsRegister<Register>()); |
| 299 | Label* fixup_label = x86_codegen->NewTypeBssEntryPatch(cls_); |
| 300 | __ Bind(fixup_label); |
| 301 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 302 | __ jmp(GetExitLabel()); |
| 303 | } |
| 304 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 305 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 306 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 307 | private: |
| 308 | // The class this slow path will load. |
| 309 | HLoadClass* const cls_; |
| 310 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 311 | // The dex PC of `at_`. |
| 312 | const uint32_t dex_pc_; |
| 313 | |
| 314 | // Whether to initialize the class. |
| 315 | const bool do_clinit_; |
| 316 | |
| 317 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 318 | }; |
| 319 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 320 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 321 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 322 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 323 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 325 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 327 | DCHECK(instruction_->IsCheckCast() |
| 328 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | |
| 330 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 331 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 332 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 333 | if (!is_fatal_) { |
| 334 | SaveLiveRegisters(codegen, locations); |
| 335 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | |
| 337 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 338 | // move resolver. |
| 339 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 340 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 341 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 342 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 343 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 344 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 345 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 346 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 347 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 348 | instruction_, |
| 349 | instruction_->GetDexPc(), |
| 350 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 351 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 352 | } else { |
| 353 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 354 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 355 | instruction_, |
| 356 | instruction_->GetDexPc(), |
| 357 | this); |
| 358 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 361 | if (!is_fatal_) { |
| 362 | if (instruction_->IsInstanceOf()) { |
| 363 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 364 | } |
| 365 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 366 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 367 | __ jmp(GetExitLabel()); |
| 368 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 371 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 372 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 373 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 374 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 375 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 376 | |
| 377 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 378 | }; |
| 379 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 380 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 381 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 382 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 383 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 384 | |
| 385 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 386 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 387 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 388 | LocationSummary* locations = instruction_->GetLocations(); |
| 389 | SaveLiveRegisters(codegen, locations); |
| 390 | InvokeRuntimeCallingConvention calling_convention; |
| 391 | x86_codegen->Load32BitValue( |
| 392 | calling_convention.GetRegisterAt(0), |
| 393 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 394 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 395 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 398 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 399 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 400 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 401 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 402 | }; |
| 403 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 404 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 405 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 406 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 407 | |
| 408 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 409 | LocationSummary* locations = instruction_->GetLocations(); |
| 410 | __ Bind(GetEntryLabel()); |
| 411 | SaveLiveRegisters(codegen, locations); |
| 412 | |
| 413 | InvokeRuntimeCallingConvention calling_convention; |
| 414 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 415 | parallel_move.AddMove( |
| 416 | locations->InAt(0), |
| 417 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 418 | Primitive::kPrimNot, |
| 419 | nullptr); |
| 420 | parallel_move.AddMove( |
| 421 | locations->InAt(1), |
| 422 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 423 | Primitive::kPrimInt, |
| 424 | nullptr); |
| 425 | parallel_move.AddMove( |
| 426 | locations->InAt(2), |
| 427 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 428 | Primitive::kPrimNot, |
| 429 | nullptr); |
| 430 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 431 | |
| 432 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 433 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 434 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 435 | RestoreLiveRegisters(codegen, locations); |
| 436 | __ jmp(GetExitLabel()); |
| 437 | } |
| 438 | |
| 439 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 440 | |
| 441 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 442 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 443 | }; |
| 444 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 445 | // Slow path marking an object reference `ref` during a read |
| 446 | // barrier. The field `obj.field` in the object `obj` holding this |
| 447 | // reference does not get updated by this slow path after marking (see |
| 448 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 449 | // |
| 450 | // This means that after the execution of this slow path, `ref` will |
| 451 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 452 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 453 | // probably still be a from-space reference (unless it gets updated by |
| 454 | // another thread, or if another thread installed another object |
| 455 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 456 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 457 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 458 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 459 | Location ref, |
| 460 | bool unpoison_ref_before_marking) |
| 461 | : SlowPathCode(instruction), |
| 462 | ref_(ref), |
| 463 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 464 | DCHECK(kEmitCompilerReadBarrier); |
| 465 | } |
| 466 | |
| 467 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 468 | |
| 469 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 470 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 471 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 472 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 473 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 474 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 475 | instruction_->IsStaticFieldGet() || |
| 476 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 477 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 478 | instruction_->IsLoadClass() || |
| 479 | instruction_->IsLoadString() || |
| 480 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 481 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 482 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 483 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 484 | << "Unexpected instruction in read barrier marking slow path: " |
| 485 | << instruction_->DebugName(); |
| 486 | |
| 487 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 488 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 489 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 490 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 491 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 492 | // No need to save live registers; it's taken care of by the |
| 493 | // entrypoint. Also, there is no need to update the stack mask, |
| 494 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 495 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 496 | DCHECK_NE(ref_reg, ESP); |
| 497 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 498 | // "Compact" slow path, saving two moves. |
| 499 | // |
| 500 | // Instead of using the standard runtime calling convention (input |
| 501 | // and output in EAX): |
| 502 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 504 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 505 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 506 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 507 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 508 | // of a dedicated entrypoint: |
| 509 | // |
| 510 | // rX <- ReadBarrierMarkRegX(rX) |
| 511 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 512 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 513 | // This runtime call does not require a stack map. |
| 514 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 515 | __ jmp(GetExitLabel()); |
| 516 | } |
| 517 | |
| 518 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 519 | // The location (register) of the marked object reference. |
| 520 | const Location ref_; |
| 521 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 522 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 523 | |
| 524 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 525 | }; |
| 526 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 527 | // Slow path marking an object reference `ref` during a read barrier, |
| 528 | // and if needed, atomically updating the field `obj.field` in the |
| 529 | // object `obj` holding this reference after marking (contrary to |
| 530 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 531 | // `obj.field`). |
| 532 | // |
| 533 | // This means that after the execution of this slow path, both `ref` |
| 534 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 535 | // hold the same to-space reference (unless another thread installed |
| 536 | // another object reference (different from `ref`) in `obj.field`). |
| 537 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 538 | public: |
| 539 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 540 | Location ref, |
| 541 | Register obj, |
| 542 | const Address& field_addr, |
| 543 | bool unpoison_ref_before_marking, |
| 544 | Register temp) |
| 545 | : SlowPathCode(instruction), |
| 546 | ref_(ref), |
| 547 | obj_(obj), |
| 548 | field_addr_(field_addr), |
| 549 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 550 | temp_(temp) { |
| 551 | DCHECK(kEmitCompilerReadBarrier); |
| 552 | } |
| 553 | |
| 554 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 555 | |
| 556 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 557 | LocationSummary* locations = instruction_->GetLocations(); |
| 558 | Register ref_reg = ref_.AsRegister<Register>(); |
| 559 | DCHECK(locations->CanCall()); |
| 560 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 561 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 562 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 563 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 564 | << instruction_->DebugName(); |
| 565 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 566 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 567 | |
| 568 | __ Bind(GetEntryLabel()); |
| 569 | if (unpoison_ref_before_marking_) { |
| 570 | // Object* ref = ref_addr->AsMirrorPtr() |
| 571 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 572 | } |
| 573 | |
| 574 | // Save the old (unpoisoned) reference. |
| 575 | __ movl(temp_, ref_reg); |
| 576 | |
| 577 | // No need to save live registers; it's taken care of by the |
| 578 | // entrypoint. Also, there is no need to update the stack mask, |
| 579 | // as this runtime call will not trigger a garbage collection. |
| 580 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 581 | DCHECK_NE(ref_reg, ESP); |
| 582 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 583 | // "Compact" slow path, saving two moves. |
| 584 | // |
| 585 | // Instead of using the standard runtime calling convention (input |
| 586 | // and output in EAX): |
| 587 | // |
| 588 | // EAX <- ref |
| 589 | // EAX <- ReadBarrierMark(EAX) |
| 590 | // ref <- EAX |
| 591 | // |
| 592 | // we just use rX (the register containing `ref`) as input and output |
| 593 | // of a dedicated entrypoint: |
| 594 | // |
| 595 | // rX <- ReadBarrierMarkRegX(rX) |
| 596 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 597 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 598 | // This runtime call does not require a stack map. |
| 599 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 600 | |
| 601 | // If the new reference is different from the old reference, |
| 602 | // update the field in the holder (`*field_addr`). |
| 603 | // |
| 604 | // Note that this field could also hold a different object, if |
| 605 | // another thread had concurrently changed it. In that case, the |
| 606 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 607 | // operation below would abort the CAS, leaving the field as-is. |
| 608 | NearLabel done; |
| 609 | __ cmpl(temp_, ref_reg); |
| 610 | __ j(kEqual, &done); |
| 611 | |
| 612 | // Update the the holder's field atomically. This may fail if |
| 613 | // mutator updates before us, but it's OK. This is achieved |
| 614 | // using a strong compare-and-set (CAS) operation with relaxed |
| 615 | // memory synchronization ordering, where the expected value is |
| 616 | // the old reference and the desired value is the new reference. |
| 617 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 618 | // instruction, which requires the expected value (the old |
| 619 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 620 | // expected value (stored in `temp_`) into EAX. |
| 621 | __ pushl(EAX); |
| 622 | __ movl(EAX, temp_); |
| 623 | |
| 624 | // Convenience aliases. |
| 625 | Register base = obj_; |
| 626 | Register expected = EAX; |
| 627 | Register value = ref_reg; |
| 628 | |
| 629 | bool base_equals_value = (base == value); |
| 630 | if (kPoisonHeapReferences) { |
| 631 | if (base_equals_value) { |
| 632 | // If `base` and `value` are the same register location, move |
| 633 | // `value` to a temporary register. This way, poisoning |
| 634 | // `value` won't invalidate `base`. |
| 635 | value = temp_; |
| 636 | __ movl(value, base); |
| 637 | } |
| 638 | |
| 639 | // Check that the register allocator did not assign the location |
| 640 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 641 | // poisoning (when enabled) works as intended below. |
| 642 | // - If `value` were equal to `expected`, both references would |
| 643 | // be poisoned twice, meaning they would not be poisoned at |
| 644 | // all, as heap poisoning uses address negation. |
| 645 | // - If `base` were equal to `expected`, poisoning `expected` |
| 646 | // would invalidate `base`. |
| 647 | DCHECK_NE(value, expected); |
| 648 | DCHECK_NE(base, expected); |
| 649 | |
| 650 | __ PoisonHeapReference(expected); |
| 651 | __ PoisonHeapReference(value); |
| 652 | } |
| 653 | |
| 654 | __ LockCmpxchgl(field_addr_, value); |
| 655 | |
| 656 | // If heap poisoning is enabled, we need to unpoison the values |
| 657 | // that were poisoned earlier. |
| 658 | if (kPoisonHeapReferences) { |
| 659 | if (base_equals_value) { |
| 660 | // `value` has been moved to a temporary register, no need |
| 661 | // to unpoison it. |
| 662 | } else { |
| 663 | __ UnpoisonHeapReference(value); |
| 664 | } |
| 665 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 666 | } |
| 667 | |
| 668 | // Restore EAX. |
| 669 | __ popl(EAX); |
| 670 | |
| 671 | __ Bind(&done); |
| 672 | __ jmp(GetExitLabel()); |
| 673 | } |
| 674 | |
| 675 | private: |
| 676 | // The location (register) of the marked object reference. |
| 677 | const Location ref_; |
| 678 | // The register containing the object holding the marked object reference field. |
| 679 | const Register obj_; |
| 680 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 681 | const Address field_addr_; |
| 682 | |
| 683 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 684 | const bool unpoison_ref_before_marking_; |
| 685 | |
| 686 | const Register temp_; |
| 687 | |
| 688 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 689 | }; |
| 690 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 691 | // Slow path generating a read barrier for a heap reference. |
| 692 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 693 | public: |
| 694 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 695 | Location out, |
| 696 | Location ref, |
| 697 | Location obj, |
| 698 | uint32_t offset, |
| 699 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 700 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 701 | out_(out), |
| 702 | ref_(ref), |
| 703 | obj_(obj), |
| 704 | offset_(offset), |
| 705 | index_(index) { |
| 706 | DCHECK(kEmitCompilerReadBarrier); |
| 707 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 708 | // has been overwritten by (or after) the heap object reference load |
| 709 | // to be instrumented, e.g.: |
| 710 | // |
| 711 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 712 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 713 | // |
| 714 | // In that case, we have lost the information about the original |
| 715 | // object, and the emitted read barrier cannot work properly. |
| 716 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 717 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 718 | } |
| 719 | |
| 720 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 721 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 722 | LocationSummary* locations = instruction_->GetLocations(); |
| 723 | Register reg_out = out_.AsRegister<Register>(); |
| 724 | DCHECK(locations->CanCall()); |
| 725 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 726 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 727 | instruction_->IsStaticFieldGet() || |
| 728 | instruction_->IsArrayGet() || |
| 729 | instruction_->IsInstanceOf() || |
| 730 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 731 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 732 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 733 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 734 | |
| 735 | __ Bind(GetEntryLabel()); |
| 736 | SaveLiveRegisters(codegen, locations); |
| 737 | |
| 738 | // We may have to change the index's value, but as `index_` is a |
| 739 | // constant member (like other "inputs" of this slow path), |
| 740 | // introduce a copy of it, `index`. |
| 741 | Location index = index_; |
| 742 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 743 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 744 | if (instruction_->IsArrayGet()) { |
| 745 | // Compute the actual memory offset and store it in `index`. |
| 746 | Register index_reg = index_.AsRegister<Register>(); |
| 747 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 748 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 749 | // We are about to change the value of `index_reg` (see the |
| 750 | // calls to art::x86::X86Assembler::shll and |
| 751 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 752 | // not been saved by the previous call to |
| 753 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 754 | // callee-save register -- |
| 755 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 756 | // callee-save registers, as it has been designed with the |
| 757 | // assumption that callee-save registers are supposed to be |
| 758 | // handled by the called function. So, as a callee-save |
| 759 | // register, `index_reg` _would_ eventually be saved onto |
| 760 | // the stack, but it would be too late: we would have |
| 761 | // changed its value earlier. Therefore, we manually save |
| 762 | // it here into another freely available register, |
| 763 | // `free_reg`, chosen of course among the caller-save |
| 764 | // registers (as a callee-save `free_reg` register would |
| 765 | // exhibit the same problem). |
| 766 | // |
| 767 | // Note we could have requested a temporary register from |
| 768 | // the register allocator instead; but we prefer not to, as |
| 769 | // this is a slow path, and we know we can find a |
| 770 | // caller-save register that is available. |
| 771 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 772 | __ movl(free_reg, index_reg); |
| 773 | index_reg = free_reg; |
| 774 | index = Location::RegisterLocation(index_reg); |
| 775 | } else { |
| 776 | // The initial register stored in `index_` has already been |
| 777 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 778 | // (as it is not a callee-save register), so we can freely |
| 779 | // use it. |
| 780 | } |
| 781 | // Shifting the index value contained in `index_reg` by the scale |
| 782 | // factor (2) cannot overflow in practice, as the runtime is |
| 783 | // unable to allocate object arrays with a size larger than |
| 784 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 785 | __ shll(index_reg, Immediate(TIMES_4)); |
| 786 | static_assert( |
| 787 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 788 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 789 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 790 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 791 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 792 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 793 | // (as in the case of ArrayGet), as it is actually an offset |
| 794 | // to an object field within an object. |
| 795 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 796 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 797 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 798 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 799 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 800 | DCHECK_EQ(offset_, 0U); |
| 801 | DCHECK(index_.IsRegisterPair()); |
| 802 | // UnsafeGet's offset location is a register pair, the low |
| 803 | // part contains the correct offset. |
| 804 | index = index_.ToLow(); |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | // We're moving two or three locations to locations that could |
| 809 | // overlap, so we need a parallel move resolver. |
| 810 | InvokeRuntimeCallingConvention calling_convention; |
| 811 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 812 | parallel_move.AddMove(ref_, |
| 813 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 814 | Primitive::kPrimNot, |
| 815 | nullptr); |
| 816 | parallel_move.AddMove(obj_, |
| 817 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 818 | Primitive::kPrimNot, |
| 819 | nullptr); |
| 820 | if (index.IsValid()) { |
| 821 | parallel_move.AddMove(index, |
| 822 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 823 | Primitive::kPrimInt, |
| 824 | nullptr); |
| 825 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 826 | } else { |
| 827 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 828 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 829 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 830 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 831 | CheckEntrypointTypes< |
| 832 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 833 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 834 | |
| 835 | RestoreLiveRegisters(codegen, locations); |
| 836 | __ jmp(GetExitLabel()); |
| 837 | } |
| 838 | |
| 839 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 840 | |
| 841 | private: |
| 842 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 843 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 844 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 845 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 846 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 847 | return static_cast<Register>(i); |
| 848 | } |
| 849 | } |
| 850 | // We shall never fail to find a free caller-save register, as |
| 851 | // there are more than two core caller-save registers on x86 |
| 852 | // (meaning it is possible to find one which is different from |
| 853 | // `ref` and `obj`). |
| 854 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 855 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 856 | UNREACHABLE(); |
| 857 | } |
| 858 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 859 | const Location out_; |
| 860 | const Location ref_; |
| 861 | const Location obj_; |
| 862 | const uint32_t offset_; |
| 863 | // An additional location containing an index to an array. |
| 864 | // Only used for HArrayGet and the UnsafeGetObject & |
| 865 | // UnsafeGetObjectVolatile intrinsics. |
| 866 | const Location index_; |
| 867 | |
| 868 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 869 | }; |
| 870 | |
| 871 | // Slow path generating a read barrier for a GC root. |
| 872 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 873 | public: |
| 874 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 875 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 876 | DCHECK(kEmitCompilerReadBarrier); |
| 877 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 878 | |
| 879 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 880 | LocationSummary* locations = instruction_->GetLocations(); |
| 881 | Register reg_out = out_.AsRegister<Register>(); |
| 882 | DCHECK(locations->CanCall()); |
| 883 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 884 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 885 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 886 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 887 | |
| 888 | __ Bind(GetEntryLabel()); |
| 889 | SaveLiveRegisters(codegen, locations); |
| 890 | |
| 891 | InvokeRuntimeCallingConvention calling_convention; |
| 892 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 893 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 894 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 895 | instruction_, |
| 896 | instruction_->GetDexPc(), |
| 897 | this); |
| 898 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 899 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 900 | |
| 901 | RestoreLiveRegisters(codegen, locations); |
| 902 | __ jmp(GetExitLabel()); |
| 903 | } |
| 904 | |
| 905 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 906 | |
| 907 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 908 | const Location out_; |
| 909 | const Location root_; |
| 910 | |
| 911 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 912 | }; |
| 913 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 914 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 915 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 916 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 917 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 918 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 919 | switch (cond) { |
| 920 | case kCondEQ: return kEqual; |
| 921 | case kCondNE: return kNotEqual; |
| 922 | case kCondLT: return kLess; |
| 923 | case kCondLE: return kLessEqual; |
| 924 | case kCondGT: return kGreater; |
| 925 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 926 | case kCondB: return kBelow; |
| 927 | case kCondBE: return kBelowEqual; |
| 928 | case kCondA: return kAbove; |
| 929 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 930 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 931 | LOG(FATAL) << "Unreachable"; |
| 932 | UNREACHABLE(); |
| 933 | } |
| 934 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 935 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 936 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 937 | switch (cond) { |
| 938 | case kCondEQ: return kEqual; |
| 939 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 940 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 941 | case kCondLT: return kBelow; |
| 942 | case kCondLE: return kBelowEqual; |
| 943 | case kCondGT: return kAbove; |
| 944 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 945 | // Unsigned remain unchanged. |
| 946 | case kCondB: return kBelow; |
| 947 | case kCondBE: return kBelowEqual; |
| 948 | case kCondA: return kAbove; |
| 949 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 950 | } |
| 951 | LOG(FATAL) << "Unreachable"; |
| 952 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 955 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 956 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 960 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 961 | } |
| 962 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 963 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 964 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 965 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 966 | } |
| 967 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 968 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 969 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 970 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 971 | } |
| 972 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 973 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 974 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 975 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 976 | } else { |
| 977 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 978 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 979 | return GetFloatingPointSpillSlotSize(); |
| 980 | } |
| 981 | |
| 982 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 983 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 984 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 985 | } else { |
| 986 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 987 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 988 | return GetFloatingPointSpillSlotSize(); |
| 989 | } |
| 990 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 991 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 992 | HInstruction* instruction, |
| 993 | uint32_t dex_pc, |
| 994 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 995 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 996 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 997 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 998 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 999 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1002 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1003 | HInstruction* instruction, |
| 1004 | SlowPathCode* slow_path) { |
| 1005 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1006 | GenerateInvokeRuntime(entry_point_offset); |
| 1007 | } |
| 1008 | |
| 1009 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1010 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1011 | } |
| 1012 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1013 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1014 | const X86InstructionSetFeatures& isa_features, |
| 1015 | const CompilerOptions& compiler_options, |
| 1016 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1017 | : CodeGenerator(graph, |
| 1018 | kNumberOfCpuRegisters, |
| 1019 | kNumberOfXmmRegisters, |
| 1020 | kNumberOfRegisterPairs, |
| 1021 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1022 | arraysize(kCoreCalleeSaves)) |
| 1023 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1024 | 0, |
| 1025 | compiler_options, |
| 1026 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1027 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1028 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1029 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1030 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1031 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1032 | isa_features_(isa_features), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1033 | boot_image_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1034 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1035 | boot_image_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1036 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1037 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 1038 | string_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1039 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1040 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1041 | constant_area_start_(-1), |
| 1042 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1043 | method_address_offset_(std::less<uint32_t>(), |
| 1044 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1045 | // Use a fake return address register to mimic Quick. |
| 1046 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1047 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1048 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1049 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1050 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1051 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1052 | } |
| 1053 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1054 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1055 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1056 | assembler_(codegen->GetAssembler()), |
| 1057 | codegen_(codegen) {} |
| 1058 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1059 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1060 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1063 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1064 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1065 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1066 | bool skip_overflow_check = |
| 1067 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1068 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1069 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1070 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1071 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1072 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1075 | if (HasEmptyFrame()) { |
| 1076 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1077 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1078 | |
| 1079 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1080 | Register reg = kCoreCalleeSaves[i]; |
| 1081 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1082 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1083 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1084 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1088 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1089 | __ subl(ESP, Immediate(adjust)); |
| 1090 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1091 | // Save the current method if we need it. Note that we do not |
| 1092 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1093 | // in the SSA graph. |
| 1094 | if (RequiresCurrentMethod()) { |
| 1095 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1096 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1097 | |
| 1098 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1099 | // Initialize should_deoptimize flag to 0. |
| 1100 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1101 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1105 | __ cfi().RememberState(); |
| 1106 | if (!HasEmptyFrame()) { |
| 1107 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1108 | __ addl(ESP, Immediate(adjust)); |
| 1109 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1110 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1111 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1112 | Register reg = kCoreCalleeSaves[i]; |
| 1113 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1114 | __ popl(reg); |
| 1115 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1116 | __ cfi().Restore(DWARFReg(reg)); |
| 1117 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1118 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1119 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1120 | __ ret(); |
| 1121 | __ cfi().RestoreState(); |
| 1122 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1125 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1126 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1129 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 1130 | switch (type) { |
| 1131 | case Primitive::kPrimBoolean: |
| 1132 | case Primitive::kPrimByte: |
| 1133 | case Primitive::kPrimChar: |
| 1134 | case Primitive::kPrimShort: |
| 1135 | case Primitive::kPrimInt: |
| 1136 | case Primitive::kPrimNot: |
| 1137 | return Location::RegisterLocation(EAX); |
| 1138 | |
| 1139 | case Primitive::kPrimLong: |
| 1140 | return Location::RegisterPairLocation(EAX, EDX); |
| 1141 | |
| 1142 | case Primitive::kPrimVoid: |
| 1143 | return Location::NoLocation(); |
| 1144 | |
| 1145 | case Primitive::kPrimDouble: |
| 1146 | case Primitive::kPrimFloat: |
| 1147 | return Location::FpuRegisterLocation(XMM0); |
| 1148 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1149 | |
| 1150 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1154 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1155 | } |
| 1156 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1157 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1158 | switch (type) { |
| 1159 | case Primitive::kPrimBoolean: |
| 1160 | case Primitive::kPrimByte: |
| 1161 | case Primitive::kPrimChar: |
| 1162 | case Primitive::kPrimShort: |
| 1163 | case Primitive::kPrimInt: |
| 1164 | case Primitive::kPrimNot: { |
| 1165 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1166 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1167 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1168 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1169 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1170 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1171 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1172 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1173 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1174 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1175 | uint32_t index = gp_index_; |
| 1176 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1177 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1178 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1179 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1180 | calling_convention.GetRegisterPairAt(index)); |
| 1181 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1182 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1183 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1188 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1189 | stack_index_++; |
| 1190 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1191 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1192 | } else { |
| 1193 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1198 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1199 | stack_index_ += 2; |
| 1200 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1201 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1202 | } else { |
| 1203 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1207 | case Primitive::kPrimVoid: |
| 1208 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1209 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1210 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1211 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1212 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1213 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1214 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1215 | if (source.Equals(destination)) { |
| 1216 | return; |
| 1217 | } |
| 1218 | if (destination.IsRegister()) { |
| 1219 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1220 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1221 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1222 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1223 | } else { |
| 1224 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1225 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1226 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1227 | } else if (destination.IsFpuRegister()) { |
| 1228 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1229 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1230 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1231 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1232 | } else { |
| 1233 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1234 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1235 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1236 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1237 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1238 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1239 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1240 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1241 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1242 | } else if (source.IsConstant()) { |
| 1243 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1244 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1245 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1246 | } else { |
| 1247 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1248 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1249 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1255 | if (source.Equals(destination)) { |
| 1256 | return; |
| 1257 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1258 | if (destination.IsRegisterPair()) { |
| 1259 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1260 | EmitParallelMoves( |
| 1261 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1262 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1263 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1264 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1265 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1266 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1267 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1268 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1269 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1270 | __ psrlq(src_reg, Immediate(32)); |
| 1271 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1272 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1273 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1274 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1275 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1276 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1277 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1278 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1279 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1280 | if (source.IsFpuRegister()) { |
| 1281 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1282 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1283 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1284 | } else if (source.IsRegisterPair()) { |
| 1285 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1286 | // Create stack space for 2 elements. |
| 1287 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1288 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1289 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1290 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1291 | // And remove the temporary stack space we allocated. |
| 1292 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1293 | } else { |
| 1294 | LOG(FATAL) << "Unimplemented"; |
| 1295 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1296 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1297 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1298 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1299 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1300 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1301 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1302 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1303 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1304 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1305 | } else if (source.IsConstant()) { |
| 1306 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1307 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1308 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1309 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1310 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1311 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1312 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1313 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1314 | EmitParallelMoves( |
| 1315 | Location::StackSlot(source.GetStackIndex()), |
| 1316 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1317 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1318 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1319 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1320 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1325 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1326 | DCHECK(location.IsRegister()); |
| 1327 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1328 | } |
| 1329 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1330 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1331 | HParallelMove move(GetGraph()->GetArena()); |
| 1332 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1333 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1334 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1335 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1336 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1337 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1338 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1342 | if (location.IsRegister()) { |
| 1343 | locations->AddTemp(location); |
| 1344 | } else if (location.IsRegisterPair()) { |
| 1345 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1346 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1347 | } else { |
| 1348 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1349 | } |
| 1350 | } |
| 1351 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1352 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1353 | DCHECK(!successor->IsExitBlock()); |
| 1354 | |
| 1355 | HBasicBlock* block = got->GetBlock(); |
| 1356 | HInstruction* previous = got->GetPrevious(); |
| 1357 | |
| 1358 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1359 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1360 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1361 | return; |
| 1362 | } |
| 1363 | |
| 1364 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1365 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1366 | } |
| 1367 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1368 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1372 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1373 | got->SetLocations(nullptr); |
| 1374 | } |
| 1375 | |
| 1376 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1377 | HandleGoto(got, got->GetSuccessor()); |
| 1378 | } |
| 1379 | |
| 1380 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1381 | try_boundary->SetLocations(nullptr); |
| 1382 | } |
| 1383 | |
| 1384 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1385 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1386 | if (!successor->IsExitBlock()) { |
| 1387 | HandleGoto(try_boundary, successor); |
| 1388 | } |
| 1389 | } |
| 1390 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1391 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1392 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1395 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1398 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1399 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1400 | LabelType* true_label, |
| 1401 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1402 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1403 | __ j(kUnordered, true_label); |
| 1404 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1405 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1406 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1407 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1408 | } |
| 1409 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1410 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1411 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1412 | LabelType* true_label, |
| 1413 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1414 | LocationSummary* locations = cond->GetLocations(); |
| 1415 | Location left = locations->InAt(0); |
| 1416 | Location right = locations->InAt(1); |
| 1417 | IfCondition if_cond = cond->GetCondition(); |
| 1418 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1419 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1420 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1421 | IfCondition true_high_cond = if_cond; |
| 1422 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1423 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1424 | |
| 1425 | // Set the conditions for the test, remembering that == needs to be |
| 1426 | // decided using the low words. |
| 1427 | switch (if_cond) { |
| 1428 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1429 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1430 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1431 | break; |
| 1432 | case kCondLT: |
| 1433 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1434 | break; |
| 1435 | case kCondLE: |
| 1436 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1437 | break; |
| 1438 | case kCondGT: |
| 1439 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1440 | break; |
| 1441 | case kCondGE: |
| 1442 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1443 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1444 | case kCondB: |
| 1445 | false_high_cond = kCondA; |
| 1446 | break; |
| 1447 | case kCondBE: |
| 1448 | true_high_cond = kCondB; |
| 1449 | break; |
| 1450 | case kCondA: |
| 1451 | false_high_cond = kCondB; |
| 1452 | break; |
| 1453 | case kCondAE: |
| 1454 | true_high_cond = kCondA; |
| 1455 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | if (right.IsConstant()) { |
| 1459 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1460 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1461 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1462 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1463 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1464 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1465 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1466 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1467 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1468 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1469 | __ j(X86Condition(true_high_cond), true_label); |
| 1470 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1471 | } |
| 1472 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1473 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1474 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1475 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1476 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1477 | |
| 1478 | __ cmpl(left_high, right_high); |
| 1479 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1480 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1481 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1482 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1483 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1484 | __ j(X86Condition(true_high_cond), true_label); |
| 1485 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1486 | } |
| 1487 | // Must be equal high, so compare the lows. |
| 1488 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1489 | } else { |
| 1490 | DCHECK(right.IsDoubleStackSlot()); |
| 1491 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1492 | if (if_cond == kCondNE) { |
| 1493 | __ j(X86Condition(true_high_cond), true_label); |
| 1494 | } else if (if_cond == kCondEQ) { |
| 1495 | __ j(X86Condition(false_high_cond), false_label); |
| 1496 | } else { |
| 1497 | __ j(X86Condition(true_high_cond), true_label); |
| 1498 | __ j(X86Condition(false_high_cond), false_label); |
| 1499 | } |
| 1500 | // Must be equal high, so compare the lows. |
| 1501 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1502 | } |
| 1503 | // The last comparison might be unsigned. |
| 1504 | __ j(final_condition, true_label); |
| 1505 | } |
| 1506 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1507 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1508 | Location rhs, |
| 1509 | HInstruction* insn, |
| 1510 | bool is_double) { |
| 1511 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1512 | if (is_double) { |
| 1513 | if (rhs.IsFpuRegister()) { |
| 1514 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1515 | } else if (const_area != nullptr) { |
| 1516 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1517 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1518 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1519 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1520 | const_area->GetBaseMethodAddress(), |
| 1521 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1522 | } else { |
| 1523 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1524 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1525 | } |
| 1526 | } else { |
| 1527 | if (rhs.IsFpuRegister()) { |
| 1528 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1529 | } else if (const_area != nullptr) { |
| 1530 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1531 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1532 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1533 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1534 | const_area->GetBaseMethodAddress(), |
| 1535 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1536 | } else { |
| 1537 | DCHECK(rhs.IsStackSlot()); |
| 1538 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1543 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1544 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1545 | LabelType* true_target_in, |
| 1546 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1547 | // Generated branching requires both targets to be explicit. If either of the |
| 1548 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1549 | LabelType fallthrough_target; |
| 1550 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1551 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1552 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1553 | LocationSummary* locations = condition->GetLocations(); |
| 1554 | Location left = locations->InAt(0); |
| 1555 | Location right = locations->InAt(1); |
| 1556 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1557 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1558 | switch (type) { |
| 1559 | case Primitive::kPrimLong: |
| 1560 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1561 | break; |
| 1562 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1563 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1564 | GenerateFPJumps(condition, true_target, false_target); |
| 1565 | break; |
| 1566 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1567 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1568 | GenerateFPJumps(condition, true_target, false_target); |
| 1569 | break; |
| 1570 | default: |
| 1571 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1572 | } |
| 1573 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1574 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1575 | __ jmp(false_target); |
| 1576 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1577 | |
| 1578 | if (fallthrough_target.IsLinked()) { |
| 1579 | __ Bind(&fallthrough_target); |
| 1580 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1581 | } |
| 1582 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1583 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1584 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1585 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1586 | // conditions if they are materialized due to the complex branching. |
| 1587 | return cond->IsCondition() && |
| 1588 | cond->GetNext() == branch && |
| 1589 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1590 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1591 | } |
| 1592 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1593 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1594 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1595 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1596 | LabelType* true_target, |
| 1597 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1598 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1599 | |
| 1600 | if (true_target == nullptr && false_target == nullptr) { |
| 1601 | // Nothing to do. The code always falls through. |
| 1602 | return; |
| 1603 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1604 | // Constant condition, statically compared against "true" (integer value 1). |
| 1605 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1606 | if (true_target != nullptr) { |
| 1607 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1608 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1609 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1610 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1611 | if (false_target != nullptr) { |
| 1612 | __ jmp(false_target); |
| 1613 | } |
| 1614 | } |
| 1615 | return; |
| 1616 | } |
| 1617 | |
| 1618 | // The following code generates these patterns: |
| 1619 | // (1) true_target == nullptr && false_target != nullptr |
| 1620 | // - opposite condition true => branch to false_target |
| 1621 | // (2) true_target != nullptr && false_target == nullptr |
| 1622 | // - condition true => branch to true_target |
| 1623 | // (3) true_target != nullptr && false_target != nullptr |
| 1624 | // - condition true => branch to true_target |
| 1625 | // - branch to false_target |
| 1626 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1627 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1628 | if (true_target == nullptr) { |
| 1629 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1630 | } else { |
| 1631 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1632 | } |
| 1633 | } else { |
| 1634 | // Materialized condition, compare against 0. |
| 1635 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1636 | if (lhs.IsRegister()) { |
| 1637 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1638 | } else { |
| 1639 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1640 | } |
| 1641 | if (true_target == nullptr) { |
| 1642 | __ j(kEqual, false_target); |
| 1643 | } else { |
| 1644 | __ j(kNotEqual, true_target); |
| 1645 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1646 | } |
| 1647 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1648 | // Condition has not been materialized, use its inputs as the comparison and |
| 1649 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1650 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1651 | |
| 1652 | // If this is a long or FP comparison that has been folded into |
| 1653 | // the HCondition, generate the comparison directly. |
| 1654 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1655 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1656 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1657 | return; |
| 1658 | } |
| 1659 | |
| 1660 | Location lhs = condition->GetLocations()->InAt(0); |
| 1661 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1662 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1663 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1664 | if (true_target == nullptr) { |
| 1665 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1666 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1667 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1668 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1669 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1670 | |
| 1671 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1672 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1673 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1674 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1678 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1679 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1680 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1681 | locations->SetInAt(0, Location::Any()); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1686 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1687 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1688 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1689 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1690 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1691 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1692 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1696 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1697 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1698 | InvokeRuntimeCallingConvention calling_convention; |
| 1699 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1700 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1701 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1702 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1703 | locations->SetInAt(0, Location::Any()); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1708 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1709 | GenerateTestAndBranch<Label>(deoptimize, |
| 1710 | /* condition_input_index */ 0, |
| 1711 | slow_path->GetEntryLabel(), |
| 1712 | /* false_target */ nullptr); |
| 1713 | } |
| 1714 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1715 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1716 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1717 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1718 | locations->SetOut(Location::RequiresRegister()); |
| 1719 | } |
| 1720 | |
| 1721 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1722 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1723 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1724 | } |
| 1725 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1726 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1727 | // There are no conditional move instructions for XMMs. |
| 1728 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1729 | return false; |
| 1730 | } |
| 1731 | |
| 1732 | // A FP condition doesn't generate the single CC that we need. |
| 1733 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1734 | HInstruction* condition = select->GetCondition(); |
| 1735 | if (condition->IsCondition()) { |
| 1736 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1737 | if (compare_type == Primitive::kPrimLong || |
| 1738 | Primitive::IsFloatingPointType(compare_type)) { |
| 1739 | return false; |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | // We can generate a CMOV for this Select. |
| 1744 | return true; |
| 1745 | } |
| 1746 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1747 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1748 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1749 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1750 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1751 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1752 | } else { |
| 1753 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1754 | if (SelectCanUseCMOV(select)) { |
| 1755 | if (select->InputAt(1)->IsConstant()) { |
| 1756 | // Cmov can't handle a constant value. |
| 1757 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1758 | } else { |
| 1759 | locations->SetInAt(1, Location::Any()); |
| 1760 | } |
| 1761 | } else { |
| 1762 | locations->SetInAt(1, Location::Any()); |
| 1763 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1764 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1765 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1766 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1767 | } |
| 1768 | locations->SetOut(Location::SameAsFirstInput()); |
| 1769 | } |
| 1770 | |
| 1771 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1772 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1773 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1774 | if (SelectCanUseCMOV(select)) { |
| 1775 | // If both the condition and the source types are integer, we can generate |
| 1776 | // a CMOV to implement Select. |
| 1777 | |
| 1778 | HInstruction* select_condition = select->GetCondition(); |
| 1779 | Condition cond = kNotEqual; |
| 1780 | |
| 1781 | // Figure out how to test the 'condition'. |
| 1782 | if (select_condition->IsCondition()) { |
| 1783 | HCondition* condition = select_condition->AsCondition(); |
| 1784 | if (!condition->IsEmittedAtUseSite()) { |
| 1785 | // This was a previously materialized condition. |
| 1786 | // Can we use the existing condition code? |
| 1787 | if (AreEflagsSetFrom(condition, select)) { |
| 1788 | // Materialization was the previous instruction. Condition codes are right. |
| 1789 | cond = X86Condition(condition->GetCondition()); |
| 1790 | } else { |
| 1791 | // No, we have to recreate the condition code. |
| 1792 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1793 | __ testl(cond_reg, cond_reg); |
| 1794 | } |
| 1795 | } else { |
| 1796 | // We can't handle FP or long here. |
| 1797 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1798 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1799 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1800 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1801 | cond = X86Condition(condition->GetCondition()); |
| 1802 | } |
| 1803 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1804 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1805 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1806 | __ testl(cond_reg, cond_reg); |
| 1807 | } |
| 1808 | |
| 1809 | // If the condition is true, overwrite the output, which already contains false. |
| 1810 | Location false_loc = locations->InAt(0); |
| 1811 | Location true_loc = locations->InAt(1); |
| 1812 | if (select->GetType() == Primitive::kPrimLong) { |
| 1813 | // 64 bit conditional move. |
| 1814 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1815 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1816 | if (true_loc.IsRegisterPair()) { |
| 1817 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1818 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1819 | } else { |
| 1820 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1821 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1822 | } |
| 1823 | } else { |
| 1824 | // 32 bit conditional move. |
| 1825 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1826 | if (true_loc.IsRegister()) { |
| 1827 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1828 | } else { |
| 1829 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1830 | } |
| 1831 | } |
| 1832 | } else { |
| 1833 | NearLabel false_target; |
| 1834 | GenerateTestAndBranch<NearLabel>( |
| 1835 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1836 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1837 | __ Bind(&false_target); |
| 1838 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1841 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1842 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1843 | } |
| 1844 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1845 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1846 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | void CodeGeneratorX86::GenerateNop() { |
| 1850 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1853 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1854 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1855 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1856 | // Handle the long/FP comparisons made in instruction simplification. |
| 1857 | switch (cond->InputAt(0)->GetType()) { |
| 1858 | case Primitive::kPrimLong: { |
| 1859 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 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 | locations->SetOut(Location::RequiresRegister()); |
| 1863 | } |
| 1864 | break; |
| 1865 | } |
| 1866 | case Primitive::kPrimFloat: |
| 1867 | case Primitive::kPrimDouble: { |
| 1868 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1869 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1870 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1871 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1872 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1873 | } else { |
| 1874 | locations->SetInAt(1, Location::Any()); |
| 1875 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1876 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1877 | locations->SetOut(Location::RequiresRegister()); |
| 1878 | } |
| 1879 | break; |
| 1880 | } |
| 1881 | default: |
| 1882 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1883 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1884 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1885 | // We need a byte register. |
| 1886 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1887 | } |
| 1888 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1889 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1892 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1893 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1894 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1895 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1896 | |
| 1897 | LocationSummary* locations = cond->GetLocations(); |
| 1898 | Location lhs = locations->InAt(0); |
| 1899 | Location rhs = locations->InAt(1); |
| 1900 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1901 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1902 | |
| 1903 | switch (cond->InputAt(0)->GetType()) { |
| 1904 | default: { |
| 1905 | // Integer case. |
| 1906 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1907 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1908 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1909 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1910 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1911 | return; |
| 1912 | } |
| 1913 | case Primitive::kPrimLong: |
| 1914 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1915 | break; |
| 1916 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1917 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1918 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1919 | break; |
| 1920 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1921 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1922 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1923 | break; |
| 1924 | } |
| 1925 | |
| 1926 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1927 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1928 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1929 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1930 | __ Bind(&false_label); |
| 1931 | __ xorl(reg, reg); |
| 1932 | __ jmp(&done_label); |
| 1933 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1934 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1935 | __ Bind(&true_label); |
| 1936 | __ movl(reg, Immediate(1)); |
| 1937 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1941 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1945 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1949 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1953 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1957 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1961 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1965 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1969 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1973 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1977 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1981 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1985 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1986 | } |
| 1987 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1988 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1989 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1993 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1997 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2001 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2005 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2009 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2013 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2017 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2020 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2021 | LocationSummary* locations = |
| 2022 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2023 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2026 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2027 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2028 | } |
| 2029 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2030 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2031 | LocationSummary* locations = |
| 2032 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2033 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2034 | } |
| 2035 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2036 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2037 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2040 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2041 | LocationSummary* locations = |
| 2042 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2043 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2044 | } |
| 2045 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2046 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2047 | // Will be generated at use site. |
| 2048 | } |
| 2049 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2050 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2051 | LocationSummary* locations = |
| 2052 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2053 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2054 | } |
| 2055 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2056 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2057 | // Will be generated at use site. |
| 2058 | } |
| 2059 | |
| 2060 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2061 | LocationSummary* locations = |
| 2062 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2063 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2064 | } |
| 2065 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2066 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2067 | // Will be generated at use site. |
| 2068 | } |
| 2069 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2070 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2071 | constructor_fence->SetLocations(nullptr); |
| 2072 | } |
| 2073 | |
| 2074 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2075 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2076 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2077 | } |
| 2078 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2079 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2080 | memory_barrier->SetLocations(nullptr); |
| 2081 | } |
| 2082 | |
| 2083 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2084 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2087 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2088 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2091 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2092 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2095 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2096 | LocationSummary* locations = |
| 2097 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2098 | switch (ret->InputAt(0)->GetType()) { |
| 2099 | case Primitive::kPrimBoolean: |
| 2100 | case Primitive::kPrimByte: |
| 2101 | case Primitive::kPrimChar: |
| 2102 | case Primitive::kPrimShort: |
| 2103 | case Primitive::kPrimInt: |
| 2104 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2105 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2106 | break; |
| 2107 | |
| 2108 | case Primitive::kPrimLong: |
| 2109 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2110 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2111 | break; |
| 2112 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2113 | case Primitive::kPrimFloat: |
| 2114 | case Primitive::kPrimDouble: |
| 2115 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2116 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2117 | break; |
| 2118 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2119 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2120 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2121 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2124 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2125 | if (kIsDebugBuild) { |
| 2126 | switch (ret->InputAt(0)->GetType()) { |
| 2127 | case Primitive::kPrimBoolean: |
| 2128 | case Primitive::kPrimByte: |
| 2129 | case Primitive::kPrimChar: |
| 2130 | case Primitive::kPrimShort: |
| 2131 | case Primitive::kPrimInt: |
| 2132 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2133 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2134 | break; |
| 2135 | |
| 2136 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2137 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2138 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2139 | break; |
| 2140 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2141 | case Primitive::kPrimFloat: |
| 2142 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2143 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2144 | break; |
| 2145 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2146 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2147 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2148 | } |
| 2149 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2150 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2153 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2154 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2155 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2156 | // the method_idx. |
| 2157 | HandleInvoke(invoke); |
| 2158 | } |
| 2159 | |
| 2160 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2161 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2162 | } |
| 2163 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2164 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2165 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2166 | // art::PrepareForRegisterAllocation. |
| 2167 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2168 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2169 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2170 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2171 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2172 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2173 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2174 | return; |
| 2175 | } |
| 2176 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2177 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2178 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2179 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2180 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2181 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2182 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2183 | } |
| 2184 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2185 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2186 | if (invoke->GetLocations()->Intrinsified()) { |
| 2187 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2188 | intrinsic.Dispatch(invoke); |
| 2189 | return true; |
| 2190 | } |
| 2191 | return false; |
| 2192 | } |
| 2193 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2194 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2195 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2196 | // art::PrepareForRegisterAllocation. |
| 2197 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2198 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2199 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2200 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2201 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2202 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2203 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2204 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2205 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2209 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2210 | if (intrinsic.TryDispatch(invoke)) { |
| 2211 | return; |
| 2212 | } |
| 2213 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2214 | HandleInvoke(invoke); |
| 2215 | } |
| 2216 | |
| 2217 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2218 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2219 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2220 | } |
| 2221 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2222 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2223 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2224 | return; |
| 2225 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2226 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2227 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2228 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2231 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2232 | // This call to HandleInvoke allocates a temporary (core) register |
| 2233 | // which is also used to transfer the hidden argument from FP to |
| 2234 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2235 | HandleInvoke(invoke); |
| 2236 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2237 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2241 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2242 | LocationSummary* locations = invoke->GetLocations(); |
| 2243 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2244 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2245 | Location receiver = locations->InAt(0); |
| 2246 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2247 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2248 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2249 | // won't be modified thereafter, before the `call` instruction. |
| 2250 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2251 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2252 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2253 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2254 | if (receiver.IsStackSlot()) { |
| 2255 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2256 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2257 | __ movl(temp, Address(temp, class_offset)); |
| 2258 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2259 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2260 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2261 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2262 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2263 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2264 | // emit a read barrier for the previous class reference load. |
| 2265 | // However this is not required in practice, as this is an |
| 2266 | // intermediate/temporary reference and because the current |
| 2267 | // concurrent copying collector keeps the from-space memory |
| 2268 | // intact/accessible until the end of the marking phase (the |
| 2269 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2270 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2271 | // temp = temp->GetAddressOfIMT() |
| 2272 | __ movl(temp, |
| 2273 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2274 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2275 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2276 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2277 | __ movl(temp, Address(temp, method_offset)); |
| 2278 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2279 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2280 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2281 | |
| 2282 | DCHECK(!codegen_->IsLeafMethod()); |
| 2283 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2284 | } |
| 2285 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2286 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2287 | HandleInvoke(invoke); |
| 2288 | } |
| 2289 | |
| 2290 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2291 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2292 | } |
| 2293 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2294 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2295 | LocationSummary* locations = |
| 2296 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2297 | switch (neg->GetResultType()) { |
| 2298 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2299 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2300 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2301 | locations->SetOut(Location::SameAsFirstInput()); |
| 2302 | break; |
| 2303 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2304 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2305 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2306 | locations->SetOut(Location::SameAsFirstInput()); |
| 2307 | locations->AddTemp(Location::RequiresRegister()); |
| 2308 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2309 | break; |
| 2310 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2311 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2312 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2313 | locations->SetOut(Location::SameAsFirstInput()); |
| 2314 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2315 | break; |
| 2316 | |
| 2317 | default: |
| 2318 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2319 | } |
| 2320 | } |
| 2321 | |
| 2322 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2323 | LocationSummary* locations = neg->GetLocations(); |
| 2324 | Location out = locations->Out(); |
| 2325 | Location in = locations->InAt(0); |
| 2326 | switch (neg->GetResultType()) { |
| 2327 | case Primitive::kPrimInt: |
| 2328 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2329 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2330 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2331 | break; |
| 2332 | |
| 2333 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2334 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2335 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2336 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2337 | // Negation is similar to subtraction from zero. The least |
| 2338 | // significant byte triggers a borrow when it is different from |
| 2339 | // zero; to take it into account, add 1 to the most significant |
| 2340 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2341 | // operation. |
| 2342 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2343 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2344 | break; |
| 2345 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2346 | case Primitive::kPrimFloat: { |
| 2347 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2348 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2349 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2350 | // Implement float negation with an exclusive or with value |
| 2351 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2352 | // single-precision floating-point number). |
| 2353 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2354 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2355 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2356 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2357 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2358 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2359 | case Primitive::kPrimDouble: { |
| 2360 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2361 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2362 | // Implement double negation with an exclusive or with value |
| 2363 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2364 | // a double-precision floating-point number). |
| 2365 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2366 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2367 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2368 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2369 | |
| 2370 | default: |
| 2371 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2372 | } |
| 2373 | } |
| 2374 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2375 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2376 | LocationSummary* locations = |
| 2377 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2378 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2379 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2380 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2381 | locations->SetOut(Location::SameAsFirstInput()); |
| 2382 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2383 | } |
| 2384 | |
| 2385 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2386 | LocationSummary* locations = neg->GetLocations(); |
| 2387 | Location out = locations->Out(); |
| 2388 | DCHECK(locations->InAt(0).Equals(out)); |
| 2389 | |
| 2390 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2391 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2392 | if (neg->GetType() == Primitive::kPrimFloat) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2393 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2394 | neg->GetBaseMethodAddress(), |
| 2395 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2396 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2397 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2398 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2399 | neg->GetBaseMethodAddress(), |
| 2400 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2401 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2402 | } |
| 2403 | } |
| 2404 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2405 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2406 | Primitive::Type result_type = conversion->GetResultType(); |
| 2407 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2408 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2409 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2410 | // The float-to-long and double-to-long type conversions rely on a |
| 2411 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2412 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2413 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2414 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2415 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2416 | : LocationSummary::kNoCall; |
| 2417 | LocationSummary* locations = |
| 2418 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2419 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2420 | // The Java language does not allow treating boolean as an integral type but |
| 2421 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2422 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2423 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2424 | case Primitive::kPrimByte: |
| 2425 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2426 | case Primitive::kPrimLong: { |
| 2427 | // Type conversion from long to byte is a result of code transformations. |
| 2428 | HInstruction* input = conversion->InputAt(0); |
| 2429 | Location input_location = input->IsConstant() |
| 2430 | ? Location::ConstantLocation(input->AsConstant()) |
| 2431 | : Location::RegisterPairLocation(EAX, EDX); |
| 2432 | locations->SetInAt(0, input_location); |
| 2433 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2434 | // the validation of the linear scan implementation |
| 2435 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2436 | break; |
| 2437 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2438 | case Primitive::kPrimBoolean: |
| 2439 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2440 | case Primitive::kPrimShort: |
| 2441 | case Primitive::kPrimInt: |
| 2442 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2443 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2444 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2445 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2446 | // the validation of the linear scan implementation |
| 2447 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2448 | break; |
| 2449 | |
| 2450 | default: |
| 2451 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2452 | << " to " << result_type; |
| 2453 | } |
| 2454 | break; |
| 2455 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2456 | case Primitive::kPrimShort: |
| 2457 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimLong: |
| 2459 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimBoolean: |
| 2461 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2462 | case Primitive::kPrimByte: |
| 2463 | case Primitive::kPrimInt: |
| 2464 | case Primitive::kPrimChar: |
| 2465 | // Processing a Dex `int-to-short' instruction. |
| 2466 | locations->SetInAt(0, Location::Any()); |
| 2467 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2468 | break; |
| 2469 | |
| 2470 | default: |
| 2471 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2472 | << " to " << result_type; |
| 2473 | } |
| 2474 | break; |
| 2475 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2476 | case Primitive::kPrimInt: |
| 2477 | switch (input_type) { |
| 2478 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2479 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2480 | locations->SetInAt(0, Location::Any()); |
| 2481 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2482 | break; |
| 2483 | |
| 2484 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2485 | // Processing a Dex `float-to-int' instruction. |
| 2486 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2487 | locations->SetOut(Location::RequiresRegister()); |
| 2488 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2489 | break; |
| 2490 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2491 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2492 | // Processing a Dex `double-to-int' instruction. |
| 2493 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2494 | locations->SetOut(Location::RequiresRegister()); |
| 2495 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2496 | break; |
| 2497 | |
| 2498 | default: |
| 2499 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2500 | << " to " << result_type; |
| 2501 | } |
| 2502 | break; |
| 2503 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2504 | case Primitive::kPrimLong: |
| 2505 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2506 | case Primitive::kPrimBoolean: |
| 2507 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2508 | case Primitive::kPrimByte: |
| 2509 | case Primitive::kPrimShort: |
| 2510 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2511 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2512 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2513 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2514 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2515 | break; |
| 2516 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2517 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2518 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2519 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2520 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2521 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2522 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2523 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2524 | // The runtime helper puts the result in EAX, EDX. |
| 2525 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2526 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2527 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2528 | |
| 2529 | default: |
| 2530 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2531 | << " to " << result_type; |
| 2532 | } |
| 2533 | break; |
| 2534 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2535 | case Primitive::kPrimChar: |
| 2536 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2537 | case Primitive::kPrimLong: |
| 2538 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2539 | case Primitive::kPrimBoolean: |
| 2540 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2541 | case Primitive::kPrimByte: |
| 2542 | case Primitive::kPrimShort: |
| 2543 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2544 | // Processing a Dex `int-to-char' instruction. |
| 2545 | locations->SetInAt(0, Location::Any()); |
| 2546 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2547 | break; |
| 2548 | |
| 2549 | default: |
| 2550 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2551 | << " to " << result_type; |
| 2552 | } |
| 2553 | break; |
| 2554 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2555 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2556 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2557 | case Primitive::kPrimBoolean: |
| 2558 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2559 | case Primitive::kPrimByte: |
| 2560 | case Primitive::kPrimShort: |
| 2561 | case Primitive::kPrimInt: |
| 2562 | case Primitive::kPrimChar: |
| 2563 | // Processing a Dex `int-to-float' instruction. |
| 2564 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2565 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2566 | break; |
| 2567 | |
| 2568 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2569 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2570 | locations->SetInAt(0, Location::Any()); |
| 2571 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2572 | break; |
| 2573 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2574 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2575 | // Processing a Dex `double-to-float' instruction. |
| 2576 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2577 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2578 | break; |
| 2579 | |
| 2580 | default: |
| 2581 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2582 | << " to " << result_type; |
| 2583 | }; |
| 2584 | break; |
| 2585 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2586 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2587 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimBoolean: |
| 2589 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimByte: |
| 2591 | case Primitive::kPrimShort: |
| 2592 | case Primitive::kPrimInt: |
| 2593 | case Primitive::kPrimChar: |
| 2594 | // Processing a Dex `int-to-double' instruction. |
| 2595 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2596 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2597 | break; |
| 2598 | |
| 2599 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2600 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2601 | locations->SetInAt(0, Location::Any()); |
| 2602 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2603 | break; |
| 2604 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2606 | // Processing a Dex `float-to-double' instruction. |
| 2607 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2608 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2609 | break; |
| 2610 | |
| 2611 | default: |
| 2612 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2613 | << " to " << result_type; |
| 2614 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2615 | break; |
| 2616 | |
| 2617 | default: |
| 2618 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2619 | << " to " << result_type; |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2624 | LocationSummary* locations = conversion->GetLocations(); |
| 2625 | Location out = locations->Out(); |
| 2626 | Location in = locations->InAt(0); |
| 2627 | Primitive::Type result_type = conversion->GetResultType(); |
| 2628 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2629 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2630 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2631 | case Primitive::kPrimByte: |
| 2632 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2633 | case Primitive::kPrimLong: |
| 2634 | // Type conversion from long to byte is a result of code transformations. |
| 2635 | if (in.IsRegisterPair()) { |
| 2636 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2637 | } else { |
| 2638 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2639 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2640 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2641 | } |
| 2642 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2643 | case Primitive::kPrimBoolean: |
| 2644 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2645 | case Primitive::kPrimShort: |
| 2646 | case Primitive::kPrimInt: |
| 2647 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2648 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2649 | if (in.IsRegister()) { |
| 2650 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2651 | } else { |
| 2652 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2653 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2654 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2655 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2656 | break; |
| 2657 | |
| 2658 | default: |
| 2659 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2660 | << " to " << result_type; |
| 2661 | } |
| 2662 | break; |
| 2663 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2664 | case Primitive::kPrimShort: |
| 2665 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2666 | case Primitive::kPrimLong: |
| 2667 | // Type conversion from long to short is a result of code transformations. |
| 2668 | if (in.IsRegisterPair()) { |
| 2669 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2670 | } else if (in.IsDoubleStackSlot()) { |
| 2671 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2672 | } else { |
| 2673 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2674 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2675 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2676 | } |
| 2677 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2678 | case Primitive::kPrimBoolean: |
| 2679 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimByte: |
| 2681 | case Primitive::kPrimInt: |
| 2682 | case Primitive::kPrimChar: |
| 2683 | // Processing a Dex `int-to-short' instruction. |
| 2684 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2685 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2686 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2687 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2688 | } else { |
| 2689 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2690 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2691 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2692 | } |
| 2693 | break; |
| 2694 | |
| 2695 | default: |
| 2696 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2697 | << " to " << result_type; |
| 2698 | } |
| 2699 | break; |
| 2700 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2701 | case Primitive::kPrimInt: |
| 2702 | switch (input_type) { |
| 2703 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2704 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2705 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2706 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2707 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2708 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2709 | } else { |
| 2710 | DCHECK(in.IsConstant()); |
| 2711 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2712 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2713 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2714 | } |
| 2715 | break; |
| 2716 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2717 | case Primitive::kPrimFloat: { |
| 2718 | // Processing a Dex `float-to-int' instruction. |
| 2719 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2720 | Register output = out.AsRegister<Register>(); |
| 2721 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2722 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2723 | |
| 2724 | __ movl(output, Immediate(kPrimIntMax)); |
| 2725 | // temp = int-to-float(output) |
| 2726 | __ cvtsi2ss(temp, output); |
| 2727 | // if input >= temp goto done |
| 2728 | __ comiss(input, temp); |
| 2729 | __ j(kAboveEqual, &done); |
| 2730 | // if input == NaN goto nan |
| 2731 | __ j(kUnordered, &nan); |
| 2732 | // output = float-to-int-truncate(input) |
| 2733 | __ cvttss2si(output, input); |
| 2734 | __ jmp(&done); |
| 2735 | __ Bind(&nan); |
| 2736 | // output = 0 |
| 2737 | __ xorl(output, output); |
| 2738 | __ Bind(&done); |
| 2739 | break; |
| 2740 | } |
| 2741 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2742 | case Primitive::kPrimDouble: { |
| 2743 | // Processing a Dex `double-to-int' instruction. |
| 2744 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2745 | Register output = out.AsRegister<Register>(); |
| 2746 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2747 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2748 | |
| 2749 | __ movl(output, Immediate(kPrimIntMax)); |
| 2750 | // temp = int-to-double(output) |
| 2751 | __ cvtsi2sd(temp, output); |
| 2752 | // if input >= temp goto done |
| 2753 | __ comisd(input, temp); |
| 2754 | __ j(kAboveEqual, &done); |
| 2755 | // if input == NaN goto nan |
| 2756 | __ j(kUnordered, &nan); |
| 2757 | // output = double-to-int-truncate(input) |
| 2758 | __ cvttsd2si(output, input); |
| 2759 | __ jmp(&done); |
| 2760 | __ Bind(&nan); |
| 2761 | // output = 0 |
| 2762 | __ xorl(output, output); |
| 2763 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2764 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2765 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2766 | |
| 2767 | default: |
| 2768 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2769 | << " to " << result_type; |
| 2770 | } |
| 2771 | break; |
| 2772 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2773 | case Primitive::kPrimLong: |
| 2774 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2775 | case Primitive::kPrimBoolean: |
| 2776 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2777 | case Primitive::kPrimByte: |
| 2778 | case Primitive::kPrimShort: |
| 2779 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2780 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2781 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2782 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2783 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2784 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2785 | __ cdq(); |
| 2786 | break; |
| 2787 | |
| 2788 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2789 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2790 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2791 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2792 | break; |
| 2793 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2794 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2795 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2796 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2797 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2798 | break; |
| 2799 | |
| 2800 | default: |
| 2801 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2802 | << " to " << result_type; |
| 2803 | } |
| 2804 | break; |
| 2805 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2806 | case Primitive::kPrimChar: |
| 2807 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2808 | case Primitive::kPrimLong: |
| 2809 | // Type conversion from long to short is a result of code transformations. |
| 2810 | if (in.IsRegisterPair()) { |
| 2811 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2812 | } else if (in.IsDoubleStackSlot()) { |
| 2813 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2814 | } else { |
| 2815 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2816 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2817 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2818 | } |
| 2819 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2820 | case Primitive::kPrimBoolean: |
| 2821 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2822 | case Primitive::kPrimByte: |
| 2823 | case Primitive::kPrimShort: |
| 2824 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2825 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2826 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2827 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2828 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2829 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2830 | } else { |
| 2831 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2832 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2833 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2834 | } |
| 2835 | break; |
| 2836 | |
| 2837 | default: |
| 2838 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2839 | << " to " << result_type; |
| 2840 | } |
| 2841 | break; |
| 2842 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2843 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2844 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2845 | case Primitive::kPrimBoolean: |
| 2846 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2847 | case Primitive::kPrimByte: |
| 2848 | case Primitive::kPrimShort: |
| 2849 | case Primitive::kPrimInt: |
| 2850 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2851 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2852 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2853 | break; |
| 2854 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2855 | case Primitive::kPrimLong: { |
| 2856 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2857 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2858 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2859 | // Create stack space for the call to |
| 2860 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2861 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2862 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2863 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2864 | __ subl(ESP, Immediate(adjustment)); |
| 2865 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2866 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2867 | // Load the value to the FP stack, using temporaries if needed. |
| 2868 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2869 | |
| 2870 | if (out.IsStackSlot()) { |
| 2871 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2872 | } else { |
| 2873 | __ fstps(Address(ESP, 0)); |
| 2874 | Location stack_temp = Location::StackSlot(0); |
| 2875 | codegen_->Move32(out, stack_temp); |
| 2876 | } |
| 2877 | |
| 2878 | // Remove the temporary stack space we allocated. |
| 2879 | if (adjustment != 0) { |
| 2880 | __ addl(ESP, Immediate(adjustment)); |
| 2881 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2882 | break; |
| 2883 | } |
| 2884 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2885 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2886 | // Processing a Dex `double-to-float' instruction. |
| 2887 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2888 | break; |
| 2889 | |
| 2890 | default: |
| 2891 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2892 | << " to " << result_type; |
| 2893 | }; |
| 2894 | break; |
| 2895 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2896 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2897 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2898 | case Primitive::kPrimBoolean: |
| 2899 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2900 | case Primitive::kPrimByte: |
| 2901 | case Primitive::kPrimShort: |
| 2902 | case Primitive::kPrimInt: |
| 2903 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2904 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2905 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2906 | break; |
| 2907 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2908 | case Primitive::kPrimLong: { |
| 2909 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2910 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2911 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2912 | // Create stack space for the call to |
| 2913 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2914 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2915 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2916 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2917 | __ subl(ESP, Immediate(adjustment)); |
| 2918 | } |
| 2919 | |
| 2920 | // Load the value to the FP stack, using temporaries if needed. |
| 2921 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2922 | |
| 2923 | if (out.IsDoubleStackSlot()) { |
| 2924 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2925 | } else { |
| 2926 | __ fstpl(Address(ESP, 0)); |
| 2927 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2928 | codegen_->Move64(out, stack_temp); |
| 2929 | } |
| 2930 | |
| 2931 | // Remove the temporary stack space we allocated. |
| 2932 | if (adjustment != 0) { |
| 2933 | __ addl(ESP, Immediate(adjustment)); |
| 2934 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2935 | break; |
| 2936 | } |
| 2937 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2938 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2939 | // Processing a Dex `float-to-double' instruction. |
| 2940 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2941 | break; |
| 2942 | |
| 2943 | default: |
| 2944 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2945 | << " to " << result_type; |
| 2946 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2947 | break; |
| 2948 | |
| 2949 | default: |
| 2950 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2951 | << " to " << result_type; |
| 2952 | } |
| 2953 | } |
| 2954 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2955 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2956 | LocationSummary* locations = |
| 2957 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2958 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2959 | case Primitive::kPrimInt: { |
| 2960 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2961 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2962 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2963 | break; |
| 2964 | } |
| 2965 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2966 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2967 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2968 | locations->SetInAt(1, Location::Any()); |
| 2969 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2970 | break; |
| 2971 | } |
| 2972 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2973 | case Primitive::kPrimFloat: |
| 2974 | case Primitive::kPrimDouble: { |
| 2975 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2976 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2977 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2978 | } else if (add->InputAt(1)->IsConstant()) { |
| 2979 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2980 | } else { |
| 2981 | locations->SetInAt(1, Location::Any()); |
| 2982 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2983 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2984 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2985 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2986 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2987 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2988 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2989 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2990 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2994 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2995 | Location first = locations->InAt(0); |
| 2996 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2997 | Location out = locations->Out(); |
| 2998 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2999 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3000 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3001 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3002 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3003 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3004 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3005 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3006 | } else { |
| 3007 | __ leal(out.AsRegister<Register>(), Address( |
| 3008 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3009 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3010 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3011 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3012 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3013 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3014 | } else { |
| 3015 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3016 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3017 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3018 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3019 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3020 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3021 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3025 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3026 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3027 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3028 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3029 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3030 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3031 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3032 | } else { |
| 3033 | DCHECK(second.IsConstant()) << second; |
| 3034 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3035 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3036 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3037 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3038 | break; |
| 3039 | } |
| 3040 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3041 | case Primitive::kPrimFloat: { |
| 3042 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3043 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3044 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3045 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3046 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3047 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3048 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3049 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3050 | const_area->GetBaseMethodAddress(), |
| 3051 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3052 | } else { |
| 3053 | DCHECK(second.IsStackSlot()); |
| 3054 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3055 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3056 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | case Primitive::kPrimDouble: { |
| 3060 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3061 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3062 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3063 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3064 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3065 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3066 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3067 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3068 | const_area->GetBaseMethodAddress(), |
| 3069 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3070 | } else { |
| 3071 | DCHECK(second.IsDoubleStackSlot()); |
| 3072 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3073 | } |
| 3074 | break; |
| 3075 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3076 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3077 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3078 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3079 | } |
| 3080 | } |
| 3081 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3082 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3083 | LocationSummary* locations = |
| 3084 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3085 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3086 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3087 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3088 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3089 | locations->SetInAt(1, Location::Any()); |
| 3090 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3091 | break; |
| 3092 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3093 | case Primitive::kPrimFloat: |
| 3094 | case Primitive::kPrimDouble: { |
| 3095 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3096 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3097 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3098 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3099 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3100 | } else { |
| 3101 | locations->SetInAt(1, Location::Any()); |
| 3102 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3103 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3104 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3105 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3106 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3107 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3108 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3109 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3113 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3114 | Location first = locations->InAt(0); |
| 3115 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3116 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3117 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3118 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3119 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3120 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3121 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3122 | __ subl(first.AsRegister<Register>(), |
| 3123 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3124 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3125 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3126 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3127 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3131 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3132 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3133 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3134 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3135 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3136 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3137 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3138 | } else { |
| 3139 | DCHECK(second.IsConstant()) << second; |
| 3140 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3141 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3142 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3143 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3144 | break; |
| 3145 | } |
| 3146 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3147 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3148 | if (second.IsFpuRegister()) { |
| 3149 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3150 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3151 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3152 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3153 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3154 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3155 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3156 | const_area->GetBaseMethodAddress(), |
| 3157 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3158 | } else { |
| 3159 | DCHECK(second.IsStackSlot()); |
| 3160 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3161 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3162 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3166 | if (second.IsFpuRegister()) { |
| 3167 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3168 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3169 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3170 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3171 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3172 | codegen_->LiteralDoubleAddress( |
| 3173 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3174 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3175 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3176 | } else { |
| 3177 | DCHECK(second.IsDoubleStackSlot()); |
| 3178 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3179 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3180 | break; |
| 3181 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3182 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3183 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3184 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3185 | } |
| 3186 | } |
| 3187 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3188 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3189 | LocationSummary* locations = |
| 3190 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3191 | switch (mul->GetResultType()) { |
| 3192 | case Primitive::kPrimInt: |
| 3193 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3194 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3195 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3196 | // Can use 3 operand multiply. |
| 3197 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3198 | } else { |
| 3199 | locations->SetOut(Location::SameAsFirstInput()); |
| 3200 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3201 | break; |
| 3202 | case Primitive::kPrimLong: { |
| 3203 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3204 | locations->SetInAt(1, Location::Any()); |
| 3205 | locations->SetOut(Location::SameAsFirstInput()); |
| 3206 | // Needed for imul on 32bits with 64bits output. |
| 3207 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3208 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3209 | break; |
| 3210 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3211 | case Primitive::kPrimFloat: |
| 3212 | case Primitive::kPrimDouble: { |
| 3213 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3214 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3215 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3216 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3217 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3218 | } else { |
| 3219 | locations->SetInAt(1, Location::Any()); |
| 3220 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3221 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3222 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3223 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3224 | |
| 3225 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3226 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3227 | } |
| 3228 | } |
| 3229 | |
| 3230 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3231 | LocationSummary* locations = mul->GetLocations(); |
| 3232 | Location first = locations->InAt(0); |
| 3233 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3234 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3235 | |
| 3236 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3237 | case Primitive::kPrimInt: |
| 3238 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3239 | // problems where the output may not be the same as the first operand. |
| 3240 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3241 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3242 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3243 | } else if (second.IsRegister()) { |
| 3244 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3245 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3246 | } else { |
| 3247 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3248 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3249 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3250 | } |
| 3251 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3252 | |
| 3253 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3254 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3255 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3256 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3257 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3258 | |
| 3259 | DCHECK_EQ(EAX, eax); |
| 3260 | DCHECK_EQ(EDX, edx); |
| 3261 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3262 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3263 | // output: in1 |
| 3264 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3265 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3266 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3267 | if (second.IsConstant()) { |
| 3268 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3269 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3270 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3271 | int32_t low_value = Low32Bits(value); |
| 3272 | int32_t high_value = High32Bits(value); |
| 3273 | Immediate low(low_value); |
| 3274 | Immediate high(high_value); |
| 3275 | |
| 3276 | __ movl(eax, high); |
| 3277 | // eax <- in1.lo * in2.hi |
| 3278 | __ imull(eax, in1_lo); |
| 3279 | // in1.hi <- in1.hi * in2.lo |
| 3280 | __ imull(in1_hi, low); |
| 3281 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3282 | __ addl(in1_hi, eax); |
| 3283 | // move in2_lo to eax to prepare for double precision |
| 3284 | __ movl(eax, low); |
| 3285 | // edx:eax <- in1.lo * in2.lo |
| 3286 | __ mull(in1_lo); |
| 3287 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3288 | __ addl(in1_hi, edx); |
| 3289 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3290 | __ movl(in1_lo, eax); |
| 3291 | } else if (second.IsRegisterPair()) { |
| 3292 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3293 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3294 | |
| 3295 | __ movl(eax, in2_hi); |
| 3296 | // eax <- in1.lo * in2.hi |
| 3297 | __ imull(eax, in1_lo); |
| 3298 | // in1.hi <- in1.hi * in2.lo |
| 3299 | __ imull(in1_hi, in2_lo); |
| 3300 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3301 | __ addl(in1_hi, eax); |
| 3302 | // move in1_lo to eax to prepare for double precision |
| 3303 | __ movl(eax, in1_lo); |
| 3304 | // edx:eax <- in1.lo * in2.lo |
| 3305 | __ mull(in2_lo); |
| 3306 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3307 | __ addl(in1_hi, edx); |
| 3308 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3309 | __ movl(in1_lo, eax); |
| 3310 | } else { |
| 3311 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3312 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3313 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3314 | |
| 3315 | __ movl(eax, in2_hi); |
| 3316 | // eax <- in1.lo * in2.hi |
| 3317 | __ imull(eax, in1_lo); |
| 3318 | // in1.hi <- in1.hi * in2.lo |
| 3319 | __ imull(in1_hi, in2_lo); |
| 3320 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3321 | __ addl(in1_hi, eax); |
| 3322 | // move in1_lo to eax to prepare for double precision |
| 3323 | __ movl(eax, in1_lo); |
| 3324 | // edx:eax <- in1.lo * in2.lo |
| 3325 | __ mull(in2_lo); |
| 3326 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3327 | __ addl(in1_hi, edx); |
| 3328 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3329 | __ movl(in1_lo, eax); |
| 3330 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3331 | |
| 3332 | break; |
| 3333 | } |
| 3334 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3335 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3336 | DCHECK(first.Equals(locations->Out())); |
| 3337 | if (second.IsFpuRegister()) { |
| 3338 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3339 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3340 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3341 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3342 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3343 | codegen_->LiteralFloatAddress( |
| 3344 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3345 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3346 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3347 | } else { |
| 3348 | DCHECK(second.IsStackSlot()); |
| 3349 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3350 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3351 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3355 | DCHECK(first.Equals(locations->Out())); |
| 3356 | if (second.IsFpuRegister()) { |
| 3357 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3358 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3359 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3360 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3361 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3362 | codegen_->LiteralDoubleAddress( |
| 3363 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3364 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3365 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3366 | } else { |
| 3367 | DCHECK(second.IsDoubleStackSlot()); |
| 3368 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3369 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3370 | break; |
| 3371 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3372 | |
| 3373 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3374 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3375 | } |
| 3376 | } |
| 3377 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3378 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3379 | uint32_t temp_offset, |
| 3380 | uint32_t stack_adjustment, |
| 3381 | bool is_fp, |
| 3382 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3383 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3384 | DCHECK(!is_wide); |
| 3385 | if (is_fp) { |
| 3386 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3387 | } else { |
| 3388 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3389 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3390 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3391 | DCHECK(is_wide); |
| 3392 | if (is_fp) { |
| 3393 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3394 | } else { |
| 3395 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3396 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3397 | } else { |
| 3398 | // 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] | 3399 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3400 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3401 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3402 | if (is_fp) { |
| 3403 | __ flds(Address(ESP, temp_offset)); |
| 3404 | } else { |
| 3405 | __ filds(Address(ESP, temp_offset)); |
| 3406 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3407 | } else { |
| 3408 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3409 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3410 | if (is_fp) { |
| 3411 | __ fldl(Address(ESP, temp_offset)); |
| 3412 | } else { |
| 3413 | __ fildl(Address(ESP, temp_offset)); |
| 3414 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3415 | } |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3420 | Primitive::Type type = rem->GetResultType(); |
| 3421 | bool is_float = type == Primitive::kPrimFloat; |
| 3422 | size_t elem_size = Primitive::ComponentSize(type); |
| 3423 | LocationSummary* locations = rem->GetLocations(); |
| 3424 | Location first = locations->InAt(0); |
| 3425 | Location second = locations->InAt(1); |
| 3426 | Location out = locations->Out(); |
| 3427 | |
| 3428 | // Create stack space for 2 elements. |
| 3429 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3430 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3431 | |
| 3432 | // 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] | 3433 | const bool is_wide = !is_float; |
| 3434 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3435 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3436 | |
| 3437 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3438 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3439 | __ Bind(&retry); |
| 3440 | __ fprem(); |
| 3441 | |
| 3442 | // Move FP status to AX. |
| 3443 | __ fstsw(); |
| 3444 | |
| 3445 | // And see if the argument reduction is complete. This is signaled by the |
| 3446 | // C2 FPU flag bit set to 0. |
| 3447 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3448 | __ j(kNotEqual, &retry); |
| 3449 | |
| 3450 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3451 | // Store FP top of stack to real stack. |
| 3452 | if (is_float) { |
| 3453 | __ fsts(Address(ESP, 0)); |
| 3454 | } else { |
| 3455 | __ fstl(Address(ESP, 0)); |
| 3456 | } |
| 3457 | |
| 3458 | // Pop the 2 items from the FP stack. |
| 3459 | __ fucompp(); |
| 3460 | |
| 3461 | // Load the value from the stack into an XMM register. |
| 3462 | DCHECK(out.IsFpuRegister()) << out; |
| 3463 | if (is_float) { |
| 3464 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3465 | } else { |
| 3466 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3467 | } |
| 3468 | |
| 3469 | // And remove the temporary stack space we allocated. |
| 3470 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3471 | } |
| 3472 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3473 | |
| 3474 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3475 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3476 | |
| 3477 | LocationSummary* locations = instruction->GetLocations(); |
| 3478 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3479 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3480 | |
| 3481 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3482 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3483 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3484 | |
| 3485 | DCHECK(imm == 1 || imm == -1); |
| 3486 | |
| 3487 | if (instruction->IsRem()) { |
| 3488 | __ xorl(out_register, out_register); |
| 3489 | } else { |
| 3490 | __ movl(out_register, input_register); |
| 3491 | if (imm == -1) { |
| 3492 | __ negl(out_register); |
| 3493 | } |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3498 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3499 | LocationSummary* locations = instruction->GetLocations(); |
| 3500 | |
| 3501 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3502 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3503 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3504 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3505 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3506 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3507 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3508 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3509 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3510 | __ testl(input_register, input_register); |
| 3511 | __ cmovl(kGreaterEqual, num, input_register); |
| 3512 | int shift = CTZ(imm); |
| 3513 | __ sarl(num, Immediate(shift)); |
| 3514 | |
| 3515 | if (imm < 0) { |
| 3516 | __ negl(num); |
| 3517 | } |
| 3518 | |
| 3519 | __ movl(out_register, num); |
| 3520 | } |
| 3521 | |
| 3522 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3523 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3524 | |
| 3525 | LocationSummary* locations = instruction->GetLocations(); |
| 3526 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3527 | |
| 3528 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3529 | Register out = locations->Out().AsRegister<Register>(); |
| 3530 | Register num; |
| 3531 | Register edx; |
| 3532 | |
| 3533 | if (instruction->IsDiv()) { |
| 3534 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3535 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3536 | } else { |
| 3537 | edx = locations->Out().AsRegister<Register>(); |
| 3538 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3539 | } |
| 3540 | |
| 3541 | DCHECK_EQ(EAX, eax); |
| 3542 | DCHECK_EQ(EDX, edx); |
| 3543 | if (instruction->IsDiv()) { |
| 3544 | DCHECK_EQ(EAX, out); |
| 3545 | } else { |
| 3546 | DCHECK_EQ(EDX, out); |
| 3547 | } |
| 3548 | |
| 3549 | int64_t magic; |
| 3550 | int shift; |
| 3551 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3552 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3553 | // Save the numerator. |
| 3554 | __ movl(num, eax); |
| 3555 | |
| 3556 | // EAX = magic |
| 3557 | __ movl(eax, Immediate(magic)); |
| 3558 | |
| 3559 | // EDX:EAX = magic * numerator |
| 3560 | __ imull(num); |
| 3561 | |
| 3562 | if (imm > 0 && magic < 0) { |
| 3563 | // EDX += num |
| 3564 | __ addl(edx, num); |
| 3565 | } else if (imm < 0 && magic > 0) { |
| 3566 | __ subl(edx, num); |
| 3567 | } |
| 3568 | |
| 3569 | // Shift if needed. |
| 3570 | if (shift != 0) { |
| 3571 | __ sarl(edx, Immediate(shift)); |
| 3572 | } |
| 3573 | |
| 3574 | // EDX += 1 if EDX < 0 |
| 3575 | __ movl(eax, edx); |
| 3576 | __ shrl(edx, Immediate(31)); |
| 3577 | __ addl(edx, eax); |
| 3578 | |
| 3579 | if (instruction->IsRem()) { |
| 3580 | __ movl(eax, num); |
| 3581 | __ imull(edx, Immediate(imm)); |
| 3582 | __ subl(eax, edx); |
| 3583 | __ movl(edx, eax); |
| 3584 | } else { |
| 3585 | __ movl(eax, edx); |
| 3586 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3587 | } |
| 3588 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3589 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3590 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3591 | |
| 3592 | LocationSummary* locations = instruction->GetLocations(); |
| 3593 | Location out = locations->Out(); |
| 3594 | Location first = locations->InAt(0); |
| 3595 | Location second = locations->InAt(1); |
| 3596 | bool is_div = instruction->IsDiv(); |
| 3597 | |
| 3598 | switch (instruction->GetResultType()) { |
| 3599 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3600 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3601 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3602 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3603 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3604 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3605 | |
| 3606 | if (imm == 0) { |
| 3607 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3608 | } else if (imm == 1 || imm == -1) { |
| 3609 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3610 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3611 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3612 | } else { |
| 3613 | DCHECK(imm <= -2 || imm >= 2); |
| 3614 | GenerateDivRemWithAnyConstant(instruction); |
| 3615 | } |
| 3616 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3617 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3618 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3619 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3620 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3621 | Register second_reg = second.AsRegister<Register>(); |
| 3622 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3623 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3624 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3625 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3626 | __ cmpl(second_reg, Immediate(-1)); |
| 3627 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3628 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3629 | // edx:eax <- sign-extended of eax |
| 3630 | __ cdq(); |
| 3631 | // eax = quotient, edx = remainder |
| 3632 | __ idivl(second_reg); |
| 3633 | __ Bind(slow_path->GetExitLabel()); |
| 3634 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3635 | break; |
| 3636 | } |
| 3637 | |
| 3638 | case Primitive::kPrimLong: { |
| 3639 | InvokeRuntimeCallingConvention calling_convention; |
| 3640 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3641 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3642 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3643 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3644 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3645 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3646 | |
| 3647 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3648 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3649 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3650 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3651 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3652 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3653 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3654 | break; |
| 3655 | } |
| 3656 | |
| 3657 | default: |
| 3658 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3659 | } |
| 3660 | } |
| 3661 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3662 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3663 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3664 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3665 | : LocationSummary::kNoCall; |
| 3666 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3667 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3668 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3669 | case Primitive::kPrimInt: { |
| 3670 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3671 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3672 | locations->SetOut(Location::SameAsFirstInput()); |
| 3673 | // Intel uses edx:eax as the dividend. |
| 3674 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3675 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3676 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3677 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3678 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3679 | locations->AddTemp(Location::RequiresRegister()); |
| 3680 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3681 | break; |
| 3682 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3683 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3684 | InvokeRuntimeCallingConvention calling_convention; |
| 3685 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3686 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3687 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3688 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3689 | // Runtime helper puts the result in EAX, EDX. |
| 3690 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3691 | break; |
| 3692 | } |
| 3693 | case Primitive::kPrimFloat: |
| 3694 | case Primitive::kPrimDouble: { |
| 3695 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3696 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3697 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3698 | } else if (div->InputAt(1)->IsConstant()) { |
| 3699 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3700 | } else { |
| 3701 | locations->SetInAt(1, Location::Any()); |
| 3702 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3703 | locations->SetOut(Location::SameAsFirstInput()); |
| 3704 | break; |
| 3705 | } |
| 3706 | |
| 3707 | default: |
| 3708 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3713 | LocationSummary* locations = div->GetLocations(); |
| 3714 | Location first = locations->InAt(0); |
| 3715 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3716 | |
| 3717 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3718 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3719 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3720 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3721 | break; |
| 3722 | } |
| 3723 | |
| 3724 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3725 | if (second.IsFpuRegister()) { |
| 3726 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3727 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3728 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3729 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3730 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3731 | codegen_->LiteralFloatAddress( |
| 3732 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3733 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3734 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3735 | } else { |
| 3736 | DCHECK(second.IsStackSlot()); |
| 3737 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3738 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3739 | break; |
| 3740 | } |
| 3741 | |
| 3742 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3743 | if (second.IsFpuRegister()) { |
| 3744 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3745 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3746 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3747 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3748 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3749 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3750 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3751 | const_area->GetBaseMethodAddress(), |
| 3752 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3753 | } else { |
| 3754 | DCHECK(second.IsDoubleStackSlot()); |
| 3755 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3756 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3757 | break; |
| 3758 | } |
| 3759 | |
| 3760 | default: |
| 3761 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3762 | } |
| 3763 | } |
| 3764 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3765 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3766 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3767 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3768 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3769 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3770 | : LocationSummary::kNoCall; |
| 3771 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3772 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3773 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3774 | case Primitive::kPrimInt: { |
| 3775 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3776 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3777 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3778 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3779 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3780 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3781 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3782 | locations->AddTemp(Location::RequiresRegister()); |
| 3783 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3784 | break; |
| 3785 | } |
| 3786 | case Primitive::kPrimLong: { |
| 3787 | InvokeRuntimeCallingConvention calling_convention; |
| 3788 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3789 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3790 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3791 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3792 | // Runtime helper puts the result in EAX, EDX. |
| 3793 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3794 | break; |
| 3795 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3796 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3797 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3798 | locations->SetInAt(0, Location::Any()); |
| 3799 | locations->SetInAt(1, Location::Any()); |
| 3800 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3801 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3802 | break; |
| 3803 | } |
| 3804 | |
| 3805 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3806 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3811 | Primitive::Type type = rem->GetResultType(); |
| 3812 | switch (type) { |
| 3813 | case Primitive::kPrimInt: |
| 3814 | case Primitive::kPrimLong: { |
| 3815 | GenerateDivRemIntegral(rem); |
| 3816 | break; |
| 3817 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3818 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3819 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3820 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3821 | break; |
| 3822 | } |
| 3823 | default: |
| 3824 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3825 | } |
| 3826 | } |
| 3827 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3828 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3829 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3830 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3831 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3832 | case Primitive::kPrimByte: |
| 3833 | case Primitive::kPrimChar: |
| 3834 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3835 | case Primitive::kPrimInt: { |
| 3836 | locations->SetInAt(0, Location::Any()); |
| 3837 | break; |
| 3838 | } |
| 3839 | case Primitive::kPrimLong: { |
| 3840 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3841 | if (!instruction->IsConstant()) { |
| 3842 | locations->AddTemp(Location::RequiresRegister()); |
| 3843 | } |
| 3844 | break; |
| 3845 | } |
| 3846 | default: |
| 3847 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3848 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3852 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3853 | codegen_->AddSlowPath(slow_path); |
| 3854 | |
| 3855 | LocationSummary* locations = instruction->GetLocations(); |
| 3856 | Location value = locations->InAt(0); |
| 3857 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3858 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3859 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3860 | case Primitive::kPrimByte: |
| 3861 | case Primitive::kPrimChar: |
| 3862 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3863 | case Primitive::kPrimInt: { |
| 3864 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3865 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3866 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3867 | } else if (value.IsStackSlot()) { |
| 3868 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3869 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3870 | } else { |
| 3871 | DCHECK(value.IsConstant()) << value; |
| 3872 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3873 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3874 | } |
| 3875 | } |
| 3876 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3877 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3878 | case Primitive::kPrimLong: { |
| 3879 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3880 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3881 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3882 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3883 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3884 | } else { |
| 3885 | DCHECK(value.IsConstant()) << value; |
| 3886 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3887 | __ jmp(slow_path->GetEntryLabel()); |
| 3888 | } |
| 3889 | } |
| 3890 | break; |
| 3891 | } |
| 3892 | default: |
| 3893 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3894 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3897 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3898 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3899 | |
| 3900 | LocationSummary* locations = |
| 3901 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3902 | |
| 3903 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3904 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3905 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3906 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3907 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3908 | // The shift count needs to be in CL or a constant. |
| 3909 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3910 | locations->SetOut(Location::SameAsFirstInput()); |
| 3911 | break; |
| 3912 | } |
| 3913 | default: |
| 3914 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3919 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3920 | |
| 3921 | LocationSummary* locations = op->GetLocations(); |
| 3922 | Location first = locations->InAt(0); |
| 3923 | Location second = locations->InAt(1); |
| 3924 | DCHECK(first.Equals(locations->Out())); |
| 3925 | |
| 3926 | switch (op->GetResultType()) { |
| 3927 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3928 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3929 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3930 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3931 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3932 | DCHECK_EQ(ECX, second_reg); |
| 3933 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3934 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3935 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3936 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3937 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3938 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3939 | } |
| 3940 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3941 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3942 | if (shift == 0) { |
| 3943 | return; |
| 3944 | } |
| 3945 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3946 | if (op->IsShl()) { |
| 3947 | __ shll(first_reg, imm); |
| 3948 | } else if (op->IsShr()) { |
| 3949 | __ sarl(first_reg, imm); |
| 3950 | } else { |
| 3951 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3952 | } |
| 3953 | } |
| 3954 | break; |
| 3955 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3956 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3957 | if (second.IsRegister()) { |
| 3958 | Register second_reg = second.AsRegister<Register>(); |
| 3959 | DCHECK_EQ(ECX, second_reg); |
| 3960 | if (op->IsShl()) { |
| 3961 | GenerateShlLong(first, second_reg); |
| 3962 | } else if (op->IsShr()) { |
| 3963 | GenerateShrLong(first, second_reg); |
| 3964 | } else { |
| 3965 | GenerateUShrLong(first, second_reg); |
| 3966 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3967 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3968 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3969 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3970 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3971 | if (shift != 0) { |
| 3972 | if (op->IsShl()) { |
| 3973 | GenerateShlLong(first, shift); |
| 3974 | } else if (op->IsShr()) { |
| 3975 | GenerateShrLong(first, shift); |
| 3976 | } else { |
| 3977 | GenerateUShrLong(first, shift); |
| 3978 | } |
| 3979 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3980 | } |
| 3981 | break; |
| 3982 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3983 | default: |
| 3984 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3985 | } |
| 3986 | } |
| 3987 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3988 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3989 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3990 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3991 | if (shift == 1) { |
| 3992 | // This is just an addition. |
| 3993 | __ addl(low, low); |
| 3994 | __ adcl(high, high); |
| 3995 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3996 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3997 | codegen_->EmitParallelMoves( |
| 3998 | loc.ToLow(), |
| 3999 | loc.ToHigh(), |
| 4000 | Primitive::kPrimInt, |
| 4001 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4002 | loc.ToLow(), |
| 4003 | Primitive::kPrimInt); |
| 4004 | } else if (shift > 32) { |
| 4005 | // Low part becomes 0. High part is low part << (shift-32). |
| 4006 | __ movl(high, low); |
| 4007 | __ shll(high, Immediate(shift - 32)); |
| 4008 | __ xorl(low, low); |
| 4009 | } else { |
| 4010 | // Between 1 and 31. |
| 4011 | __ shld(high, low, Immediate(shift)); |
| 4012 | __ shll(low, Immediate(shift)); |
| 4013 | } |
| 4014 | } |
| 4015 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4016 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4017 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4018 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4019 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4020 | __ testl(shifter, Immediate(32)); |
| 4021 | __ j(kEqual, &done); |
| 4022 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4023 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4024 | __ Bind(&done); |
| 4025 | } |
| 4026 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4027 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4028 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4029 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4030 | if (shift == 32) { |
| 4031 | // Need to copy the sign. |
| 4032 | DCHECK_NE(low, high); |
| 4033 | __ movl(low, high); |
| 4034 | __ sarl(high, Immediate(31)); |
| 4035 | } else if (shift > 32) { |
| 4036 | DCHECK_NE(low, high); |
| 4037 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4038 | __ movl(low, high); |
| 4039 | __ sarl(high, Immediate(31)); |
| 4040 | __ sarl(low, Immediate(shift - 32)); |
| 4041 | } else { |
| 4042 | // Between 1 and 31. |
| 4043 | __ shrd(low, high, Immediate(shift)); |
| 4044 | __ sarl(high, Immediate(shift)); |
| 4045 | } |
| 4046 | } |
| 4047 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4048 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4049 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4050 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4051 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4052 | __ testl(shifter, Immediate(32)); |
| 4053 | __ j(kEqual, &done); |
| 4054 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4055 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4056 | __ Bind(&done); |
| 4057 | } |
| 4058 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4059 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4060 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4061 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4062 | if (shift == 32) { |
| 4063 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4064 | codegen_->EmitParallelMoves( |
| 4065 | loc.ToHigh(), |
| 4066 | loc.ToLow(), |
| 4067 | Primitive::kPrimInt, |
| 4068 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4069 | loc.ToHigh(), |
| 4070 | Primitive::kPrimInt); |
| 4071 | } else if (shift > 32) { |
| 4072 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4073 | __ movl(low, high); |
| 4074 | __ shrl(low, Immediate(shift - 32)); |
| 4075 | __ xorl(high, high); |
| 4076 | } else { |
| 4077 | // Between 1 and 31. |
| 4078 | __ shrd(low, high, Immediate(shift)); |
| 4079 | __ shrl(high, Immediate(shift)); |
| 4080 | } |
| 4081 | } |
| 4082 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4083 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4084 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4085 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4086 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4087 | __ testl(shifter, Immediate(32)); |
| 4088 | __ j(kEqual, &done); |
| 4089 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4090 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4091 | __ Bind(&done); |
| 4092 | } |
| 4093 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4094 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4095 | LocationSummary* locations = |
| 4096 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4097 | |
| 4098 | switch (ror->GetResultType()) { |
| 4099 | case Primitive::kPrimLong: |
| 4100 | // Add the temporary needed. |
| 4101 | locations->AddTemp(Location::RequiresRegister()); |
| 4102 | FALLTHROUGH_INTENDED; |
| 4103 | case Primitive::kPrimInt: |
| 4104 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4105 | // The shift count needs to be in CL (unless it is a constant). |
| 4106 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4107 | locations->SetOut(Location::SameAsFirstInput()); |
| 4108 | break; |
| 4109 | default: |
| 4110 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4111 | UNREACHABLE(); |
| 4112 | } |
| 4113 | } |
| 4114 | |
| 4115 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4116 | LocationSummary* locations = ror->GetLocations(); |
| 4117 | Location first = locations->InAt(0); |
| 4118 | Location second = locations->InAt(1); |
| 4119 | |
| 4120 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 4121 | Register first_reg = first.AsRegister<Register>(); |
| 4122 | if (second.IsRegister()) { |
| 4123 | Register second_reg = second.AsRegister<Register>(); |
| 4124 | __ rorl(first_reg, second_reg); |
| 4125 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4126 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4127 | __ rorl(first_reg, imm); |
| 4128 | } |
| 4129 | return; |
| 4130 | } |
| 4131 | |
| 4132 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 4133 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4134 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4135 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4136 | if (second.IsRegister()) { |
| 4137 | Register second_reg = second.AsRegister<Register>(); |
| 4138 | DCHECK_EQ(second_reg, ECX); |
| 4139 | __ movl(temp_reg, first_reg_hi); |
| 4140 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4141 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4142 | __ movl(temp_reg, first_reg_hi); |
| 4143 | __ testl(second_reg, Immediate(32)); |
| 4144 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4145 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4146 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4147 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4148 | if (shift_amt == 0) { |
| 4149 | // Already fine. |
| 4150 | return; |
| 4151 | } |
| 4152 | if (shift_amt == 32) { |
| 4153 | // Just swap. |
| 4154 | __ movl(temp_reg, first_reg_lo); |
| 4155 | __ movl(first_reg_lo, first_reg_hi); |
| 4156 | __ movl(first_reg_hi, temp_reg); |
| 4157 | return; |
| 4158 | } |
| 4159 | |
| 4160 | Immediate imm(shift_amt); |
| 4161 | // Save the constents of the low value. |
| 4162 | __ movl(temp_reg, first_reg_lo); |
| 4163 | |
| 4164 | // Shift right into low, feeding bits from high. |
| 4165 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4166 | |
| 4167 | // Shift right into high, feeding bits from the original low. |
| 4168 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4169 | |
| 4170 | // Swap if needed. |
| 4171 | if (shift_amt > 32) { |
| 4172 | __ movl(temp_reg, first_reg_lo); |
| 4173 | __ movl(first_reg_lo, first_reg_hi); |
| 4174 | __ movl(first_reg_hi, temp_reg); |
| 4175 | } |
| 4176 | } |
| 4177 | } |
| 4178 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4179 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4180 | HandleShift(shl); |
| 4181 | } |
| 4182 | |
| 4183 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4184 | HandleShift(shl); |
| 4185 | } |
| 4186 | |
| 4187 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4188 | HandleShift(shr); |
| 4189 | } |
| 4190 | |
| 4191 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4192 | HandleShift(shr); |
| 4193 | } |
| 4194 | |
| 4195 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4196 | HandleShift(ushr); |
| 4197 | } |
| 4198 | |
| 4199 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4200 | HandleShift(ushr); |
| 4201 | } |
| 4202 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4203 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4204 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4205 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4206 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4207 | if (instruction->IsStringAlloc()) { |
| 4208 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4209 | } else { |
| 4210 | InvokeRuntimeCallingConvention calling_convention; |
| 4211 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4212 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4213 | } |
| 4214 | |
| 4215 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4216 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4217 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4218 | if (instruction->IsStringAlloc()) { |
| 4219 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4220 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4221 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4222 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4223 | __ call(Address(temp, code_offset.Int32Value())); |
| 4224 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4225 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4226 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4227 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4228 | DCHECK(!codegen_->IsLeafMethod()); |
| 4229 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4230 | } |
| 4231 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4232 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4233 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4234 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4235 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4236 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4237 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4238 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4242 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4243 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4244 | QuickEntrypointEnum entrypoint = |
| 4245 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4246 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4247 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4248 | DCHECK(!codegen_->IsLeafMethod()); |
| 4249 | } |
| 4250 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4251 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4252 | LocationSummary* locations = |
| 4253 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4254 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4255 | if (location.IsStackSlot()) { |
| 4256 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4257 | } else if (location.IsDoubleStackSlot()) { |
| 4258 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4259 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4260 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4261 | } |
| 4262 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4263 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4264 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4265 | } |
| 4266 | |
| 4267 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4268 | LocationSummary* locations = |
| 4269 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4270 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4271 | } |
| 4272 | |
| 4273 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4274 | } |
| 4275 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4276 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4277 | LocationSummary* locations = |
| 4278 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4279 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4280 | locations->SetOut(Location::RequiresRegister()); |
| 4281 | } |
| 4282 | |
| 4283 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4284 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4285 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4286 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4287 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4288 | __ movl(locations->Out().AsRegister<Register>(), |
| 4289 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4290 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4291 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4292 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4293 | __ movl(locations->Out().AsRegister<Register>(), |
| 4294 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4295 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4296 | // temp = temp->GetImtEntryAt(method_offset); |
| 4297 | __ movl(locations->Out().AsRegister<Register>(), |
| 4298 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4299 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4300 | } |
| 4301 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4302 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4303 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4304 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4306 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4307 | } |
| 4308 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4309 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4310 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4311 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4312 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4313 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4314 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4315 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4316 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4317 | break; |
| 4318 | |
| 4319 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4320 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4321 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4322 | break; |
| 4323 | |
| 4324 | default: |
| 4325 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4326 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4327 | } |
| 4328 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4329 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4330 | LocationSummary* locations = |
| 4331 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4332 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4333 | locations->SetOut(Location::SameAsFirstInput()); |
| 4334 | } |
| 4335 | |
| 4336 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4337 | LocationSummary* locations = bool_not->GetLocations(); |
| 4338 | Location in = locations->InAt(0); |
| 4339 | Location out = locations->Out(); |
| 4340 | DCHECK(in.Equals(out)); |
| 4341 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4342 | } |
| 4343 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4344 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4345 | LocationSummary* locations = |
| 4346 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4347 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4348 | case Primitive::kPrimBoolean: |
| 4349 | case Primitive::kPrimByte: |
| 4350 | case Primitive::kPrimShort: |
| 4351 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4352 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4353 | case Primitive::kPrimLong: { |
| 4354 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4355 | locations->SetInAt(1, Location::Any()); |
| 4356 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4357 | break; |
| 4358 | } |
| 4359 | case Primitive::kPrimFloat: |
| 4360 | case Primitive::kPrimDouble: { |
| 4361 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4362 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4363 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4364 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4365 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4366 | } else { |
| 4367 | locations->SetInAt(1, Location::Any()); |
| 4368 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4369 | locations->SetOut(Location::RequiresRegister()); |
| 4370 | break; |
| 4371 | } |
| 4372 | default: |
| 4373 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4374 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4378 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4379 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4380 | Location left = locations->InAt(0); |
| 4381 | Location right = locations->InAt(1); |
| 4382 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4383 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4384 | Condition less_cond = kLess; |
| 4385 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4386 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4387 | case Primitive::kPrimBoolean: |
| 4388 | case Primitive::kPrimByte: |
| 4389 | case Primitive::kPrimShort: |
| 4390 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4391 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4392 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4393 | break; |
| 4394 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4395 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4396 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4397 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4398 | int32_t val_low = 0; |
| 4399 | int32_t val_high = 0; |
| 4400 | bool right_is_const = false; |
| 4401 | |
| 4402 | if (right.IsConstant()) { |
| 4403 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4404 | right_is_const = true; |
| 4405 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4406 | val_low = Low32Bits(val); |
| 4407 | val_high = High32Bits(val); |
| 4408 | } |
| 4409 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4410 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4411 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4412 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4413 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4414 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4415 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4416 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4417 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4418 | __ j(kLess, &less); // Signed compare. |
| 4419 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4420 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4421 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4422 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4423 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4424 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4425 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4426 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4427 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4428 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4429 | break; |
| 4430 | } |
| 4431 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4432 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4433 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4434 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4435 | break; |
| 4436 | } |
| 4437 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4438 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4439 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4440 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4441 | break; |
| 4442 | } |
| 4443 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4444 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4445 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4446 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4447 | __ movl(out, Immediate(0)); |
| 4448 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4449 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4450 | |
| 4451 | __ Bind(&greater); |
| 4452 | __ movl(out, Immediate(1)); |
| 4453 | __ jmp(&done); |
| 4454 | |
| 4455 | __ Bind(&less); |
| 4456 | __ movl(out, Immediate(-1)); |
| 4457 | |
| 4458 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4459 | } |
| 4460 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4461 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4462 | LocationSummary* locations = |
| 4463 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4464 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4465 | locations->SetInAt(i, Location::Any()); |
| 4466 | } |
| 4467 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4468 | } |
| 4469 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4470 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4471 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4472 | } |
| 4473 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4474 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4475 | /* |
| 4476 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4477 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4478 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4479 | */ |
| 4480 | switch (kind) { |
| 4481 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4482 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4483 | break; |
| 4484 | } |
| 4485 | case MemBarrierKind::kAnyStore: |
| 4486 | case MemBarrierKind::kLoadAny: |
| 4487 | case MemBarrierKind::kStoreStore: { |
| 4488 | // nop |
| 4489 | break; |
| 4490 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4491 | case MemBarrierKind::kNTStoreStore: |
| 4492 | // Non-Temporal Store/Store needs an explicit fence. |
| 4493 | MemoryFence(/* non-temporal */ true); |
| 4494 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4495 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4496 | } |
| 4497 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4498 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4499 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4500 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4501 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4502 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4503 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4504 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4505 | Register temp) { |
| 4506 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4507 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4508 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4509 | return location.AsRegister<Register>(); |
| 4510 | } |
| 4511 | // For intrinsics we allow any location, so it may be on the stack. |
| 4512 | if (!location.IsRegister()) { |
| 4513 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4514 | return temp; |
| 4515 | } |
| 4516 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4517 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4518 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4519 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4520 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4521 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4522 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4523 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4524 | __ movl(temp, Address(ESP, stack_offset)); |
| 4525 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4526 | } |
| 4527 | return location.AsRegister<Register>(); |
| 4528 | } |
| 4529 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4530 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4531 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4532 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4533 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4534 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4535 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4536 | uint32_t offset = |
| 4537 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4538 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4540 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4541 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4542 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4543 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4544 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4545 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4546 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4547 | temp.AsRegister<Register>()); |
| 4548 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 4549 | RecordBootMethodPatch(invoke); |
| 4550 | break; |
| 4551 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4552 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4553 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4554 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4555 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4556 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4557 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4558 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4559 | // Bind a new fixup label at the end of the "movl" insn. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4560 | __ Bind(NewMethodBssEntryPatch( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4561 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4562 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()))); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4563 | break; |
| 4564 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4565 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4566 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4567 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4568 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | switch (invoke->GetCodePtrLocation()) { |
| 4572 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4573 | __ call(GetFrameEntryLabel()); |
| 4574 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4575 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4576 | // (callee_method + offset_of_quick_compiled_code)() |
| 4577 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4578 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4579 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4580 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4581 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4582 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4583 | |
| 4584 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4585 | } |
| 4586 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4587 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4588 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4589 | Register temp = temp_in.AsRegister<Register>(); |
| 4590 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4591 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4592 | |
| 4593 | // Use the calling convention instead of the location of the receiver, as |
| 4594 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4595 | // slow path, the arguments have been moved to the right place, so here we are |
| 4596 | // guaranteed that the receiver is the first register of the calling convention. |
| 4597 | InvokeDexCallingConvention calling_convention; |
| 4598 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4599 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4600 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4601 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4602 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4603 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4604 | // emit a read barrier for the previous class reference load. |
| 4605 | // However this is not required in practice, as this is an |
| 4606 | // intermediate/temporary reference and because the current |
| 4607 | // concurrent copying collector keeps the from-space memory |
| 4608 | // intact/accessible until the end of the marking phase (the |
| 4609 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4610 | __ MaybeUnpoisonHeapReference(temp); |
| 4611 | // temp = temp->GetMethodAt(method_offset); |
| 4612 | __ movl(temp, Address(temp, method_offset)); |
| 4613 | // call temp->GetEntryPoint(); |
| 4614 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4615 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4616 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4619 | void CodeGeneratorX86::RecordBootMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 4620 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4621 | HX86ComputeBaseMethodAddress* address = |
| 4622 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 4623 | boot_image_method_patches_.emplace_back(address, |
| 4624 | *invoke->GetTargetMethod().dex_file, |
| 4625 | invoke->GetTargetMethod().dex_method_index); |
| 4626 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4627 | } |
| 4628 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4629 | Label* CodeGeneratorX86::NewMethodBssEntryPatch( |
| 4630 | HX86ComputeBaseMethodAddress* method_address, |
| 4631 | MethodReference target_method) { |
| 4632 | // Add the patch entry and bind its label at the end of the instruction. |
| 4633 | method_bss_entry_patches_.emplace_back(method_address, |
| 4634 | *target_method.dex_file, |
| 4635 | target_method.dex_method_index); |
| 4636 | return &method_bss_entry_patches_.back().label; |
| 4637 | } |
| 4638 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4639 | void CodeGeneratorX86::RecordBootTypePatch(HLoadClass* load_class) { |
Vladimir Marko | 00916b9 | 2017-05-17 17:45:45 +0100 | [diff] [blame] | 4640 | HX86ComputeBaseMethodAddress* address = load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4641 | boot_image_type_patches_.emplace_back(address, |
| 4642 | load_class->GetDexFile(), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4643 | load_class->GetTypeIndex().index_); |
| 4644 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4645 | } |
| 4646 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4647 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4648 | HX86ComputeBaseMethodAddress* address = |
| 4649 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4650 | type_bss_entry_patches_.emplace_back( |
| 4651 | address, load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4652 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4653 | } |
| 4654 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4655 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4656 | HX86ComputeBaseMethodAddress* address = load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4657 | string_patches_.emplace_back(address, |
| 4658 | load_string->GetDexFile(), |
| 4659 | load_string->GetStringIndex().index_); |
| 4660 | __ Bind(&string_patches_.back().label); |
| 4661 | } |
| 4662 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4663 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4664 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4665 | HX86ComputeBaseMethodAddress* address = |
| 4666 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 4667 | string_bss_entry_patches_.emplace_back( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4668 | address, load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 4669 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4670 | } |
| 4671 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4672 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4673 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4674 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4675 | |
| 4676 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4677 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4678 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4679 | ArenaVector<LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4680 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4681 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4682 | linker_patches->push_back(Factory( |
| 4683 | literal_offset, &info.dex_file, GetMethodAddressOffset(info.method_address), info.index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4684 | } |
| 4685 | } |
| 4686 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4687 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4688 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4689 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4690 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4691 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4692 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4693 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 4694 | string_patches_.size() + |
| 4695 | string_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4696 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4697 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4698 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(boot_image_method_patches_, |
| 4699 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4700 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(boot_image_type_patches_, |
| 4701 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4702 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4703 | } else { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4704 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4705 | DCHECK(boot_image_type_patches_.empty()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 4706 | EmitPcRelativeLinkerPatches<LinkerPatch::StringInternTablePatch>(string_patches_, |
| 4707 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4708 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4709 | EmitPcRelativeLinkerPatches<LinkerPatch::MethodBssEntryPatch>(method_bss_entry_patches_, |
| 4710 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4711 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4712 | linker_patches); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 4713 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_bss_entry_patches_, |
| 4714 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4715 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4718 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4719 | Register card, |
| 4720 | Register object, |
| 4721 | Register value, |
| 4722 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4723 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4724 | if (value_can_be_null) { |
| 4725 | __ testl(value, value); |
| 4726 | __ j(kEqual, &is_null); |
| 4727 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4728 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4729 | __ movl(temp, object); |
| 4730 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4731 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4732 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4733 | if (value_can_be_null) { |
| 4734 | __ Bind(&is_null); |
| 4735 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4736 | } |
| 4737 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4738 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4739 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4740 | |
| 4741 | bool object_field_get_with_read_barrier = |
| 4742 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4743 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4744 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4745 | kEmitCompilerReadBarrier ? |
| 4746 | LocationSummary::kCallOnSlowPath : |
| 4747 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4748 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4749 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4750 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4751 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4752 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4753 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4754 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4755 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4756 | // The output overlaps in case of long: we don't want the low move |
| 4757 | // to overwrite the object's location. Likewise, in the case of |
| 4758 | // an object field get with read barriers enabled, we do not want |
| 4759 | // the move to overwrite the object's location, as we need it to emit |
| 4760 | // the read barrier. |
| 4761 | locations->SetOut( |
| 4762 | Location::RequiresRegister(), |
| 4763 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4764 | Location::kOutputOverlap : |
| 4765 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4766 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4767 | |
| 4768 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4769 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4770 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4771 | // load the temp into the XMM and then copy the XMM into the |
| 4772 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4773 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4774 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4775 | } |
| 4776 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4777 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4778 | const FieldInfo& field_info) { |
| 4779 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4780 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4781 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4782 | Location base_loc = locations->InAt(0); |
| 4783 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4784 | Location out = locations->Out(); |
| 4785 | bool is_volatile = field_info.IsVolatile(); |
| 4786 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4787 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4788 | |
| 4789 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4790 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4791 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4792 | break; |
| 4793 | } |
| 4794 | |
| 4795 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4796 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4797 | break; |
| 4798 | } |
| 4799 | |
| 4800 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4801 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4802 | break; |
| 4803 | } |
| 4804 | |
| 4805 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4806 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4807 | break; |
| 4808 | } |
| 4809 | |
| 4810 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4811 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4812 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4813 | |
| 4814 | case Primitive::kPrimNot: { |
| 4815 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4816 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4817 | // Note that a potential implicit null check is handled in this |
| 4818 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4819 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4820 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4821 | if (is_volatile) { |
| 4822 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4823 | } |
| 4824 | } else { |
| 4825 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4826 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4827 | if (is_volatile) { |
| 4828 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4829 | } |
| 4830 | // If read barriers are enabled, emit read barriers other than |
| 4831 | // Baker's using a slow path (and also unpoison the loaded |
| 4832 | // reference, if heap poisoning is enabled). |
| 4833 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4834 | } |
| 4835 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4836 | } |
| 4837 | |
| 4838 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4839 | if (is_volatile) { |
| 4840 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4841 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4842 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4843 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4844 | __ psrlq(temp, Immediate(32)); |
| 4845 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4846 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4847 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4848 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4849 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4850 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4851 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4852 | break; |
| 4853 | } |
| 4854 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4855 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4856 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4857 | break; |
| 4858 | } |
| 4859 | |
| 4860 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4861 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4862 | break; |
| 4863 | } |
| 4864 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4865 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4866 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4867 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4868 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4869 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4870 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4871 | // Potential implicit null checks, in the case of reference or |
| 4872 | // long fields, are handled in the previous switch statement. |
| 4873 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4874 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4875 | } |
| 4876 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4877 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4878 | if (field_type == Primitive::kPrimNot) { |
| 4879 | // Memory barriers, in the case of references, are also handled |
| 4880 | // in the previous switch statement. |
| 4881 | } else { |
| 4882 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4883 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4884 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4885 | } |
| 4886 | |
| 4887 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4888 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4889 | |
| 4890 | LocationSummary* locations = |
| 4891 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4892 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4893 | bool is_volatile = field_info.IsVolatile(); |
| 4894 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4895 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4896 | || (field_type == Primitive::kPrimByte); |
| 4897 | |
| 4898 | // The register allocator does not support multiple |
| 4899 | // inputs that die at entry with one in a specific register. |
| 4900 | if (is_byte_type) { |
| 4901 | // Ensure the value is in a byte register. |
| 4902 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4903 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4904 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4905 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4906 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4907 | } else { |
| 4908 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4909 | } |
| 4910 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4911 | // 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] | 4912 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4913 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4914 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4915 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4916 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4917 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4918 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4919 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4920 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4921 | } else { |
| 4922 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4923 | |
| 4924 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4925 | // Temporary registers for the write barrier. |
| 4926 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4927 | // Ensure the card is in a byte register. |
| 4928 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4929 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4930 | } |
| 4931 | } |
| 4932 | |
| 4933 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4934 | const FieldInfo& field_info, |
| 4935 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4936 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4937 | |
| 4938 | LocationSummary* locations = instruction->GetLocations(); |
| 4939 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4940 | Location value = locations->InAt(1); |
| 4941 | bool is_volatile = field_info.IsVolatile(); |
| 4942 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4943 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4944 | bool needs_write_barrier = |
| 4945 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4946 | |
| 4947 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4948 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4949 | } |
| 4950 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4951 | bool maybe_record_implicit_null_check_done = false; |
| 4952 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4953 | switch (field_type) { |
| 4954 | case Primitive::kPrimBoolean: |
| 4955 | case Primitive::kPrimByte: { |
| 4956 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4957 | break; |
| 4958 | } |
| 4959 | |
| 4960 | case Primitive::kPrimShort: |
| 4961 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4962 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4963 | __ movw(Address(base, offset), |
| 4964 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4965 | } else { |
| 4966 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4967 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4968 | break; |
| 4969 | } |
| 4970 | |
| 4971 | case Primitive::kPrimInt: |
| 4972 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4973 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4974 | // Note that in the case where `value` is a null reference, |
| 4975 | // we do not enter this block, as the reference does not |
| 4976 | // need poisoning. |
| 4977 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4978 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4979 | __ movl(temp, value.AsRegister<Register>()); |
| 4980 | __ PoisonHeapReference(temp); |
| 4981 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4982 | } else if (value.IsConstant()) { |
| 4983 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4984 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4985 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4986 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4987 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4988 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4989 | break; |
| 4990 | } |
| 4991 | |
| 4992 | case Primitive::kPrimLong: { |
| 4993 | if (is_volatile) { |
| 4994 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4995 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4996 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4997 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4998 | __ punpckldq(temp1, temp2); |
| 4999 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5000 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5001 | } else if (value.IsConstant()) { |
| 5002 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5003 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5004 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5005 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5006 | } else { |
| 5007 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5008 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5009 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5010 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5011 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5012 | break; |
| 5013 | } |
| 5014 | |
| 5015 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5016 | if (value.IsConstant()) { |
| 5017 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5018 | __ movl(Address(base, offset), Immediate(v)); |
| 5019 | } else { |
| 5020 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5021 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5022 | break; |
| 5023 | } |
| 5024 | |
| 5025 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5026 | if (value.IsConstant()) { |
| 5027 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5028 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5029 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5030 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5031 | maybe_record_implicit_null_check_done = true; |
| 5032 | } else { |
| 5033 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5034 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5035 | break; |
| 5036 | } |
| 5037 | |
| 5038 | case Primitive::kPrimVoid: |
| 5039 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5040 | UNREACHABLE(); |
| 5041 | } |
| 5042 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5043 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5044 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5045 | } |
| 5046 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5047 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5048 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5049 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5050 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5053 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5054 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5055 | } |
| 5056 | } |
| 5057 | |
| 5058 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5059 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5060 | } |
| 5061 | |
| 5062 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5063 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5064 | } |
| 5065 | |
| 5066 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5067 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5068 | } |
| 5069 | |
| 5070 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5071 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5075 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5076 | } |
| 5077 | |
| 5078 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5079 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5080 | } |
| 5081 | |
| 5082 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5083 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5084 | } |
| 5085 | |
| 5086 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5087 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5088 | } |
| 5089 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5090 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5091 | HUnresolvedInstanceFieldGet* instruction) { |
| 5092 | FieldAccessCallingConventionX86 calling_convention; |
| 5093 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5094 | instruction, instruction->GetFieldType(), calling_convention); |
| 5095 | } |
| 5096 | |
| 5097 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5098 | HUnresolvedInstanceFieldGet* instruction) { |
| 5099 | FieldAccessCallingConventionX86 calling_convention; |
| 5100 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5101 | instruction->GetFieldType(), |
| 5102 | instruction->GetFieldIndex(), |
| 5103 | instruction->GetDexPc(), |
| 5104 | calling_convention); |
| 5105 | } |
| 5106 | |
| 5107 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5108 | HUnresolvedInstanceFieldSet* instruction) { |
| 5109 | FieldAccessCallingConventionX86 calling_convention; |
| 5110 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5111 | instruction, instruction->GetFieldType(), calling_convention); |
| 5112 | } |
| 5113 | |
| 5114 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5115 | HUnresolvedInstanceFieldSet* instruction) { |
| 5116 | FieldAccessCallingConventionX86 calling_convention; |
| 5117 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5118 | instruction->GetFieldType(), |
| 5119 | instruction->GetFieldIndex(), |
| 5120 | instruction->GetDexPc(), |
| 5121 | calling_convention); |
| 5122 | } |
| 5123 | |
| 5124 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5125 | HUnresolvedStaticFieldGet* instruction) { |
| 5126 | FieldAccessCallingConventionX86 calling_convention; |
| 5127 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5128 | instruction, instruction->GetFieldType(), calling_convention); |
| 5129 | } |
| 5130 | |
| 5131 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5132 | HUnresolvedStaticFieldGet* instruction) { |
| 5133 | FieldAccessCallingConventionX86 calling_convention; |
| 5134 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5135 | instruction->GetFieldType(), |
| 5136 | instruction->GetFieldIndex(), |
| 5137 | instruction->GetDexPc(), |
| 5138 | calling_convention); |
| 5139 | } |
| 5140 | |
| 5141 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5142 | HUnresolvedStaticFieldSet* instruction) { |
| 5143 | FieldAccessCallingConventionX86 calling_convention; |
| 5144 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5145 | instruction, instruction->GetFieldType(), calling_convention); |
| 5146 | } |
| 5147 | |
| 5148 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5149 | HUnresolvedStaticFieldSet* instruction) { |
| 5150 | FieldAccessCallingConventionX86 calling_convention; |
| 5151 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5152 | instruction->GetFieldType(), |
| 5153 | instruction->GetFieldIndex(), |
| 5154 | instruction->GetDexPc(), |
| 5155 | calling_convention); |
| 5156 | } |
| 5157 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5158 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5159 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5160 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5161 | ? Location::RequiresRegister() |
| 5162 | : Location::Any(); |
| 5163 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5164 | } |
| 5165 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5166 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5167 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5168 | return; |
| 5169 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5170 | LocationSummary* locations = instruction->GetLocations(); |
| 5171 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5172 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5173 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5174 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5175 | } |
| 5176 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5177 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5178 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5179 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5180 | |
| 5181 | LocationSummary* locations = instruction->GetLocations(); |
| 5182 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5183 | |
| 5184 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5185 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5186 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5187 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5188 | } else { |
| 5189 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5190 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5191 | __ jmp(slow_path->GetEntryLabel()); |
| 5192 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5193 | } |
| 5194 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5195 | } |
| 5196 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5197 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5198 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5199 | } |
| 5200 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5201 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5202 | bool object_array_get_with_read_barrier = |
| 5203 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5204 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5205 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5206 | object_array_get_with_read_barrier ? |
| 5207 | LocationSummary::kCallOnSlowPath : |
| 5208 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5209 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5210 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5211 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5212 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5213 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5214 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5215 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5216 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5217 | // The output overlaps in case of long: we don't want the low move |
| 5218 | // to overwrite the array's location. Likewise, in the case of an |
| 5219 | // object array get with read barriers enabled, we do not want the |
| 5220 | // move to overwrite the array's location, as we need it to emit |
| 5221 | // the read barrier. |
| 5222 | locations->SetOut( |
| 5223 | Location::RequiresRegister(), |
| 5224 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5225 | Location::kOutputOverlap : |
| 5226 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5227 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5228 | } |
| 5229 | |
| 5230 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5231 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5232 | Location obj_loc = locations->InAt(0); |
| 5233 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5234 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5235 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5236 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5237 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5238 | Primitive::Type type = instruction->GetType(); |
| 5239 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5240 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5241 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5242 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5243 | break; |
| 5244 | } |
| 5245 | |
| 5246 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5247 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5248 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5249 | break; |
| 5250 | } |
| 5251 | |
| 5252 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5253 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5254 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5255 | break; |
| 5256 | } |
| 5257 | |
| 5258 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5259 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5260 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5261 | // Branch cases into compressed and uncompressed for each index's type. |
| 5262 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5263 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5264 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5265 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5266 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5267 | "Expecting 0=compressed, 1=uncompressed"); |
| 5268 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5269 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5270 | __ jmp(&done); |
| 5271 | __ Bind(¬_compressed); |
| 5272 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5273 | __ Bind(&done); |
| 5274 | } else { |
| 5275 | // Common case for charAt of array of char or when string compression's |
| 5276 | // feature is turned off. |
| 5277 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5278 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5279 | break; |
| 5280 | } |
| 5281 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5282 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5283 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5284 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5285 | break; |
| 5286 | } |
| 5287 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5288 | case Primitive::kPrimNot: { |
| 5289 | static_assert( |
| 5290 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5291 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5292 | // /* HeapReference<Object> */ out = |
| 5293 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5294 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5295 | // Note that a potential implicit null check is handled in this |
| 5296 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5297 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5298 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5299 | } else { |
| 5300 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5301 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5302 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5303 | // If read barriers are enabled, emit read barriers other than |
| 5304 | // Baker's using a slow path (and also unpoison the loaded |
| 5305 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5306 | if (index.IsConstant()) { |
| 5307 | uint32_t offset = |
| 5308 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5309 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5310 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5311 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5312 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5313 | } |
| 5314 | } |
| 5315 | break; |
| 5316 | } |
| 5317 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5318 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5319 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5320 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5321 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5322 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5323 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5324 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5325 | break; |
| 5326 | } |
| 5327 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5328 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5329 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5330 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5331 | break; |
| 5332 | } |
| 5333 | |
| 5334 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5335 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5336 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5337 | break; |
| 5338 | } |
| 5339 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5340 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5341 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5342 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5343 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5344 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5345 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5346 | // Potential implicit null checks, in the case of reference or |
| 5347 | // long arrays, are handled in the previous switch statement. |
| 5348 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5349 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5350 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5351 | } |
| 5352 | |
| 5353 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5354 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5355 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5356 | bool needs_write_barrier = |
| 5357 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5358 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5359 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5360 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5361 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5362 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5363 | LocationSummary::kCallOnSlowPath : |
| 5364 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5365 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5366 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5367 | || (value_type == Primitive::kPrimByte); |
| 5368 | // We need the inputs to be different than the output in case of long operation. |
| 5369 | // In case of a byte operation, the register allocator does not support multiple |
| 5370 | // inputs that die at entry with one in a specific register. |
| 5371 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5372 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5373 | if (is_byte_type) { |
| 5374 | // Ensure the value is in a byte register. |
| 5375 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5376 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5377 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5378 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5379 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5380 | } |
| 5381 | if (needs_write_barrier) { |
| 5382 | // Temporary registers for the write barrier. |
| 5383 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5384 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5385 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5386 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5390 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5391 | Location array_loc = locations->InAt(0); |
| 5392 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5393 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5394 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5395 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5396 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5397 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5398 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5399 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5400 | bool needs_write_barrier = |
| 5401 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5402 | |
| 5403 | switch (value_type) { |
| 5404 | case Primitive::kPrimBoolean: |
| 5405 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5406 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5407 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5408 | if (value.IsRegister()) { |
| 5409 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5410 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5411 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5412 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5413 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5414 | break; |
| 5415 | } |
| 5416 | |
| 5417 | case Primitive::kPrimShort: |
| 5418 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5419 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5420 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5421 | if (value.IsRegister()) { |
| 5422 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5423 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5424 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5425 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5426 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5427 | break; |
| 5428 | } |
| 5429 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5430 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5431 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5432 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5433 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5434 | if (!value.IsRegister()) { |
| 5435 | // Just setting null. |
| 5436 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5437 | DCHECK(value.IsConstant()) << value; |
| 5438 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5439 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5440 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5441 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5442 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5443 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5444 | |
| 5445 | DCHECK(needs_write_barrier); |
| 5446 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5447 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5448 | // short when Baker read barriers are enabled. |
| 5449 | Label done; |
| 5450 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5451 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5452 | Location temp_loc = locations->GetTemp(0); |
| 5453 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5454 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5455 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5456 | codegen_->AddSlowPath(slow_path); |
| 5457 | if (instruction->GetValueCanBeNull()) { |
| 5458 | __ testl(register_value, register_value); |
| 5459 | __ j(kNotEqual, ¬_null); |
| 5460 | __ movl(address, Immediate(0)); |
| 5461 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5462 | __ jmp(&done); |
| 5463 | __ Bind(¬_null); |
| 5464 | } |
| 5465 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5466 | // Note that when Baker read barriers are enabled, the type |
| 5467 | // checks are performed without read barriers. This is fine, |
| 5468 | // even in the case where a class object is in the from-space |
| 5469 | // after the flip, as a comparison involving such a type would |
| 5470 | // not produce a false positive; it may of course produce a |
| 5471 | // false negative, in which case we would take the ArraySet |
| 5472 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5473 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5474 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5475 | __ movl(temp, Address(array, class_offset)); |
| 5476 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5477 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5478 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5479 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5480 | __ movl(temp, Address(temp, component_offset)); |
| 5481 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5482 | // nor the object reference in `register_value->klass`, as |
| 5483 | // we are comparing two poisoned references. |
| 5484 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5485 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5486 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5487 | __ j(kEqual, &do_put); |
| 5488 | // If heap poisoning is enabled, the `temp` reference has |
| 5489 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5490 | __ MaybeUnpoisonHeapReference(temp); |
| 5491 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5492 | // If heap poisoning is enabled, no need to unpoison the |
| 5493 | // heap reference loaded below, as it is only used for a |
| 5494 | // comparison with null. |
| 5495 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5496 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5497 | __ Bind(&do_put); |
| 5498 | } else { |
| 5499 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5500 | } |
| 5501 | } |
| 5502 | |
| 5503 | if (kPoisonHeapReferences) { |
| 5504 | __ movl(temp, register_value); |
| 5505 | __ PoisonHeapReference(temp); |
| 5506 | __ movl(address, temp); |
| 5507 | } else { |
| 5508 | __ movl(address, register_value); |
| 5509 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5510 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5511 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5512 | } |
| 5513 | |
| 5514 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5515 | codegen_->MarkGCCard( |
| 5516 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5517 | __ Bind(&done); |
| 5518 | |
| 5519 | if (slow_path != nullptr) { |
| 5520 | __ Bind(slow_path->GetExitLabel()); |
| 5521 | } |
| 5522 | |
| 5523 | break; |
| 5524 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5525 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5526 | case Primitive::kPrimInt: { |
| 5527 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5528 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5529 | if (value.IsRegister()) { |
| 5530 | __ movl(address, value.AsRegister<Register>()); |
| 5531 | } else { |
| 5532 | DCHECK(value.IsConstant()) << value; |
| 5533 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5534 | __ movl(address, Immediate(v)); |
| 5535 | } |
| 5536 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5537 | break; |
| 5538 | } |
| 5539 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5540 | case Primitive::kPrimLong: { |
| 5541 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5542 | if (value.IsRegisterPair()) { |
| 5543 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5544 | value.AsRegisterPairLow<Register>()); |
| 5545 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5546 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5547 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5548 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5549 | DCHECK(value.IsConstant()); |
| 5550 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5551 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5552 | Immediate(Low32Bits(val))); |
| 5553 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5554 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5555 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5556 | } |
| 5557 | break; |
| 5558 | } |
| 5559 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5560 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5561 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5562 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5563 | if (value.IsFpuRegister()) { |
| 5564 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5565 | } else { |
| 5566 | DCHECK(value.IsConstant()); |
| 5567 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5568 | __ movl(address, Immediate(v)); |
| 5569 | } |
| 5570 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5571 | break; |
| 5572 | } |
| 5573 | |
| 5574 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5575 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5576 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5577 | if (value.IsFpuRegister()) { |
| 5578 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5579 | } else { |
| 5580 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5581 | Address address_hi = |
| 5582 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5583 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5584 | __ movl(address, Immediate(Low32Bits(v))); |
| 5585 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5586 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5587 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5588 | break; |
| 5589 | } |
| 5590 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5591 | case Primitive::kPrimVoid: |
| 5592 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5593 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5594 | } |
| 5595 | } |
| 5596 | |
| 5597 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5598 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5599 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5600 | if (!instruction->IsEmittedAtUseSite()) { |
| 5601 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5602 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5606 | if (instruction->IsEmittedAtUseSite()) { |
| 5607 | return; |
| 5608 | } |
| 5609 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5610 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5611 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5612 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5613 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5614 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5615 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5616 | // Mask out most significant bit in case the array is String's array of char. |
| 5617 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5618 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5619 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5623 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5624 | InvokeRuntimeCallingConvention calling_convention; |
| 5625 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5626 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5627 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5628 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5629 | HInstruction* length = instruction->InputAt(1); |
| 5630 | if (!length->IsEmittedAtUseSite()) { |
| 5631 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5632 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5633 | // Need register to see array's length. |
| 5634 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5635 | locations->AddTemp(Location::RequiresRegister()); |
| 5636 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5640 | const bool is_string_compressed_char_at = |
| 5641 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5642 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5643 | Location index_loc = locations->InAt(0); |
| 5644 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5645 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5646 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5647 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5648 | if (length_loc.IsConstant()) { |
| 5649 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5650 | if (index_loc.IsConstant()) { |
| 5651 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5652 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5653 | if (index < 0 || index >= length) { |
| 5654 | codegen_->AddSlowPath(slow_path); |
| 5655 | __ jmp(slow_path->GetEntryLabel()); |
| 5656 | } else { |
| 5657 | // Some optimization after BCE may have generated this, and we should not |
| 5658 | // generate a bounds check if it is a valid range. |
| 5659 | } |
| 5660 | return; |
| 5661 | } |
| 5662 | |
| 5663 | // We have to reverse the jump condition because the length is the constant. |
| 5664 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5665 | __ cmpl(index_reg, Immediate(length)); |
| 5666 | codegen_->AddSlowPath(slow_path); |
| 5667 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5668 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5669 | HInstruction* array_length = instruction->InputAt(1); |
| 5670 | if (array_length->IsEmittedAtUseSite()) { |
| 5671 | // Address the length field in the array. |
| 5672 | DCHECK(array_length->IsArrayLength()); |
| 5673 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5674 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5675 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5676 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5677 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5678 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5679 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5680 | __ movl(length_reg, array_len); |
| 5681 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5682 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5683 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5684 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5685 | // Checking bounds for general case: |
| 5686 | // Array of char or string's array with feature compression off. |
| 5687 | if (index_loc.IsConstant()) { |
| 5688 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5689 | __ cmpl(array_len, Immediate(value)); |
| 5690 | } else { |
| 5691 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5692 | } |
| 5693 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5694 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5695 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5696 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5697 | } |
| 5698 | codegen_->AddSlowPath(slow_path); |
| 5699 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5700 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5701 | } |
| 5702 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5703 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5704 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5705 | } |
| 5706 | |
| 5707 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5708 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5709 | } |
| 5710 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5711 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5712 | LocationSummary* locations = |
| 5713 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5714 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5715 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5716 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5717 | locations->SetCustomSlowPathCallerSaves( |
| 5718 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5719 | } |
| 5720 | |
| 5721 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5722 | HBasicBlock* block = instruction->GetBlock(); |
| 5723 | if (block->GetLoopInformation() != nullptr) { |
| 5724 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5725 | // The back edge will generate the suspend check. |
| 5726 | return; |
| 5727 | } |
| 5728 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5729 | // The goto will generate the suspend check. |
| 5730 | return; |
| 5731 | } |
| 5732 | GenerateSuspendCheck(instruction, nullptr); |
| 5733 | } |
| 5734 | |
| 5735 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5736 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5737 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5738 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5739 | if (slow_path == nullptr) { |
| 5740 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5741 | instruction->SetSlowPath(slow_path); |
| 5742 | codegen_->AddSlowPath(slow_path); |
| 5743 | if (successor != nullptr) { |
| 5744 | DCHECK(successor->IsLoopHeader()); |
| 5745 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5746 | } |
| 5747 | } else { |
| 5748 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5749 | } |
| 5750 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5751 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5752 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5753 | if (successor == nullptr) { |
| 5754 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5755 | __ Bind(slow_path->GetReturnLabel()); |
| 5756 | } else { |
| 5757 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5758 | __ jmp(slow_path->GetEntryLabel()); |
| 5759 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5760 | } |
| 5761 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5762 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5763 | return codegen_->GetAssembler(); |
| 5764 | } |
| 5765 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5766 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5767 | ScratchRegisterScope ensure_scratch( |
| 5768 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5769 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5770 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5771 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5772 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5776 | ScratchRegisterScope ensure_scratch( |
| 5777 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5778 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5779 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5780 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5781 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5782 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5783 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5787 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5788 | Location source = move->GetSource(); |
| 5789 | Location destination = move->GetDestination(); |
| 5790 | |
| 5791 | if (source.IsRegister()) { |
| 5792 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5793 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5794 | } else if (destination.IsFpuRegister()) { |
| 5795 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5796 | } else { |
| 5797 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5798 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5799 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5800 | } else if (source.IsRegisterPair()) { |
| 5801 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5802 | // Create stack space for 2 elements. |
| 5803 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5804 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5805 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5806 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5807 | // And remove the temporary stack space we allocated. |
| 5808 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5809 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5810 | if (destination.IsRegister()) { |
| 5811 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5812 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5813 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5814 | } else if (destination.IsRegisterPair()) { |
| 5815 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5816 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5817 | __ psrlq(src_reg, Immediate(32)); |
| 5818 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5819 | } else if (destination.IsStackSlot()) { |
| 5820 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5821 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5822 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5823 | } else { |
| 5824 | DCHECK(destination.IsSIMDStackSlot()); |
| 5825 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5826 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5827 | } else if (source.IsStackSlot()) { |
| 5828 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5829 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5830 | } else if (destination.IsFpuRegister()) { |
| 5831 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5832 | } else { |
| 5833 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5834 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5835 | } |
| 5836 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5837 | if (destination.IsRegisterPair()) { |
| 5838 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5839 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5840 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5841 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5842 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5843 | } else { |
| 5844 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5845 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5846 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5847 | } else if (source.IsSIMDStackSlot()) { |
| 5848 | DCHECK(destination.IsFpuRegister()); |
| 5849 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5850 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5851 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5852 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5853 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5854 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5855 | if (value == 0) { |
| 5856 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5857 | } else { |
| 5858 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5859 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5860 | } else { |
| 5861 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5862 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5863 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5864 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5865 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5866 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5867 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5868 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5869 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5870 | if (value == 0) { |
| 5871 | // Easy handling of 0.0. |
| 5872 | __ xorps(dest, dest); |
| 5873 | } else { |
| 5874 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5875 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5876 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5877 | __ movl(temp, Immediate(value)); |
| 5878 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5879 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5880 | } else { |
| 5881 | DCHECK(destination.IsStackSlot()) << destination; |
| 5882 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5883 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5884 | } else if (constant->IsLongConstant()) { |
| 5885 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5886 | int32_t low_value = Low32Bits(value); |
| 5887 | int32_t high_value = High32Bits(value); |
| 5888 | Immediate low(low_value); |
| 5889 | Immediate high(high_value); |
| 5890 | if (destination.IsDoubleStackSlot()) { |
| 5891 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5892 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5893 | } else { |
| 5894 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5895 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5896 | } |
| 5897 | } else { |
| 5898 | DCHECK(constant->IsDoubleConstant()); |
| 5899 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5900 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5901 | int32_t low_value = Low32Bits(value); |
| 5902 | int32_t high_value = High32Bits(value); |
| 5903 | Immediate low(low_value); |
| 5904 | Immediate high(high_value); |
| 5905 | if (destination.IsFpuRegister()) { |
| 5906 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5907 | if (value == 0) { |
| 5908 | // Easy handling of 0.0. |
| 5909 | __ xorpd(dest, dest); |
| 5910 | } else { |
| 5911 | __ pushl(high); |
| 5912 | __ pushl(low); |
| 5913 | __ movsd(dest, Address(ESP, 0)); |
| 5914 | __ addl(ESP, Immediate(8)); |
| 5915 | } |
| 5916 | } else { |
| 5917 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5918 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5919 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5920 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5921 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5922 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5923 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5924 | } |
| 5925 | } |
| 5926 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5927 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5928 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5929 | ScratchRegisterScope ensure_scratch( |
| 5930 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5931 | |
| 5932 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5933 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5934 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5935 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5936 | } |
| 5937 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5938 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5939 | ScratchRegisterScope ensure_scratch( |
| 5940 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5941 | |
| 5942 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5943 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5944 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5945 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5946 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5947 | } |
| 5948 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5949 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5950 | ScratchRegisterScope ensure_scratch1( |
| 5951 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5952 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5953 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5954 | ScratchRegisterScope ensure_scratch2( |
| 5955 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5956 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5957 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5958 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5959 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5960 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5961 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5962 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5966 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5967 | Location source = move->GetSource(); |
| 5968 | Location destination = move->GetDestination(); |
| 5969 | |
| 5970 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5971 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5972 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5973 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5974 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5975 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5976 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5977 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5978 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5979 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5980 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5981 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5982 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5983 | // Use XOR Swap algorithm to avoid a temporary. |
| 5984 | DCHECK_NE(source.reg(), destination.reg()); |
| 5985 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5986 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5987 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5988 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5989 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5990 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5991 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5992 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5993 | // Take advantage of the 16 bytes in the XMM register. |
| 5994 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5995 | Address stack(ESP, destination.GetStackIndex()); |
| 5996 | // Load the double into the high doubleword. |
| 5997 | __ movhpd(reg, stack); |
| 5998 | |
| 5999 | // Store the low double into the destination. |
| 6000 | __ movsd(stack, reg); |
| 6001 | |
| 6002 | // Move the high double to the low double. |
| 6003 | __ psrldq(reg, Immediate(8)); |
| 6004 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6005 | // Take advantage of the 16 bytes in the XMM register. |
| 6006 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6007 | Address stack(ESP, source.GetStackIndex()); |
| 6008 | // Load the double into the high doubleword. |
| 6009 | __ movhpd(reg, stack); |
| 6010 | |
| 6011 | // Store the low double into the destination. |
| 6012 | __ movsd(stack, reg); |
| 6013 | |
| 6014 | // Move the high double to the low double. |
| 6015 | __ psrldq(reg, Immediate(8)); |
| 6016 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 6017 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 6018 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6019 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6020 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6021 | } |
| 6022 | } |
| 6023 | |
| 6024 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6025 | __ pushl(static_cast<Register>(reg)); |
| 6026 | } |
| 6027 | |
| 6028 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6029 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6030 | } |
| 6031 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6032 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6033 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6034 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6035 | case HLoadClass::LoadKind::kInvalid: |
| 6036 | LOG(FATAL) << "UNREACHABLE"; |
| 6037 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6038 | case HLoadClass::LoadKind::kReferrersClass: |
| 6039 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6040 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6041 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6042 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6043 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6044 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6045 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6046 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6047 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6048 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6049 | break; |
| 6050 | } |
| 6051 | return desired_class_load_kind; |
| 6052 | } |
| 6053 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6054 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6055 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6056 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6057 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6058 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6059 | cls, |
| 6060 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6061 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6062 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6063 | return; |
| 6064 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6065 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6066 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6067 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6068 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6069 | ? LocationSummary::kCallOnSlowPath |
| 6070 | : LocationSummary::kNoCall; |
| 6071 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6072 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6073 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6074 | } |
| 6075 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6076 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6077 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 6078 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6080 | } |
| 6081 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6082 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6083 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6084 | // Rely on the type resolution and/or initialization to save everything. |
| 6085 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6086 | InvokeRuntimeCallingConvention calling_convention; |
| 6087 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6088 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6089 | } else { |
| 6090 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6091 | } |
| 6092 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6093 | } |
| 6094 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6095 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| 6096 | dex::TypeIndex dex_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6097 | Handle<mirror::Class> handle) { |
| 6098 | jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index), |
| 6099 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6100 | // Add a patch entry and return the label. |
| 6101 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 6102 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6103 | return &info->label; |
| 6104 | } |
| 6105 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6106 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6107 | // move. |
| 6108 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6109 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6110 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6111 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6112 | return; |
| 6113 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6114 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6115 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6116 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6117 | Location out_loc = locations->Out(); |
| 6118 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6119 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6120 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6121 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6122 | ? kWithoutReadBarrier |
| 6123 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6124 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6125 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6126 | DCHECK(!cls->CanCallRuntime()); |
| 6127 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6128 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6129 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6130 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6131 | cls, |
| 6132 | out_loc, |
| 6133 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6134 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6135 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6136 | break; |
| 6137 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6138 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6139 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6140 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6141 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6142 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6143 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6144 | break; |
| 6145 | } |
| 6146 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6147 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6148 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6149 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6150 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6151 | __ movl(out, Immediate(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6152 | break; |
| 6153 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6154 | case HLoadClass::LoadKind::kBssEntry: { |
| 6155 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6156 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6157 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6158 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6159 | generate_null_check = true; |
| 6160 | break; |
| 6161 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6162 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6163 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6164 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6165 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6166 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6167 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6168 | break; |
| 6169 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6170 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6171 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6172 | LOG(FATAL) << "UNREACHABLE"; |
| 6173 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6174 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6175 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6176 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6177 | DCHECK(cls->CanCallRuntime()); |
| 6178 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6179 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6180 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6181 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6182 | if (generate_null_check) { |
| 6183 | __ testl(out, out); |
| 6184 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6185 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6186 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6187 | if (cls->MustGenerateClinitCheck()) { |
| 6188 | GenerateClassInitializationCheck(slow_path, out); |
| 6189 | } else { |
| 6190 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6191 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6192 | } |
| 6193 | } |
| 6194 | |
| 6195 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6196 | LocationSummary* locations = |
| 6197 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6198 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6199 | if (check->HasUses()) { |
| 6200 | locations->SetOut(Location::SameAsFirstInput()); |
| 6201 | } |
| 6202 | } |
| 6203 | |
| 6204 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6205 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6206 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6207 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6208 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6209 | GenerateClassInitializationCheck(slow_path, |
| 6210 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6211 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6212 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6213 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6214 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6215 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6216 | Immediate(mirror::Class::kStatusInitialized)); |
| 6217 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6218 | __ Bind(slow_path->GetExitLabel()); |
| 6219 | // No need for memory fence, thanks to the X86 memory model. |
| 6220 | } |
| 6221 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6222 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6223 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6224 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6225 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 6226 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6227 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6228 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6229 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6230 | case HLoadString::LoadKind::kJitTableAddress: |
| 6231 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6232 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6233 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6234 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6235 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6236 | } |
| 6237 | return desired_string_load_kind; |
| 6238 | } |
| 6239 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6240 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6241 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6242 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6243 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6244 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 6245 | load_kind == HLoadString::LoadKind::kBootImageInternTable || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6246 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6247 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6248 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6249 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6250 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6251 | } else { |
| 6252 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6253 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6254 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6255 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6256 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6257 | InvokeRuntimeCallingConvention calling_convention; |
| 6258 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6259 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6260 | } else { |
| 6261 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6262 | } |
| 6263 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6264 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6267 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6268 | dex::StringIndex dex_index, |
| 6269 | Handle<mirror::String> handle) { |
| 6270 | jit_string_roots_.Overwrite( |
| 6271 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6272 | // Add a patch entry and return the label. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6273 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6274 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6275 | return &info->label; |
| 6276 | } |
| 6277 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6278 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6279 | // move. |
| 6280 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6281 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6282 | Location out_loc = locations->Out(); |
| 6283 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6284 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6285 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6286 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6287 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6288 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6289 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6290 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 6291 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6292 | } |
| 6293 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6294 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6295 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6296 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6297 | __ movl(out, Immediate(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame^] | 6298 | return; |
| 6299 | } |
| 6300 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 6301 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6302 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6303 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6304 | codegen_->RecordBootStringPatch(load); |
| 6305 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6306 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6307 | case HLoadString::LoadKind::kBssEntry: { |
| 6308 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6309 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6310 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6311 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6312 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6313 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6314 | codegen_->AddSlowPath(slow_path); |
| 6315 | __ testl(out, out); |
| 6316 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6317 | __ Bind(slow_path->GetExitLabel()); |
| 6318 | return; |
| 6319 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6320 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6321 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6322 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6323 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6324 | // /* GcRoot<mirror::String> */ out = *address |
| 6325 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6326 | return; |
| 6327 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6328 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6329 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6330 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6331 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6332 | // 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] | 6333 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6334 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6335 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6336 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6337 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6338 | } |
| 6339 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6340 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6341 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6342 | } |
| 6343 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6344 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6345 | LocationSummary* locations = |
| 6346 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6347 | locations->SetOut(Location::RequiresRegister()); |
| 6348 | } |
| 6349 | |
| 6350 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6351 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6352 | } |
| 6353 | |
| 6354 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6355 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6356 | } |
| 6357 | |
| 6358 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6359 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6360 | } |
| 6361 | |
| 6362 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6363 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6364 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6365 | InvokeRuntimeCallingConvention calling_convention; |
| 6366 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6367 | } |
| 6368 | |
| 6369 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6370 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6371 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6372 | } |
| 6373 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6374 | // Temp is used for read barrier. |
| 6375 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6376 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6377 | !kUseBakerReadBarrier && |
| 6378 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6379 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6380 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6381 | return 1; |
| 6382 | } |
| 6383 | return 0; |
| 6384 | } |
| 6385 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6386 | // 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] | 6387 | // interface pointer, one for loading the current interface. |
| 6388 | // The other checks have one temp for loading the object's class. |
| 6389 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6390 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6391 | return 2; |
| 6392 | } |
| 6393 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6394 | } |
| 6395 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6396 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6397 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6398 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6399 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6400 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6401 | case TypeCheckKind::kExactCheck: |
| 6402 | case TypeCheckKind::kAbstractClassCheck: |
| 6403 | case TypeCheckKind::kClassHierarchyCheck: |
| 6404 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6405 | call_kind = |
| 6406 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6407 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6408 | break; |
| 6409 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6410 | case TypeCheckKind::kUnresolvedCheck: |
| 6411 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6412 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6413 | break; |
| 6414 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6415 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6416 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6417 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6418 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6419 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6420 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6421 | locations->SetInAt(1, Location::Any()); |
| 6422 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6423 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6424 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6425 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6426 | } |
| 6427 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6428 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6429 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6430 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6431 | Location obj_loc = locations->InAt(0); |
| 6432 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6433 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6434 | Location out_loc = locations->Out(); |
| 6435 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6436 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6437 | DCHECK_LE(num_temps, 1u); |
| 6438 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6439 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6440 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6441 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6442 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6443 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6444 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6445 | |
| 6446 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6447 | // Avoid null check if we know obj is not null. |
| 6448 | if (instruction->MustDoNullCheck()) { |
| 6449 | __ testl(obj, obj); |
| 6450 | __ j(kEqual, &zero); |
| 6451 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6452 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6453 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6454 | case TypeCheckKind::kExactCheck: { |
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 (cls.IsRegister()) { |
| 6462 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6463 | } else { |
| 6464 | DCHECK(cls.IsStackSlot()) << cls; |
| 6465 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6466 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6467 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6468 | // Classes must be equal for the instanceof to succeed. |
| 6469 | __ j(kNotEqual, &zero); |
| 6470 | __ movl(out, Immediate(1)); |
| 6471 | __ jmp(&done); |
| 6472 | break; |
| 6473 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6474 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6475 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6476 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6477 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6478 | out_loc, |
| 6479 | obj_loc, |
| 6480 | class_offset, |
| 6481 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6482 | // If the class is abstract, we eagerly fetch the super class of the |
| 6483 | // object to avoid doing a comparison we know will fail. |
| 6484 | NearLabel loop; |
| 6485 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6486 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6487 | GenerateReferenceLoadOneRegister(instruction, |
| 6488 | out_loc, |
| 6489 | super_offset, |
| 6490 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6491 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6492 | __ testl(out, out); |
| 6493 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6494 | __ j(kEqual, &done); |
| 6495 | if (cls.IsRegister()) { |
| 6496 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6497 | } else { |
| 6498 | DCHECK(cls.IsStackSlot()) << cls; |
| 6499 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6500 | } |
| 6501 | __ j(kNotEqual, &loop); |
| 6502 | __ movl(out, Immediate(1)); |
| 6503 | if (zero.IsLinked()) { |
| 6504 | __ jmp(&done); |
| 6505 | } |
| 6506 | break; |
| 6507 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6508 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6509 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6510 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6511 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6512 | out_loc, |
| 6513 | obj_loc, |
| 6514 | class_offset, |
| 6515 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6516 | // Walk over the class hierarchy to find a match. |
| 6517 | NearLabel loop, success; |
| 6518 | __ Bind(&loop); |
| 6519 | if (cls.IsRegister()) { |
| 6520 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6521 | } else { |
| 6522 | DCHECK(cls.IsStackSlot()) << cls; |
| 6523 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6524 | } |
| 6525 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6526 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6527 | GenerateReferenceLoadOneRegister(instruction, |
| 6528 | out_loc, |
| 6529 | super_offset, |
| 6530 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6531 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6532 | __ testl(out, out); |
| 6533 | __ j(kNotEqual, &loop); |
| 6534 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6535 | __ jmp(&done); |
| 6536 | __ Bind(&success); |
| 6537 | __ movl(out, Immediate(1)); |
| 6538 | if (zero.IsLinked()) { |
| 6539 | __ jmp(&done); |
| 6540 | } |
| 6541 | break; |
| 6542 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6543 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6544 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6545 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6546 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6547 | out_loc, |
| 6548 | obj_loc, |
| 6549 | class_offset, |
| 6550 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6551 | // Do an exact check. |
| 6552 | NearLabel exact_check; |
| 6553 | if (cls.IsRegister()) { |
| 6554 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6555 | } else { |
| 6556 | DCHECK(cls.IsStackSlot()) << cls; |
| 6557 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6558 | } |
| 6559 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6560 | // 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] | 6561 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6562 | GenerateReferenceLoadOneRegister(instruction, |
| 6563 | out_loc, |
| 6564 | component_offset, |
| 6565 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6566 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6567 | __ testl(out, out); |
| 6568 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6569 | __ j(kEqual, &done); |
| 6570 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6571 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6572 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6573 | __ movl(out, Immediate(1)); |
| 6574 | __ jmp(&done); |
| 6575 | break; |
| 6576 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6577 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6578 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6579 | // No read barrier since the slow path will retry upon failure. |
| 6580 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6581 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6582 | out_loc, |
| 6583 | obj_loc, |
| 6584 | class_offset, |
| 6585 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6586 | if (cls.IsRegister()) { |
| 6587 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6588 | } else { |
| 6589 | DCHECK(cls.IsStackSlot()) << cls; |
| 6590 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6591 | } |
| 6592 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6593 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6594 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6595 | codegen_->AddSlowPath(slow_path); |
| 6596 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6597 | __ movl(out, Immediate(1)); |
| 6598 | if (zero.IsLinked()) { |
| 6599 | __ jmp(&done); |
| 6600 | } |
| 6601 | break; |
| 6602 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6603 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6604 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6605 | case TypeCheckKind::kInterfaceCheck: { |
| 6606 | // 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] | 6607 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6608 | // cases. |
| 6609 | // |
| 6610 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6611 | // entry point without resorting to a type checking slow path |
| 6612 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6613 | // require to assign fixed registers for the inputs of this |
| 6614 | // HInstanceOf instruction (following the runtime calling |
| 6615 | // convention), which might be cluttered by the potential first |
| 6616 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6617 | // |
| 6618 | // TODO: Introduce a new runtime entry point taking the object |
| 6619 | // to test (instead of its class) as argument, and let it deal |
| 6620 | // with the read barrier issues. This will let us refactor this |
| 6621 | // case of the `switch` code as it was previously (with a direct |
| 6622 | // call to the runtime not using a type checking slow path). |
| 6623 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6624 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6625 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6626 | /* is_fatal */ false); |
| 6627 | codegen_->AddSlowPath(slow_path); |
| 6628 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6629 | if (zero.IsLinked()) { |
| 6630 | __ jmp(&done); |
| 6631 | } |
| 6632 | break; |
| 6633 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6634 | } |
| 6635 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6636 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6637 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6638 | __ xorl(out, out); |
| 6639 | } |
| 6640 | |
| 6641 | if (done.IsLinked()) { |
| 6642 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6643 | } |
| 6644 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6645 | if (slow_path != nullptr) { |
| 6646 | __ Bind(slow_path->GetExitLabel()); |
| 6647 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6648 | } |
| 6649 | |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6650 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6651 | switch (type_check_kind) { |
| 6652 | case TypeCheckKind::kExactCheck: |
| 6653 | case TypeCheckKind::kAbstractClassCheck: |
| 6654 | case TypeCheckKind::kClassHierarchyCheck: |
| 6655 | case TypeCheckKind::kArrayObjectCheck: |
| 6656 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6657 | case TypeCheckKind::kInterfaceCheck: |
| 6658 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6659 | case TypeCheckKind::kArrayCheck: |
| 6660 | case TypeCheckKind::kUnresolvedCheck: |
| 6661 | return false; |
| 6662 | } |
| 6663 | LOG(FATAL) << "Unreachable"; |
| 6664 | UNREACHABLE(); |
| 6665 | } |
| 6666 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6667 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6668 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6669 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6670 | LocationSummary::CallKind call_kind = |
| 6671 | IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch) |
| 6672 | ? LocationSummary::kNoCall |
| 6673 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6674 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6675 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6676 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6677 | // Require a register for the interface check since there is a loop that compares the class to |
| 6678 | // a memory address. |
| 6679 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6680 | } else { |
| 6681 | locations->SetInAt(1, Location::Any()); |
| 6682 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6683 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6684 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6685 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6686 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6687 | } |
| 6688 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6689 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6690 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6691 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6692 | Location obj_loc = locations->InAt(0); |
| 6693 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6694 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6695 | Location temp_loc = locations->GetTemp(0); |
| 6696 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6697 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6698 | DCHECK_GE(num_temps, 1u); |
| 6699 | DCHECK_LE(num_temps, 2u); |
| 6700 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6701 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6702 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6703 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6704 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6705 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6706 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6707 | const uint32_t object_array_data_offset = |
| 6708 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6709 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6710 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6711 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6712 | // read barriers is done for performance and code size reasons. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6713 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6714 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6715 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6716 | SlowPathCode* type_check_slow_path = |
| 6717 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6718 | is_type_check_slow_path_fatal); |
| 6719 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6720 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6721 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6722 | // Avoid null check if we know obj is not null. |
| 6723 | if (instruction->MustDoNullCheck()) { |
| 6724 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6725 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6726 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6727 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6728 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6729 | case TypeCheckKind::kExactCheck: |
| 6730 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6731 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6732 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6733 | temp_loc, |
| 6734 | obj_loc, |
| 6735 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6736 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6737 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6738 | if (cls.IsRegister()) { |
| 6739 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6740 | } else { |
| 6741 | DCHECK(cls.IsStackSlot()) << cls; |
| 6742 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6743 | } |
| 6744 | // Jump to slow path for throwing the exception or doing a |
| 6745 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6746 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6747 | break; |
| 6748 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6749 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6750 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6751 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6752 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6753 | temp_loc, |
| 6754 | obj_loc, |
| 6755 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6756 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6757 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6758 | // If the class is abstract, we eagerly fetch the super class of the |
| 6759 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6760 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6761 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6762 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6763 | GenerateReferenceLoadOneRegister(instruction, |
| 6764 | temp_loc, |
| 6765 | super_offset, |
| 6766 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6767 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6768 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6769 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6770 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6771 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6772 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6773 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6774 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 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 | } |
| 6781 | __ j(kNotEqual, &loop); |
| 6782 | break; |
| 6783 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6784 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6785 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6786 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6787 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6788 | temp_loc, |
| 6789 | obj_loc, |
| 6790 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6791 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6792 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6793 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6794 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6795 | __ Bind(&loop); |
| 6796 | if (cls.IsRegister()) { |
| 6797 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6798 | } else { |
| 6799 | DCHECK(cls.IsStackSlot()) << cls; |
| 6800 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6801 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6802 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6803 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6804 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6805 | GenerateReferenceLoadOneRegister(instruction, |
| 6806 | temp_loc, |
| 6807 | super_offset, |
| 6808 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6809 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6810 | |
| 6811 | // If the class reference currently in `temp` is not null, jump |
| 6812 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6813 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6814 | __ j(kNotZero, &loop); |
| 6815 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6816 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6817 | break; |
| 6818 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6819 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6820 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6821 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6822 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6823 | temp_loc, |
| 6824 | obj_loc, |
| 6825 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6826 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6827 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6828 | // Do an exact check. |
| 6829 | if (cls.IsRegister()) { |
| 6830 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6831 | } else { |
| 6832 | DCHECK(cls.IsStackSlot()) << cls; |
| 6833 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6834 | } |
| 6835 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6836 | |
| 6837 | // 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] | 6838 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6839 | GenerateReferenceLoadOneRegister(instruction, |
| 6840 | temp_loc, |
| 6841 | component_offset, |
| 6842 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6843 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6844 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6845 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6846 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6847 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6848 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6849 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6850 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6851 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6852 | break; |
| 6853 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6854 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6855 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6856 | // 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] | 6857 | // We cannot directly call the CheckCast runtime entry point |
| 6858 | // without resorting to a type checking slow path here (i.e. by |
| 6859 | // calling InvokeRuntime directly), as it would require to |
| 6860 | // assign fixed registers for the inputs of this HInstanceOf |
| 6861 | // instruction (following the runtime calling convention), which |
| 6862 | // might be cluttered by the potential first read barrier |
| 6863 | // emission at the beginning of this method. |
| 6864 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6865 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6866 | |
| 6867 | case TypeCheckKind::kInterfaceCheck: { |
| 6868 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6869 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6870 | // 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] | 6871 | // to the slow path if we are running under poisoning. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6872 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6873 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6874 | // doing this. |
| 6875 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6876 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6877 | temp_loc, |
| 6878 | obj_loc, |
| 6879 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6880 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6881 | |
| 6882 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6883 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6884 | temp_loc, |
| 6885 | temp_loc, |
| 6886 | iftable_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6887 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6888 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6889 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6890 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6891 | NearLabel start_loop; |
| 6892 | __ Bind(&start_loop); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6893 | // Need to subtract first to handle the empty array case. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6894 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6895 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6896 | // Go to next interface if the classes do not match. |
| 6897 | __ cmpl(cls.AsRegister<Register>(), |
| 6898 | CodeGeneratorX86::ArrayAddress(temp, |
| 6899 | maybe_temp2_loc, |
| 6900 | TIMES_4, |
| 6901 | object_array_data_offset)); |
| 6902 | __ j(kNotEqual, &start_loop); |
| 6903 | } else { |
| 6904 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6905 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6906 | break; |
| 6907 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6908 | } |
| 6909 | __ Bind(&done); |
| 6910 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6911 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6912 | } |
| 6913 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6914 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6915 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6916 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6917 | InvokeRuntimeCallingConvention calling_convention; |
| 6918 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6919 | } |
| 6920 | |
| 6921 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6922 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6923 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6924 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6925 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6926 | if (instruction->IsEnter()) { |
| 6927 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6928 | } else { |
| 6929 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6930 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6931 | } |
| 6932 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6933 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6934 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6935 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6936 | |
| 6937 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6938 | LocationSummary* locations = |
| 6939 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6940 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6941 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6942 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6943 | locations->SetInAt(1, Location::Any()); |
| 6944 | locations->SetOut(Location::SameAsFirstInput()); |
| 6945 | } |
| 6946 | |
| 6947 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6948 | HandleBitwiseOperation(instruction); |
| 6949 | } |
| 6950 | |
| 6951 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6952 | HandleBitwiseOperation(instruction); |
| 6953 | } |
| 6954 | |
| 6955 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6956 | HandleBitwiseOperation(instruction); |
| 6957 | } |
| 6958 | |
| 6959 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6960 | LocationSummary* locations = instruction->GetLocations(); |
| 6961 | Location first = locations->InAt(0); |
| 6962 | Location second = locations->InAt(1); |
| 6963 | DCHECK(first.Equals(locations->Out())); |
| 6964 | |
| 6965 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6966 | if (second.IsRegister()) { |
| 6967 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6968 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
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>(), second.AsRegister<Register>()); |
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>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6974 | } |
| 6975 | } else if (second.IsConstant()) { |
| 6976 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6977 | __ andl(first.AsRegister<Register>(), |
| 6978 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6979 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6980 | __ orl(first.AsRegister<Register>(), |
| 6981 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6982 | } else { |
| 6983 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6984 | __ xorl(first.AsRegister<Register>(), |
| 6985 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6986 | } |
| 6987 | } else { |
| 6988 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6989 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6990 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6991 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6992 | } else { |
| 6993 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6994 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6995 | } |
| 6996 | } |
| 6997 | } else { |
| 6998 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6999 | if (second.IsRegisterPair()) { |
| 7000 | if (instruction->IsAnd()) { |
| 7001 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7002 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7003 | } else if (instruction->IsOr()) { |
| 7004 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7005 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7006 | } else { |
| 7007 | DCHECK(instruction->IsXor()); |
| 7008 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7009 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7010 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7011 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7012 | if (instruction->IsAnd()) { |
| 7013 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7014 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7015 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7016 | } else if (instruction->IsOr()) { |
| 7017 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7018 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7019 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7020 | } else { |
| 7021 | DCHECK(instruction->IsXor()); |
| 7022 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7023 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7024 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7025 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7026 | } else { |
| 7027 | DCHECK(second.IsConstant()) << second; |
| 7028 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7029 | int32_t low_value = Low32Bits(value); |
| 7030 | int32_t high_value = High32Bits(value); |
| 7031 | Immediate low(low_value); |
| 7032 | Immediate high(high_value); |
| 7033 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7034 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7035 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7036 | if (low_value == 0) { |
| 7037 | __ xorl(first_low, first_low); |
| 7038 | } else if (low_value != -1) { |
| 7039 | __ andl(first_low, low); |
| 7040 | } |
| 7041 | if (high_value == 0) { |
| 7042 | __ xorl(first_high, first_high); |
| 7043 | } else if (high_value != -1) { |
| 7044 | __ andl(first_high, high); |
| 7045 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7046 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7047 | if (low_value != 0) { |
| 7048 | __ orl(first_low, low); |
| 7049 | } |
| 7050 | if (high_value != 0) { |
| 7051 | __ orl(first_high, high); |
| 7052 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7053 | } else { |
| 7054 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7055 | if (low_value != 0) { |
| 7056 | __ xorl(first_low, low); |
| 7057 | } |
| 7058 | if (high_value != 0) { |
| 7059 | __ xorl(first_high, high); |
| 7060 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7061 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7062 | } |
| 7063 | } |
| 7064 | } |
| 7065 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7066 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7067 | HInstruction* instruction, |
| 7068 | Location out, |
| 7069 | uint32_t offset, |
| 7070 | Location maybe_temp, |
| 7071 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7072 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7073 | if (read_barrier_option == kWithReadBarrier) { |
| 7074 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7075 | if (kUseBakerReadBarrier) { |
| 7076 | // Load with fast path based Baker's read barrier. |
| 7077 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7078 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7079 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7080 | } else { |
| 7081 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7082 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7083 | // in the following move operation, as we will need it for the |
| 7084 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7085 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7086 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7087 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7088 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7089 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7090 | } |
| 7091 | } else { |
| 7092 | // Plain load with no read barrier. |
| 7093 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7094 | __ movl(out_reg, Address(out_reg, offset)); |
| 7095 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7096 | } |
| 7097 | } |
| 7098 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7099 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7100 | HInstruction* instruction, |
| 7101 | Location out, |
| 7102 | Location obj, |
| 7103 | uint32_t offset, |
| 7104 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7105 | Register out_reg = out.AsRegister<Register>(); |
| 7106 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7107 | if (read_barrier_option == kWithReadBarrier) { |
| 7108 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7109 | if (kUseBakerReadBarrier) { |
| 7110 | // Load with fast path based Baker's read barrier. |
| 7111 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7112 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7113 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7114 | } else { |
| 7115 | // Load with slow path based read barrier. |
| 7116 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7117 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7118 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7119 | } |
| 7120 | } else { |
| 7121 | // Plain load with no read barrier. |
| 7122 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7123 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7124 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7125 | } |
| 7126 | } |
| 7127 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7128 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7129 | HInstruction* instruction, |
| 7130 | Location root, |
| 7131 | const Address& address, |
| 7132 | Label* fixup_label, |
| 7133 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7134 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7135 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7136 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7137 | if (kUseBakerReadBarrier) { |
| 7138 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7139 | // Baker's read barrier are used: |
| 7140 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7141 | // root = obj.field; |
| 7142 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7143 | // if (temp != null) { |
| 7144 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7145 | // } |
| 7146 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7147 | // /* GcRoot<mirror::Object> */ root = *address |
| 7148 | __ movl(root_reg, address); |
| 7149 | if (fixup_label != nullptr) { |
| 7150 | __ Bind(fixup_label); |
| 7151 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7152 | static_assert( |
| 7153 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7154 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7155 | "have different sizes."); |
| 7156 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7157 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7158 | "have different sizes."); |
| 7159 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7160 | // Slow path marking the GC root `root`. |
| 7161 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7162 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7163 | codegen_->AddSlowPath(slow_path); |
| 7164 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7165 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7166 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7167 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7168 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7169 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7170 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7171 | __ Bind(slow_path->GetExitLabel()); |
| 7172 | } else { |
| 7173 | // GC root loaded through a slow path for read barriers other |
| 7174 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7175 | // /* GcRoot<mirror::Object>* */ root = address |
| 7176 | __ leal(root_reg, address); |
| 7177 | if (fixup_label != nullptr) { |
| 7178 | __ Bind(fixup_label); |
| 7179 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7180 | // /* mirror::Object* */ root = root->Read() |
| 7181 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7182 | } |
| 7183 | } else { |
| 7184 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7185 | // /* GcRoot<mirror::Object> */ root = *address |
| 7186 | __ movl(root_reg, address); |
| 7187 | if (fixup_label != nullptr) { |
| 7188 | __ Bind(fixup_label); |
| 7189 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7190 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7191 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7192 | } |
| 7193 | } |
| 7194 | |
| 7195 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7196 | Location ref, |
| 7197 | Register obj, |
| 7198 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7199 | bool needs_null_check) { |
| 7200 | DCHECK(kEmitCompilerReadBarrier); |
| 7201 | DCHECK(kUseBakerReadBarrier); |
| 7202 | |
| 7203 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7204 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7205 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7206 | } |
| 7207 | |
| 7208 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7209 | Location ref, |
| 7210 | Register obj, |
| 7211 | uint32_t data_offset, |
| 7212 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7213 | bool needs_null_check) { |
| 7214 | DCHECK(kEmitCompilerReadBarrier); |
| 7215 | DCHECK(kUseBakerReadBarrier); |
| 7216 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7217 | static_assert( |
| 7218 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7219 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7220 | // /* HeapReference<Object> */ ref = |
| 7221 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7222 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7223 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7224 | } |
| 7225 | |
| 7226 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7227 | Location ref, |
| 7228 | Register obj, |
| 7229 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7230 | bool needs_null_check, |
| 7231 | bool always_update_field, |
| 7232 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7233 | DCHECK(kEmitCompilerReadBarrier); |
| 7234 | DCHECK(kUseBakerReadBarrier); |
| 7235 | |
| 7236 | // In slow path based read barriers, the read barrier call is |
| 7237 | // inserted after the original load. However, in fast path based |
| 7238 | // Baker's read barriers, we need to perform the load of |
| 7239 | // mirror::Object::monitor_ *before* the original reference load. |
| 7240 | // This load-load ordering is required by the read barrier. |
| 7241 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7242 | // |
| 7243 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7244 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7245 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7246 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7247 | // if (is_gray) { |
| 7248 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7249 | // } |
| 7250 | // |
| 7251 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7252 | // slightly more complex as: |
| 7253 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7254 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7255 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7256 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7257 | // - it performs additional checks that we do not do here for |
| 7258 | // performance reasons. |
| 7259 | |
| 7260 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7261 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7262 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7263 | // 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] | 7264 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7265 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7266 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7267 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7268 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7269 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7270 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7271 | // ref = ReadBarrier::Mark(ref); |
| 7272 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7273 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7274 | if (needs_null_check) { |
| 7275 | MaybeRecordImplicitNullCheck(instruction); |
| 7276 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7277 | |
| 7278 | // Load fence to prevent load-load reordering. |
| 7279 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7280 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7281 | |
| 7282 | // The actual reference load. |
| 7283 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7284 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7285 | |
| 7286 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7287 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7288 | SlowPathCode* slow_path; |
| 7289 | if (always_update_field) { |
| 7290 | DCHECK(temp != nullptr); |
| 7291 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| 7292 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7293 | } else { |
| 7294 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 7295 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7296 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7297 | AddSlowPath(slow_path); |
| 7298 | |
| 7299 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7300 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7301 | |
| 7302 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7303 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7304 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7305 | __ Bind(slow_path->GetExitLabel()); |
| 7306 | } |
| 7307 | |
| 7308 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7309 | Location out, |
| 7310 | Location ref, |
| 7311 | Location obj, |
| 7312 | uint32_t offset, |
| 7313 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7314 | DCHECK(kEmitCompilerReadBarrier); |
| 7315 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7316 | // Insert a slow path based read barrier *after* the reference load. |
| 7317 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7318 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7319 | // reference will be carried out by the runtime within the slow |
| 7320 | // path. |
| 7321 | // |
| 7322 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7323 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7324 | // not used by the artReadBarrierSlow entry point. |
| 7325 | // |
| 7326 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7327 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7328 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7329 | AddSlowPath(slow_path); |
| 7330 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7331 | __ jmp(slow_path->GetEntryLabel()); |
| 7332 | __ Bind(slow_path->GetExitLabel()); |
| 7333 | } |
| 7334 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7335 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7336 | Location out, |
| 7337 | Location ref, |
| 7338 | Location obj, |
| 7339 | uint32_t offset, |
| 7340 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7341 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7342 | // Baker's read barriers shall be handled by the fast path |
| 7343 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7344 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7345 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7346 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7347 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7348 | } else if (kPoisonHeapReferences) { |
| 7349 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7350 | } |
| 7351 | } |
| 7352 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7353 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7354 | Location out, |
| 7355 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7356 | DCHECK(kEmitCompilerReadBarrier); |
| 7357 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7358 | // Insert a slow path based read barrier *after* the GC root load. |
| 7359 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7360 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7361 | // not need to do anything special for this here. |
| 7362 | SlowPathCode* slow_path = |
| 7363 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7364 | AddSlowPath(slow_path); |
| 7365 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7366 | __ jmp(slow_path->GetEntryLabel()); |
| 7367 | __ Bind(slow_path->GetExitLabel()); |
| 7368 | } |
| 7369 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7370 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7371 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7372 | LOG(FATAL) << "Unreachable"; |
| 7373 | } |
| 7374 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7375 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7376 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7377 | LOG(FATAL) << "Unreachable"; |
| 7378 | } |
| 7379 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7380 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7381 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7382 | LocationSummary* locations = |
| 7383 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7384 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7385 | } |
| 7386 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7387 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7388 | int32_t lower_bound, |
| 7389 | uint32_t num_entries, |
| 7390 | HBasicBlock* switch_block, |
| 7391 | HBasicBlock* default_block) { |
| 7392 | // Figure out the correct compare values and jump conditions. |
| 7393 | // Handle the first compare/branch as a special case because it might |
| 7394 | // jump to the default case. |
| 7395 | DCHECK_GT(num_entries, 2u); |
| 7396 | Condition first_condition; |
| 7397 | uint32_t index; |
| 7398 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7399 | if (lower_bound != 0) { |
| 7400 | first_condition = kLess; |
| 7401 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7402 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7403 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7404 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7405 | index = 1; |
| 7406 | } else { |
| 7407 | // Handle all the compare/jumps below. |
| 7408 | first_condition = kBelow; |
| 7409 | index = 0; |
| 7410 | } |
| 7411 | |
| 7412 | // Handle the rest of the compare/jumps. |
| 7413 | for (; index + 1 < num_entries; index += 2) { |
| 7414 | int32_t compare_to_value = lower_bound + index + 1; |
| 7415 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7416 | // Jump to successors[index] if value < case_value[index]. |
| 7417 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7418 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7419 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7420 | } |
| 7421 | |
| 7422 | if (index != num_entries) { |
| 7423 | // There are an odd number of entries. Handle the last one. |
| 7424 | DCHECK_EQ(index + 1, num_entries); |
| 7425 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7426 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7427 | } |
| 7428 | |
| 7429 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7430 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7431 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7432 | } |
| 7433 | } |
| 7434 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7435 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7436 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7437 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7438 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7439 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7440 | |
| 7441 | GenPackedSwitchWithCompares(value_reg, |
| 7442 | lower_bound, |
| 7443 | num_entries, |
| 7444 | switch_instr->GetBlock(), |
| 7445 | switch_instr->GetDefaultBlock()); |
| 7446 | } |
| 7447 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7448 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7449 | LocationSummary* locations = |
| 7450 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7451 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7452 | |
| 7453 | // Constant area pointer. |
| 7454 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7455 | |
| 7456 | // And the temporary we need. |
| 7457 | locations->AddTemp(Location::RequiresRegister()); |
| 7458 | } |
| 7459 | |
| 7460 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7461 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7462 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7463 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7464 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7465 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7466 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7467 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7468 | GenPackedSwitchWithCompares(value_reg, |
| 7469 | lower_bound, |
| 7470 | num_entries, |
| 7471 | switch_instr->GetBlock(), |
| 7472 | default_block); |
| 7473 | return; |
| 7474 | } |
| 7475 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7476 | // Optimizing has a jump area. |
| 7477 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7478 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7479 | |
| 7480 | // Remove the bias, if needed. |
| 7481 | if (lower_bound != 0) { |
| 7482 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7483 | value_reg = temp_reg; |
| 7484 | } |
| 7485 | |
| 7486 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7487 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7488 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7489 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7490 | |
| 7491 | // We are in the range of the table. |
| 7492 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7493 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7494 | |
| 7495 | // Compute the actual target address by adding in constant_area. |
| 7496 | __ addl(temp_reg, constant_area); |
| 7497 | |
| 7498 | // And jump. |
| 7499 | __ jmp(temp_reg); |
| 7500 | } |
| 7501 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7502 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7503 | HX86ComputeBaseMethodAddress* insn) { |
| 7504 | LocationSummary* locations = |
| 7505 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7506 | locations->SetOut(Location::RequiresRegister()); |
| 7507 | } |
| 7508 | |
| 7509 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7510 | HX86ComputeBaseMethodAddress* insn) { |
| 7511 | LocationSummary* locations = insn->GetLocations(); |
| 7512 | Register reg = locations->Out().AsRegister<Register>(); |
| 7513 | |
| 7514 | // Generate call to next instruction. |
| 7515 | Label next_instruction; |
| 7516 | __ call(&next_instruction); |
| 7517 | __ Bind(&next_instruction); |
| 7518 | |
| 7519 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7520 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7521 | |
| 7522 | // Grab the return address off the stack. |
| 7523 | __ popl(reg); |
| 7524 | } |
| 7525 | |
| 7526 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7527 | HX86LoadFromConstantTable* insn) { |
| 7528 | LocationSummary* locations = |
| 7529 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7530 | |
| 7531 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7532 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7533 | |
| 7534 | // 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] | 7535 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7536 | return; |
| 7537 | } |
| 7538 | |
| 7539 | switch (insn->GetType()) { |
| 7540 | case Primitive::kPrimFloat: |
| 7541 | case Primitive::kPrimDouble: |
| 7542 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7543 | break; |
| 7544 | |
| 7545 | case Primitive::kPrimInt: |
| 7546 | locations->SetOut(Location::RequiresRegister()); |
| 7547 | break; |
| 7548 | |
| 7549 | default: |
| 7550 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7551 | } |
| 7552 | } |
| 7553 | |
| 7554 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7555 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7556 | return; |
| 7557 | } |
| 7558 | |
| 7559 | LocationSummary* locations = insn->GetLocations(); |
| 7560 | Location out = locations->Out(); |
| 7561 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7562 | HConstant *value = insn->GetConstant(); |
| 7563 | |
| 7564 | switch (insn->GetType()) { |
| 7565 | case Primitive::kPrimFloat: |
| 7566 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7567 | codegen_->LiteralFloatAddress( |
| 7568 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7569 | break; |
| 7570 | |
| 7571 | case Primitive::kPrimDouble: |
| 7572 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7573 | codegen_->LiteralDoubleAddress( |
| 7574 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7575 | break; |
| 7576 | |
| 7577 | case Primitive::kPrimInt: |
| 7578 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7579 | codegen_->LiteralInt32Address( |
| 7580 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7581 | break; |
| 7582 | |
| 7583 | default: |
| 7584 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7585 | } |
| 7586 | } |
| 7587 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7588 | /** |
| 7589 | * Class to handle late fixup of offsets into constant area. |
| 7590 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7591 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7592 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7593 | RIPFixup(CodeGeneratorX86& codegen, |
| 7594 | HX86ComputeBaseMethodAddress* base_method_address, |
| 7595 | size_t offset) |
| 7596 | : codegen_(&codegen), |
| 7597 | base_method_address_(base_method_address), |
| 7598 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7599 | |
| 7600 | protected: |
| 7601 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7602 | |
| 7603 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7604 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7605 | |
| 7606 | private: |
| 7607 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7608 | // Patch the correct offset for the instruction. The place to patch is the |
| 7609 | // last 4 bytes of the instruction. |
| 7610 | // The value to patch is the distance from the offset in the constant area |
| 7611 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7612 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7613 | int32_t relative_position = |
| 7614 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7615 | |
| 7616 | // Patch in the right value. |
| 7617 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7618 | } |
| 7619 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7620 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7621 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7622 | }; |
| 7623 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7624 | /** |
| 7625 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7626 | * constant area. |
| 7627 | */ |
| 7628 | class JumpTableRIPFixup : public RIPFixup { |
| 7629 | public: |
| 7630 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7631 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 7632 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7633 | |
| 7634 | void CreateJumpTable() { |
| 7635 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7636 | |
| 7637 | // Ensure that the reference to the jump table has the correct offset. |
| 7638 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7639 | SetOffset(offset_in_constant_table); |
| 7640 | |
| 7641 | // The label values in the jump table are computed relative to the |
| 7642 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7643 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7644 | |
| 7645 | // Populate the jump table with the correct values for the jump table. |
| 7646 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7647 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7648 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7649 | // The value that we want is the target offset - the position of the table. |
| 7650 | for (int32_t i = 0; i < num_entries; i++) { |
| 7651 | HBasicBlock* b = successors[i]; |
| 7652 | Label* l = codegen_->GetLabelOf(b); |
| 7653 | DCHECK(l->IsBound()); |
| 7654 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7655 | assembler->AppendInt32(offset_to_block); |
| 7656 | } |
| 7657 | } |
| 7658 | |
| 7659 | private: |
| 7660 | const HX86PackedSwitch* switch_instr_; |
| 7661 | }; |
| 7662 | |
| 7663 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7664 | // Generate the constant area if needed. |
| 7665 | X86Assembler* assembler = GetAssembler(); |
| 7666 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7667 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7668 | // byte values. |
| 7669 | assembler->Align(4, 0); |
| 7670 | constant_area_start_ = assembler->CodeSize(); |
| 7671 | |
| 7672 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7673 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7674 | jump_table->CreateJumpTable(); |
| 7675 | } |
| 7676 | |
| 7677 | // And now add the constant area to the generated code. |
| 7678 | assembler->AddConstantArea(); |
| 7679 | } |
| 7680 | |
| 7681 | // And finish up. |
| 7682 | CodeGenerator::Finalize(allocator); |
| 7683 | } |
| 7684 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7685 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 7686 | HX86ComputeBaseMethodAddress* method_base, |
| 7687 | Register reg) { |
| 7688 | AssemblerFixup* fixup = |
| 7689 | new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7690 | return Address(reg, kDummy32BitOffset, fixup); |
| 7691 | } |
| 7692 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7693 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 7694 | HX86ComputeBaseMethodAddress* method_base, |
| 7695 | Register reg) { |
| 7696 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7697 | return Address(reg, kDummy32BitOffset, fixup); |
| 7698 | } |
| 7699 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7700 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 7701 | HX86ComputeBaseMethodAddress* method_base, |
| 7702 | Register reg) { |
| 7703 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7704 | return Address(reg, kDummy32BitOffset, fixup); |
| 7705 | } |
| 7706 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7707 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 7708 | HX86ComputeBaseMethodAddress* method_base, |
| 7709 | Register reg) { |
| 7710 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7711 | return Address(reg, kDummy32BitOffset, fixup); |
| 7712 | } |
| 7713 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7714 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7715 | if (value == 0) { |
| 7716 | __ xorl(dest, dest); |
| 7717 | } else { |
| 7718 | __ movl(dest, Immediate(value)); |
| 7719 | } |
| 7720 | } |
| 7721 | |
| 7722 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7723 | if (value == 0) { |
| 7724 | __ testl(dest, dest); |
| 7725 | } else { |
| 7726 | __ cmpl(dest, Immediate(value)); |
| 7727 | } |
| 7728 | } |
| 7729 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7730 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7731 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7732 | GenerateIntCompare(lhs_reg, rhs); |
| 7733 | } |
| 7734 | |
| 7735 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7736 | if (rhs.IsConstant()) { |
| 7737 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7738 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7739 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7740 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7741 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7742 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7743 | } |
| 7744 | } |
| 7745 | |
| 7746 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7747 | Location index, |
| 7748 | ScaleFactor scale, |
| 7749 | uint32_t data_offset) { |
| 7750 | return index.IsConstant() ? |
| 7751 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7752 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7753 | } |
| 7754 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7755 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7756 | Register reg, |
| 7757 | Register value) { |
| 7758 | // Create a fixup to be used to create and address the jump table. |
| 7759 | JumpTableRIPFixup* table_fixup = |
| 7760 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7761 | |
| 7762 | // We have to populate the jump tables. |
| 7763 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7764 | |
| 7765 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7766 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7767 | } |
| 7768 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7769 | // TODO: target as memory. |
| 7770 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7771 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7772 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7773 | return; |
| 7774 | } |
| 7775 | |
| 7776 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7777 | |
| 7778 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7779 | if (target.Equals(return_loc)) { |
| 7780 | return; |
| 7781 | } |
| 7782 | |
| 7783 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7784 | // with the else branch. |
| 7785 | if (type == Primitive::kPrimLong) { |
| 7786 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7787 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7788 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7789 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7790 | } else { |
| 7791 | // Let the parallel move resolver take care of all of this. |
| 7792 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7793 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7794 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7795 | } |
| 7796 | } |
| 7797 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7798 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7799 | const uint8_t* roots_data, |
| 7800 | const PatchInfo<Label>& info, |
| 7801 | uint64_t index_in_table) const { |
| 7802 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7803 | uintptr_t address = |
| 7804 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7805 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7806 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7807 | dchecked_integral_cast<uint32_t>(address); |
| 7808 | } |
| 7809 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7810 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7811 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7812 | const auto it = jit_string_roots_.find( |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7813 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7814 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7815 | uint64_t index_in_table = it->second; |
| 7816 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7817 | } |
| 7818 | |
| 7819 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7820 | const auto it = jit_class_roots_.find( |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7821 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7822 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7823 | uint64_t index_in_table = it->second; |
| 7824 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7825 | } |
| 7826 | } |
| 7827 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7828 | #undef __ |
| 7829 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7830 | } // namespace x86 |
| 7831 | } // namespace art |