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" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame^] | 26 | #include "heap_poisoning.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_x86.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 29 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 30 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 32 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 34 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 39 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 40 | template<class MirrorType> |
| 41 | class GcRoot; |
| 42 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 43 | namespace x86 { |
| 44 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 45 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 46 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 47 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 48 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 49 | static constexpr int kC2ConditionMask = 0x400; |
| 50 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 51 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 52 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 53 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 54 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 55 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 57 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 59 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 61 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 62 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 64 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 65 | // Live registers will be restored in the catch block if caught. |
| 66 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 67 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 68 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 69 | instruction_, |
| 70 | instruction_->GetDexPc(), |
| 71 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 72 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 75 | bool IsFatal() const OVERRIDE { return true; } |
| 76 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 77 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 78 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 81 | }; |
| 82 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 83 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 84 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 85 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 87 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 88 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 90 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 91 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 94 | bool IsFatal() const OVERRIDE { return true; } |
| 95 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 96 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 97 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 100 | }; |
| 101 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 102 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 104 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 105 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 107 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 109 | if (is_div_) { |
| 110 | __ negl(reg_); |
| 111 | } else { |
| 112 | __ movl(reg_, Immediate(0)); |
| 113 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | __ jmp(GetExitLabel()); |
| 115 | } |
| 116 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 117 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 118 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | private: |
| 120 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 121 | bool is_div_; |
| 122 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 125 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 126 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 127 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 128 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 129 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 130 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 131 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 132 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 133 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 134 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 135 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 136 | // Live registers will be restored in the catch block if caught. |
| 137 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 138 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 139 | |
| 140 | // Are we using an array length from memory? |
| 141 | HInstruction* array_length = instruction_->InputAt(1); |
| 142 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 143 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 144 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 145 | // Load the array length into our temporary. |
| 146 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 147 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 148 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 149 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 150 | // Check for conflicts with index. |
| 151 | if (length_loc.Equals(locations->InAt(0))) { |
| 152 | // We know we aren't using parameter 2. |
| 153 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 154 | } |
| 155 | __ movl(length_loc.AsRegister<Register>(), array_len); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 156 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 157 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 158 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 159 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 160 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 161 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 162 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 163 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 164 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 165 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 166 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 167 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 168 | ? kQuickThrowStringBounds |
| 169 | : kQuickThrowArrayBounds; |
| 170 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 171 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 172 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 175 | bool IsFatal() const OVERRIDE { return true; } |
| 176 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 177 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 178 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 181 | }; |
| 182 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 183 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 185 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 186 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 187 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 188 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 189 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 190 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 191 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 192 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 193 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 194 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 195 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 196 | if (successor_ == nullptr) { |
| 197 | __ jmp(GetReturnLabel()); |
| 198 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 199 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 200 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 203 | Label* GetReturnLabel() { |
| 204 | DCHECK(successor_ == nullptr); |
| 205 | return &return_label_; |
| 206 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 207 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 208 | HBasicBlock* GetSuccessor() const { |
| 209 | return successor_; |
| 210 | } |
| 211 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 212 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 213 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 214 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 215 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 216 | Label return_label_; |
| 217 | |
| 218 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 219 | }; |
| 220 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 221 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 222 | public: |
| 223 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 224 | |
| 225 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 226 | LocationSummary* locations = instruction_->GetLocations(); |
| 227 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 228 | |
| 229 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 230 | __ Bind(GetEntryLabel()); |
| 231 | SaveLiveRegisters(codegen, locations); |
| 232 | |
| 233 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 234 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 235 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 236 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 237 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 238 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 239 | RestoreLiveRegisters(codegen, locations); |
| 240 | |
| 241 | // Store the resolved String to the BSS entry. |
| 242 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 243 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 244 | locations->Out().AsRegister<Register>()); |
| 245 | Label* fixup_label = x86_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 246 | __ Bind(fixup_label); |
| 247 | |
| 248 | __ jmp(GetExitLabel()); |
| 249 | } |
| 250 | |
| 251 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 252 | |
| 253 | private: |
| 254 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 255 | }; |
| 256 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 257 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | public: |
| 259 | LoadClassSlowPathX86(HLoadClass* cls, |
| 260 | HInstruction* at, |
| 261 | uint32_t dex_pc, |
| 262 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 263 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 264 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 265 | } |
| 266 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 267 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 268 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 270 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 271 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 272 | |
| 273 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 274 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 275 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 276 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 277 | : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 278 | instruction_, |
| 279 | dex_pc_, |
| 280 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 281 | if (do_clinit_) { |
| 282 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 283 | } else { |
| 284 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 285 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | |
| 287 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 288 | Location out = locations->Out(); |
| 289 | if (out.IsValid()) { |
| 290 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 291 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 292 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 293 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 294 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 295 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 296 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 297 | DCHECK(out.IsValid()); |
| 298 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 299 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 300 | locations->Out().AsRegister<Register>()); |
| 301 | Label* fixup_label = x86_codegen->NewTypeBssEntryPatch(cls_); |
| 302 | __ Bind(fixup_label); |
| 303 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 304 | __ jmp(GetExitLabel()); |
| 305 | } |
| 306 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 307 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 308 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 309 | private: |
| 310 | // The class this slow path will load. |
| 311 | HLoadClass* const cls_; |
| 312 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 313 | // The dex PC of `at_`. |
| 314 | const uint32_t dex_pc_; |
| 315 | |
| 316 | // Whether to initialize the class. |
| 317 | const bool do_clinit_; |
| 318 | |
| 319 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 320 | }; |
| 321 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 322 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 323 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 324 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 325 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 327 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 328 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 329 | DCHECK(instruction_->IsCheckCast() |
| 330 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 331 | |
| 332 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 333 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 334 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 335 | if (!is_fatal_) { |
| 336 | SaveLiveRegisters(codegen, locations); |
| 337 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | |
| 339 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 340 | // move resolver. |
| 341 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 342 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 343 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 344 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 345 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 346 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 347 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 348 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 349 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 350 | instruction_, |
| 351 | instruction_->GetDexPc(), |
| 352 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 353 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 354 | } else { |
| 355 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 356 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 357 | instruction_, |
| 358 | instruction_->GetDexPc(), |
| 359 | this); |
| 360 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | if (!is_fatal_) { |
| 364 | if (instruction_->IsInstanceOf()) { |
| 365 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 366 | } |
| 367 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 368 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 369 | __ jmp(GetExitLabel()); |
| 370 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 373 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 374 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 375 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 376 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 377 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 378 | |
| 379 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 380 | }; |
| 381 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 382 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 384 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 385 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 386 | |
| 387 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 388 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 389 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 390 | LocationSummary* locations = instruction_->GetLocations(); |
| 391 | SaveLiveRegisters(codegen, locations); |
| 392 | InvokeRuntimeCallingConvention calling_convention; |
| 393 | x86_codegen->Load32BitValue( |
| 394 | calling_convention.GetRegisterAt(0), |
| 395 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 396 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 397 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 400 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 401 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 402 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 403 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 404 | }; |
| 405 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 406 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 407 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 408 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 409 | |
| 410 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 411 | LocationSummary* locations = instruction_->GetLocations(); |
| 412 | __ Bind(GetEntryLabel()); |
| 413 | SaveLiveRegisters(codegen, locations); |
| 414 | |
| 415 | InvokeRuntimeCallingConvention calling_convention; |
| 416 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 417 | parallel_move.AddMove( |
| 418 | locations->InAt(0), |
| 419 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 420 | Primitive::kPrimNot, |
| 421 | nullptr); |
| 422 | parallel_move.AddMove( |
| 423 | locations->InAt(1), |
| 424 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 425 | Primitive::kPrimInt, |
| 426 | nullptr); |
| 427 | parallel_move.AddMove( |
| 428 | locations->InAt(2), |
| 429 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 430 | Primitive::kPrimNot, |
| 431 | nullptr); |
| 432 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 433 | |
| 434 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 435 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 436 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 437 | RestoreLiveRegisters(codegen, locations); |
| 438 | __ jmp(GetExitLabel()); |
| 439 | } |
| 440 | |
| 441 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 442 | |
| 443 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 444 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 445 | }; |
| 446 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 447 | // Slow path marking an object reference `ref` during a read |
| 448 | // barrier. The field `obj.field` in the object `obj` holding this |
| 449 | // reference does not get updated by this slow path after marking (see |
| 450 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 451 | // |
| 452 | // This means that after the execution of this slow path, `ref` will |
| 453 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 454 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 455 | // probably still be a from-space reference (unless it gets updated by |
| 456 | // another thread, or if another thread installed another object |
| 457 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 458 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 459 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 460 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 461 | Location ref, |
| 462 | bool unpoison_ref_before_marking) |
| 463 | : SlowPathCode(instruction), |
| 464 | ref_(ref), |
| 465 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 466 | DCHECK(kEmitCompilerReadBarrier); |
| 467 | } |
| 468 | |
| 469 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 470 | |
| 471 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 472 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 473 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 474 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 475 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 476 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 477 | instruction_->IsStaticFieldGet() || |
| 478 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 479 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 480 | instruction_->IsLoadClass() || |
| 481 | instruction_->IsLoadString() || |
| 482 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 483 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 484 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 485 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 486 | << "Unexpected instruction in read barrier marking slow path: " |
| 487 | << instruction_->DebugName(); |
| 488 | |
| 489 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 490 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 491 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 492 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 493 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 494 | // No need to save live registers; it's taken care of by the |
| 495 | // entrypoint. Also, there is no need to update the stack mask, |
| 496 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 497 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 498 | DCHECK_NE(ref_reg, ESP); |
| 499 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 500 | // "Compact" slow path, saving two moves. |
| 501 | // |
| 502 | // Instead of using the standard runtime calling convention (input |
| 503 | // and output in EAX): |
| 504 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 505 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 506 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 507 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 508 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 509 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 510 | // of a dedicated entrypoint: |
| 511 | // |
| 512 | // rX <- ReadBarrierMarkRegX(rX) |
| 513 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 514 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 515 | // This runtime call does not require a stack map. |
| 516 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 517 | __ jmp(GetExitLabel()); |
| 518 | } |
| 519 | |
| 520 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 521 | // The location (register) of the marked object reference. |
| 522 | const Location ref_; |
| 523 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 524 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 525 | |
| 526 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 527 | }; |
| 528 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 529 | // Slow path marking an object reference `ref` during a read barrier, |
| 530 | // and if needed, atomically updating the field `obj.field` in the |
| 531 | // object `obj` holding this reference after marking (contrary to |
| 532 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 533 | // `obj.field`). |
| 534 | // |
| 535 | // This means that after the execution of this slow path, both `ref` |
| 536 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 537 | // hold the same to-space reference (unless another thread installed |
| 538 | // another object reference (different from `ref`) in `obj.field`). |
| 539 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 540 | public: |
| 541 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 542 | Location ref, |
| 543 | Register obj, |
| 544 | const Address& field_addr, |
| 545 | bool unpoison_ref_before_marking, |
| 546 | Register temp) |
| 547 | : SlowPathCode(instruction), |
| 548 | ref_(ref), |
| 549 | obj_(obj), |
| 550 | field_addr_(field_addr), |
| 551 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 552 | temp_(temp) { |
| 553 | DCHECK(kEmitCompilerReadBarrier); |
| 554 | } |
| 555 | |
| 556 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 557 | |
| 558 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 559 | LocationSummary* locations = instruction_->GetLocations(); |
| 560 | Register ref_reg = ref_.AsRegister<Register>(); |
| 561 | DCHECK(locations->CanCall()); |
| 562 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 563 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 564 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 565 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 566 | << instruction_->DebugName(); |
| 567 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 568 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 569 | |
| 570 | __ Bind(GetEntryLabel()); |
| 571 | if (unpoison_ref_before_marking_) { |
| 572 | // Object* ref = ref_addr->AsMirrorPtr() |
| 573 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 574 | } |
| 575 | |
| 576 | // Save the old (unpoisoned) reference. |
| 577 | __ movl(temp_, ref_reg); |
| 578 | |
| 579 | // No need to save live registers; it's taken care of by the |
| 580 | // entrypoint. Also, there is no need to update the stack mask, |
| 581 | // as this runtime call will not trigger a garbage collection. |
| 582 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 583 | DCHECK_NE(ref_reg, ESP); |
| 584 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 585 | // "Compact" slow path, saving two moves. |
| 586 | // |
| 587 | // Instead of using the standard runtime calling convention (input |
| 588 | // and output in EAX): |
| 589 | // |
| 590 | // EAX <- ref |
| 591 | // EAX <- ReadBarrierMark(EAX) |
| 592 | // ref <- EAX |
| 593 | // |
| 594 | // we just use rX (the register containing `ref`) as input and output |
| 595 | // of a dedicated entrypoint: |
| 596 | // |
| 597 | // rX <- ReadBarrierMarkRegX(rX) |
| 598 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 599 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 600 | // This runtime call does not require a stack map. |
| 601 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 602 | |
| 603 | // If the new reference is different from the old reference, |
| 604 | // update the field in the holder (`*field_addr`). |
| 605 | // |
| 606 | // Note that this field could also hold a different object, if |
| 607 | // another thread had concurrently changed it. In that case, the |
| 608 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 609 | // operation below would abort the CAS, leaving the field as-is. |
| 610 | NearLabel done; |
| 611 | __ cmpl(temp_, ref_reg); |
| 612 | __ j(kEqual, &done); |
| 613 | |
| 614 | // Update the the holder's field atomically. This may fail if |
| 615 | // mutator updates before us, but it's OK. This is achieved |
| 616 | // using a strong compare-and-set (CAS) operation with relaxed |
| 617 | // memory synchronization ordering, where the expected value is |
| 618 | // the old reference and the desired value is the new reference. |
| 619 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 620 | // instruction, which requires the expected value (the old |
| 621 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 622 | // expected value (stored in `temp_`) into EAX. |
| 623 | __ pushl(EAX); |
| 624 | __ movl(EAX, temp_); |
| 625 | |
| 626 | // Convenience aliases. |
| 627 | Register base = obj_; |
| 628 | Register expected = EAX; |
| 629 | Register value = ref_reg; |
| 630 | |
| 631 | bool base_equals_value = (base == value); |
| 632 | if (kPoisonHeapReferences) { |
| 633 | if (base_equals_value) { |
| 634 | // If `base` and `value` are the same register location, move |
| 635 | // `value` to a temporary register. This way, poisoning |
| 636 | // `value` won't invalidate `base`. |
| 637 | value = temp_; |
| 638 | __ movl(value, base); |
| 639 | } |
| 640 | |
| 641 | // Check that the register allocator did not assign the location |
| 642 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 643 | // poisoning (when enabled) works as intended below. |
| 644 | // - If `value` were equal to `expected`, both references would |
| 645 | // be poisoned twice, meaning they would not be poisoned at |
| 646 | // all, as heap poisoning uses address negation. |
| 647 | // - If `base` were equal to `expected`, poisoning `expected` |
| 648 | // would invalidate `base`. |
| 649 | DCHECK_NE(value, expected); |
| 650 | DCHECK_NE(base, expected); |
| 651 | |
| 652 | __ PoisonHeapReference(expected); |
| 653 | __ PoisonHeapReference(value); |
| 654 | } |
| 655 | |
| 656 | __ LockCmpxchgl(field_addr_, value); |
| 657 | |
| 658 | // If heap poisoning is enabled, we need to unpoison the values |
| 659 | // that were poisoned earlier. |
| 660 | if (kPoisonHeapReferences) { |
| 661 | if (base_equals_value) { |
| 662 | // `value` has been moved to a temporary register, no need |
| 663 | // to unpoison it. |
| 664 | } else { |
| 665 | __ UnpoisonHeapReference(value); |
| 666 | } |
| 667 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 668 | } |
| 669 | |
| 670 | // Restore EAX. |
| 671 | __ popl(EAX); |
| 672 | |
| 673 | __ Bind(&done); |
| 674 | __ jmp(GetExitLabel()); |
| 675 | } |
| 676 | |
| 677 | private: |
| 678 | // The location (register) of the marked object reference. |
| 679 | const Location ref_; |
| 680 | // The register containing the object holding the marked object reference field. |
| 681 | const Register obj_; |
| 682 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 683 | const Address field_addr_; |
| 684 | |
| 685 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 686 | const bool unpoison_ref_before_marking_; |
| 687 | |
| 688 | const Register temp_; |
| 689 | |
| 690 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 691 | }; |
| 692 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 693 | // Slow path generating a read barrier for a heap reference. |
| 694 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 695 | public: |
| 696 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 697 | Location out, |
| 698 | Location ref, |
| 699 | Location obj, |
| 700 | uint32_t offset, |
| 701 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 702 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 703 | out_(out), |
| 704 | ref_(ref), |
| 705 | obj_(obj), |
| 706 | offset_(offset), |
| 707 | index_(index) { |
| 708 | DCHECK(kEmitCompilerReadBarrier); |
| 709 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 710 | // has been overwritten by (or after) the heap object reference load |
| 711 | // to be instrumented, e.g.: |
| 712 | // |
| 713 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 714 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 715 | // |
| 716 | // In that case, we have lost the information about the original |
| 717 | // object, and the emitted read barrier cannot work properly. |
| 718 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 719 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 720 | } |
| 721 | |
| 722 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 723 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 724 | LocationSummary* locations = instruction_->GetLocations(); |
| 725 | Register reg_out = out_.AsRegister<Register>(); |
| 726 | DCHECK(locations->CanCall()); |
| 727 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 728 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 729 | instruction_->IsStaticFieldGet() || |
| 730 | instruction_->IsArrayGet() || |
| 731 | instruction_->IsInstanceOf() || |
| 732 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 733 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 734 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 735 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 736 | |
| 737 | __ Bind(GetEntryLabel()); |
| 738 | SaveLiveRegisters(codegen, locations); |
| 739 | |
| 740 | // We may have to change the index's value, but as `index_` is a |
| 741 | // constant member (like other "inputs" of this slow path), |
| 742 | // introduce a copy of it, `index`. |
| 743 | Location index = index_; |
| 744 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 745 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 746 | if (instruction_->IsArrayGet()) { |
| 747 | // Compute the actual memory offset and store it in `index`. |
| 748 | Register index_reg = index_.AsRegister<Register>(); |
| 749 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 750 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 751 | // We are about to change the value of `index_reg` (see the |
| 752 | // calls to art::x86::X86Assembler::shll and |
| 753 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 754 | // not been saved by the previous call to |
| 755 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 756 | // callee-save register -- |
| 757 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 758 | // callee-save registers, as it has been designed with the |
| 759 | // assumption that callee-save registers are supposed to be |
| 760 | // handled by the called function. So, as a callee-save |
| 761 | // register, `index_reg` _would_ eventually be saved onto |
| 762 | // the stack, but it would be too late: we would have |
| 763 | // changed its value earlier. Therefore, we manually save |
| 764 | // it here into another freely available register, |
| 765 | // `free_reg`, chosen of course among the caller-save |
| 766 | // registers (as a callee-save `free_reg` register would |
| 767 | // exhibit the same problem). |
| 768 | // |
| 769 | // Note we could have requested a temporary register from |
| 770 | // the register allocator instead; but we prefer not to, as |
| 771 | // this is a slow path, and we know we can find a |
| 772 | // caller-save register that is available. |
| 773 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 774 | __ movl(free_reg, index_reg); |
| 775 | index_reg = free_reg; |
| 776 | index = Location::RegisterLocation(index_reg); |
| 777 | } else { |
| 778 | // The initial register stored in `index_` has already been |
| 779 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 780 | // (as it is not a callee-save register), so we can freely |
| 781 | // use it. |
| 782 | } |
| 783 | // Shifting the index value contained in `index_reg` by the scale |
| 784 | // factor (2) cannot overflow in practice, as the runtime is |
| 785 | // unable to allocate object arrays with a size larger than |
| 786 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 787 | __ shll(index_reg, Immediate(TIMES_4)); |
| 788 | static_assert( |
| 789 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 790 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 791 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 792 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 793 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 794 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 795 | // (as in the case of ArrayGet), as it is actually an offset |
| 796 | // to an object field within an object. |
| 797 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 798 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 799 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 800 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 801 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 802 | DCHECK_EQ(offset_, 0U); |
| 803 | DCHECK(index_.IsRegisterPair()); |
| 804 | // UnsafeGet's offset location is a register pair, the low |
| 805 | // part contains the correct offset. |
| 806 | index = index_.ToLow(); |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | // We're moving two or three locations to locations that could |
| 811 | // overlap, so we need a parallel move resolver. |
| 812 | InvokeRuntimeCallingConvention calling_convention; |
| 813 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 814 | parallel_move.AddMove(ref_, |
| 815 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 816 | Primitive::kPrimNot, |
| 817 | nullptr); |
| 818 | parallel_move.AddMove(obj_, |
| 819 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 820 | Primitive::kPrimNot, |
| 821 | nullptr); |
| 822 | if (index.IsValid()) { |
| 823 | parallel_move.AddMove(index, |
| 824 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 825 | Primitive::kPrimInt, |
| 826 | nullptr); |
| 827 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 828 | } else { |
| 829 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 830 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 831 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 832 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 833 | CheckEntrypointTypes< |
| 834 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 835 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 836 | |
| 837 | RestoreLiveRegisters(codegen, locations); |
| 838 | __ jmp(GetExitLabel()); |
| 839 | } |
| 840 | |
| 841 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 842 | |
| 843 | private: |
| 844 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 845 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 846 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 847 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 848 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 849 | return static_cast<Register>(i); |
| 850 | } |
| 851 | } |
| 852 | // We shall never fail to find a free caller-save register, as |
| 853 | // there are more than two core caller-save registers on x86 |
| 854 | // (meaning it is possible to find one which is different from |
| 855 | // `ref` and `obj`). |
| 856 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 857 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 858 | UNREACHABLE(); |
| 859 | } |
| 860 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 861 | const Location out_; |
| 862 | const Location ref_; |
| 863 | const Location obj_; |
| 864 | const uint32_t offset_; |
| 865 | // An additional location containing an index to an array. |
| 866 | // Only used for HArrayGet and the UnsafeGetObject & |
| 867 | // UnsafeGetObjectVolatile intrinsics. |
| 868 | const Location index_; |
| 869 | |
| 870 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 871 | }; |
| 872 | |
| 873 | // Slow path generating a read barrier for a GC root. |
| 874 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 875 | public: |
| 876 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 877 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 878 | DCHECK(kEmitCompilerReadBarrier); |
| 879 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 880 | |
| 881 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 882 | LocationSummary* locations = instruction_->GetLocations(); |
| 883 | Register reg_out = out_.AsRegister<Register>(); |
| 884 | DCHECK(locations->CanCall()); |
| 885 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 886 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 887 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 888 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 889 | |
| 890 | __ Bind(GetEntryLabel()); |
| 891 | SaveLiveRegisters(codegen, locations); |
| 892 | |
| 893 | InvokeRuntimeCallingConvention calling_convention; |
| 894 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 895 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 896 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 897 | instruction_, |
| 898 | instruction_->GetDexPc(), |
| 899 | this); |
| 900 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 901 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 902 | |
| 903 | RestoreLiveRegisters(codegen, locations); |
| 904 | __ jmp(GetExitLabel()); |
| 905 | } |
| 906 | |
| 907 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 908 | |
| 909 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 910 | const Location out_; |
| 911 | const Location root_; |
| 912 | |
| 913 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 914 | }; |
| 915 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 916 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 917 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 918 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 919 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 920 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 921 | switch (cond) { |
| 922 | case kCondEQ: return kEqual; |
| 923 | case kCondNE: return kNotEqual; |
| 924 | case kCondLT: return kLess; |
| 925 | case kCondLE: return kLessEqual; |
| 926 | case kCondGT: return kGreater; |
| 927 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 928 | case kCondB: return kBelow; |
| 929 | case kCondBE: return kBelowEqual; |
| 930 | case kCondA: return kAbove; |
| 931 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 932 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 933 | LOG(FATAL) << "Unreachable"; |
| 934 | UNREACHABLE(); |
| 935 | } |
| 936 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 937 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 938 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 939 | switch (cond) { |
| 940 | case kCondEQ: return kEqual; |
| 941 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 942 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 943 | case kCondLT: return kBelow; |
| 944 | case kCondLE: return kBelowEqual; |
| 945 | case kCondGT: return kAbove; |
| 946 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 947 | // Unsigned remain unchanged. |
| 948 | case kCondB: return kBelow; |
| 949 | case kCondBE: return kBelowEqual; |
| 950 | case kCondA: return kAbove; |
| 951 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 952 | } |
| 953 | LOG(FATAL) << "Unreachable"; |
| 954 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 957 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 958 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 962 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 965 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 966 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 967 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 968 | } |
| 969 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 970 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 971 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 972 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 973 | } |
| 974 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 975 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 976 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 977 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 978 | } else { |
| 979 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 980 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 981 | return GetFloatingPointSpillSlotSize(); |
| 982 | } |
| 983 | |
| 984 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 985 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 986 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 987 | } else { |
| 988 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 989 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 990 | return GetFloatingPointSpillSlotSize(); |
| 991 | } |
| 992 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 993 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 994 | HInstruction* instruction, |
| 995 | uint32_t dex_pc, |
| 996 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 997 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 998 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 999 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1000 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1001 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1004 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1005 | HInstruction* instruction, |
| 1006 | SlowPathCode* slow_path) { |
| 1007 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1008 | GenerateInvokeRuntime(entry_point_offset); |
| 1009 | } |
| 1010 | |
| 1011 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1012 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1013 | } |
| 1014 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1015 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1016 | const X86InstructionSetFeatures& isa_features, |
| 1017 | const CompilerOptions& compiler_options, |
| 1018 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1019 | : CodeGenerator(graph, |
| 1020 | kNumberOfCpuRegisters, |
| 1021 | kNumberOfXmmRegisters, |
| 1022 | kNumberOfRegisterPairs, |
| 1023 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1024 | arraysize(kCoreCalleeSaves)) |
| 1025 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1026 | 0, |
| 1027 | compiler_options, |
| 1028 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1029 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1030 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1031 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1032 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1033 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1034 | isa_features_(isa_features), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1035 | boot_image_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1036 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1037 | boot_image_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1038 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1039 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1040 | string_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1041 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1042 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1043 | constant_area_start_(-1), |
| 1044 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1045 | method_address_offset_(std::less<uint32_t>(), |
| 1046 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1047 | // Use a fake return address register to mimic Quick. |
| 1048 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1049 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1050 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1051 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1052 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1053 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1056 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1057 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1058 | assembler_(codegen->GetAssembler()), |
| 1059 | codegen_(codegen) {} |
| 1060 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1061 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1062 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1063 | } |
| 1064 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1065 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1066 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1067 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1068 | bool skip_overflow_check = |
| 1069 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1070 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1071 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1072 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1073 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1074 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1075 | } |
| 1076 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1077 | if (HasEmptyFrame()) { |
| 1078 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1079 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1080 | |
| 1081 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1082 | Register reg = kCoreCalleeSaves[i]; |
| 1083 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1084 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1085 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1086 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1090 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1091 | __ subl(ESP, Immediate(adjust)); |
| 1092 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1093 | // Save the current method if we need it. Note that we do not |
| 1094 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1095 | // in the SSA graph. |
| 1096 | if (RequiresCurrentMethod()) { |
| 1097 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1098 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1099 | |
| 1100 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1101 | // Initialize should_deoptimize flag to 0. |
| 1102 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1103 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1107 | __ cfi().RememberState(); |
| 1108 | if (!HasEmptyFrame()) { |
| 1109 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1110 | __ addl(ESP, Immediate(adjust)); |
| 1111 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1112 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1113 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1114 | Register reg = kCoreCalleeSaves[i]; |
| 1115 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1116 | __ popl(reg); |
| 1117 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1118 | __ cfi().Restore(DWARFReg(reg)); |
| 1119 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1120 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1121 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1122 | __ ret(); |
| 1123 | __ cfi().RestoreState(); |
| 1124 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1127 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1128 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1131 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 1132 | switch (type) { |
| 1133 | case Primitive::kPrimBoolean: |
| 1134 | case Primitive::kPrimByte: |
| 1135 | case Primitive::kPrimChar: |
| 1136 | case Primitive::kPrimShort: |
| 1137 | case Primitive::kPrimInt: |
| 1138 | case Primitive::kPrimNot: |
| 1139 | return Location::RegisterLocation(EAX); |
| 1140 | |
| 1141 | case Primitive::kPrimLong: |
| 1142 | return Location::RegisterPairLocation(EAX, EDX); |
| 1143 | |
| 1144 | case Primitive::kPrimVoid: |
| 1145 | return Location::NoLocation(); |
| 1146 | |
| 1147 | case Primitive::kPrimDouble: |
| 1148 | case Primitive::kPrimFloat: |
| 1149 | return Location::FpuRegisterLocation(XMM0); |
| 1150 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1151 | |
| 1152 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1156 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1157 | } |
| 1158 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1159 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1160 | switch (type) { |
| 1161 | case Primitive::kPrimBoolean: |
| 1162 | case Primitive::kPrimByte: |
| 1163 | case Primitive::kPrimChar: |
| 1164 | case Primitive::kPrimShort: |
| 1165 | case Primitive::kPrimInt: |
| 1166 | case Primitive::kPrimNot: { |
| 1167 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1168 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1169 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1170 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1171 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1172 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1173 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1174 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1175 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1176 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1177 | uint32_t index = gp_index_; |
| 1178 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1179 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1180 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1181 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1182 | calling_convention.GetRegisterPairAt(index)); |
| 1183 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1184 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1185 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1190 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1191 | stack_index_++; |
| 1192 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1193 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1194 | } else { |
| 1195 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1200 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1201 | stack_index_ += 2; |
| 1202 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1203 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1204 | } else { |
| 1205 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1209 | case Primitive::kPrimVoid: |
| 1210 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1211 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1212 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1213 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1214 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1215 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1216 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1217 | if (source.Equals(destination)) { |
| 1218 | return; |
| 1219 | } |
| 1220 | if (destination.IsRegister()) { |
| 1221 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1222 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1223 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1224 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1225 | } else { |
| 1226 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1227 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1228 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1229 | } else if (destination.IsFpuRegister()) { |
| 1230 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1231 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1232 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1233 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1234 | } else { |
| 1235 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1236 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1237 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1238 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1239 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1240 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1241 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1242 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1243 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1244 | } else if (source.IsConstant()) { |
| 1245 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1246 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1247 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1248 | } else { |
| 1249 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1250 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1251 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1252 | } |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1257 | if (source.Equals(destination)) { |
| 1258 | return; |
| 1259 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1260 | if (destination.IsRegisterPair()) { |
| 1261 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1262 | EmitParallelMoves( |
| 1263 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1264 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1265 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1266 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1267 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1268 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1269 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1270 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1271 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1272 | __ psrlq(src_reg, Immediate(32)); |
| 1273 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1274 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1275 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1276 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1277 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1278 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1279 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1280 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1281 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1282 | if (source.IsFpuRegister()) { |
| 1283 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1284 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1285 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1286 | } else if (source.IsRegisterPair()) { |
| 1287 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1288 | // Create stack space for 2 elements. |
| 1289 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1290 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1291 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1292 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1293 | // And remove the temporary stack space we allocated. |
| 1294 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1295 | } else { |
| 1296 | LOG(FATAL) << "Unimplemented"; |
| 1297 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1298 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1299 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1300 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1301 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1302 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1303 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1304 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1305 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1306 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1307 | } else if (source.IsConstant()) { |
| 1308 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1309 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1310 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1311 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1312 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1313 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1314 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1315 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1316 | EmitParallelMoves( |
| 1317 | Location::StackSlot(source.GetStackIndex()), |
| 1318 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1319 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1320 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1321 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1322 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1327 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1328 | DCHECK(location.IsRegister()); |
| 1329 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1330 | } |
| 1331 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1332 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1333 | HParallelMove move(GetGraph()->GetArena()); |
| 1334 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1335 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1336 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1337 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1338 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1339 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1340 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1344 | if (location.IsRegister()) { |
| 1345 | locations->AddTemp(location); |
| 1346 | } else if (location.IsRegisterPair()) { |
| 1347 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1348 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1349 | } else { |
| 1350 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1351 | } |
| 1352 | } |
| 1353 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1354 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1355 | DCHECK(!successor->IsExitBlock()); |
| 1356 | |
| 1357 | HBasicBlock* block = got->GetBlock(); |
| 1358 | HInstruction* previous = got->GetPrevious(); |
| 1359 | |
| 1360 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1361 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1362 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1363 | return; |
| 1364 | } |
| 1365 | |
| 1366 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1367 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1368 | } |
| 1369 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1370 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1374 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1375 | got->SetLocations(nullptr); |
| 1376 | } |
| 1377 | |
| 1378 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1379 | HandleGoto(got, got->GetSuccessor()); |
| 1380 | } |
| 1381 | |
| 1382 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1383 | try_boundary->SetLocations(nullptr); |
| 1384 | } |
| 1385 | |
| 1386 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1387 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1388 | if (!successor->IsExitBlock()) { |
| 1389 | HandleGoto(try_boundary, successor); |
| 1390 | } |
| 1391 | } |
| 1392 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1393 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1394 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1397 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1400 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1401 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1402 | LabelType* true_label, |
| 1403 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1404 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1405 | __ j(kUnordered, true_label); |
| 1406 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1407 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1408 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1409 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1410 | } |
| 1411 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1412 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1413 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1414 | LabelType* true_label, |
| 1415 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1416 | LocationSummary* locations = cond->GetLocations(); |
| 1417 | Location left = locations->InAt(0); |
| 1418 | Location right = locations->InAt(1); |
| 1419 | IfCondition if_cond = cond->GetCondition(); |
| 1420 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1421 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1422 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1423 | IfCondition true_high_cond = if_cond; |
| 1424 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1425 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1426 | |
| 1427 | // Set the conditions for the test, remembering that == needs to be |
| 1428 | // decided using the low words. |
| 1429 | switch (if_cond) { |
| 1430 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1431 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1432 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1433 | break; |
| 1434 | case kCondLT: |
| 1435 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1436 | break; |
| 1437 | case kCondLE: |
| 1438 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | break; |
| 1440 | case kCondGT: |
| 1441 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1442 | break; |
| 1443 | case kCondGE: |
| 1444 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1446 | case kCondB: |
| 1447 | false_high_cond = kCondA; |
| 1448 | break; |
| 1449 | case kCondBE: |
| 1450 | true_high_cond = kCondB; |
| 1451 | break; |
| 1452 | case kCondA: |
| 1453 | false_high_cond = kCondB; |
| 1454 | break; |
| 1455 | case kCondAE: |
| 1456 | true_high_cond = kCondA; |
| 1457 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | if (right.IsConstant()) { |
| 1461 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1462 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1463 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1464 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1465 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1466 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1467 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1468 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1469 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1470 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1471 | __ j(X86Condition(true_high_cond), true_label); |
| 1472 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1473 | } |
| 1474 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1475 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1476 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1477 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1478 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1479 | |
| 1480 | __ cmpl(left_high, right_high); |
| 1481 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1482 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1483 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1484 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1485 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1486 | __ j(X86Condition(true_high_cond), true_label); |
| 1487 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1488 | } |
| 1489 | // Must be equal high, so compare the lows. |
| 1490 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1491 | } else { |
| 1492 | DCHECK(right.IsDoubleStackSlot()); |
| 1493 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1494 | if (if_cond == kCondNE) { |
| 1495 | __ j(X86Condition(true_high_cond), true_label); |
| 1496 | } else if (if_cond == kCondEQ) { |
| 1497 | __ j(X86Condition(false_high_cond), false_label); |
| 1498 | } else { |
| 1499 | __ j(X86Condition(true_high_cond), true_label); |
| 1500 | __ j(X86Condition(false_high_cond), false_label); |
| 1501 | } |
| 1502 | // Must be equal high, so compare the lows. |
| 1503 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1504 | } |
| 1505 | // The last comparison might be unsigned. |
| 1506 | __ j(final_condition, true_label); |
| 1507 | } |
| 1508 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1509 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1510 | Location rhs, |
| 1511 | HInstruction* insn, |
| 1512 | bool is_double) { |
| 1513 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1514 | if (is_double) { |
| 1515 | if (rhs.IsFpuRegister()) { |
| 1516 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1517 | } else if (const_area != nullptr) { |
| 1518 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1519 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1520 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1521 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1522 | const_area->GetBaseMethodAddress(), |
| 1523 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1524 | } else { |
| 1525 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1526 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1527 | } |
| 1528 | } else { |
| 1529 | if (rhs.IsFpuRegister()) { |
| 1530 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1531 | } else if (const_area != nullptr) { |
| 1532 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1533 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1534 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1535 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1536 | const_area->GetBaseMethodAddress(), |
| 1537 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1538 | } else { |
| 1539 | DCHECK(rhs.IsStackSlot()); |
| 1540 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1541 | } |
| 1542 | } |
| 1543 | } |
| 1544 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1545 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1546 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1547 | LabelType* true_target_in, |
| 1548 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1549 | // Generated branching requires both targets to be explicit. If either of the |
| 1550 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1551 | LabelType fallthrough_target; |
| 1552 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1553 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1554 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1555 | LocationSummary* locations = condition->GetLocations(); |
| 1556 | Location left = locations->InAt(0); |
| 1557 | Location right = locations->InAt(1); |
| 1558 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1559 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1560 | switch (type) { |
| 1561 | case Primitive::kPrimLong: |
| 1562 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1563 | break; |
| 1564 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1565 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1566 | GenerateFPJumps(condition, true_target, false_target); |
| 1567 | break; |
| 1568 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1569 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1570 | GenerateFPJumps(condition, true_target, false_target); |
| 1571 | break; |
| 1572 | default: |
| 1573 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1574 | } |
| 1575 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1576 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1577 | __ jmp(false_target); |
| 1578 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1579 | |
| 1580 | if (fallthrough_target.IsLinked()) { |
| 1581 | __ Bind(&fallthrough_target); |
| 1582 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1583 | } |
| 1584 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1585 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1586 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1587 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1588 | // conditions if they are materialized due to the complex branching. |
| 1589 | return cond->IsCondition() && |
| 1590 | cond->GetNext() == branch && |
| 1591 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1592 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1593 | } |
| 1594 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1595 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1596 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1597 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1598 | LabelType* true_target, |
| 1599 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1600 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1601 | |
| 1602 | if (true_target == nullptr && false_target == nullptr) { |
| 1603 | // Nothing to do. The code always falls through. |
| 1604 | return; |
| 1605 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1606 | // Constant condition, statically compared against "true" (integer value 1). |
| 1607 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1608 | if (true_target != nullptr) { |
| 1609 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1610 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1611 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1612 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1613 | if (false_target != nullptr) { |
| 1614 | __ jmp(false_target); |
| 1615 | } |
| 1616 | } |
| 1617 | return; |
| 1618 | } |
| 1619 | |
| 1620 | // The following code generates these patterns: |
| 1621 | // (1) true_target == nullptr && false_target != nullptr |
| 1622 | // - opposite condition true => branch to false_target |
| 1623 | // (2) true_target != nullptr && false_target == nullptr |
| 1624 | // - condition true => branch to true_target |
| 1625 | // (3) true_target != nullptr && false_target != nullptr |
| 1626 | // - condition true => branch to true_target |
| 1627 | // - branch to false_target |
| 1628 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1629 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1630 | if (true_target == nullptr) { |
| 1631 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1632 | } else { |
| 1633 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1634 | } |
| 1635 | } else { |
| 1636 | // Materialized condition, compare against 0. |
| 1637 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1638 | if (lhs.IsRegister()) { |
| 1639 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1640 | } else { |
| 1641 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1642 | } |
| 1643 | if (true_target == nullptr) { |
| 1644 | __ j(kEqual, false_target); |
| 1645 | } else { |
| 1646 | __ j(kNotEqual, true_target); |
| 1647 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1648 | } |
| 1649 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1650 | // Condition has not been materialized, use its inputs as the comparison and |
| 1651 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1652 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1653 | |
| 1654 | // If this is a long or FP comparison that has been folded into |
| 1655 | // the HCondition, generate the comparison directly. |
| 1656 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1657 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1658 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1659 | return; |
| 1660 | } |
| 1661 | |
| 1662 | Location lhs = condition->GetLocations()->InAt(0); |
| 1663 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1664 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1665 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1666 | if (true_target == nullptr) { |
| 1667 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1668 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1669 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1670 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1671 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1672 | |
| 1673 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1674 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1675 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1676 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1680 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1681 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1682 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1683 | locations->SetInAt(0, Location::Any()); |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1688 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1689 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1690 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1691 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1692 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1693 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1694 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1698 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1699 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1700 | InvokeRuntimeCallingConvention calling_convention; |
| 1701 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1702 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1703 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1704 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1705 | locations->SetInAt(0, Location::Any()); |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1710 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1711 | GenerateTestAndBranch<Label>(deoptimize, |
| 1712 | /* condition_input_index */ 0, |
| 1713 | slow_path->GetEntryLabel(), |
| 1714 | /* false_target */ nullptr); |
| 1715 | } |
| 1716 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1717 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1718 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1719 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1720 | locations->SetOut(Location::RequiresRegister()); |
| 1721 | } |
| 1722 | |
| 1723 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1724 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1725 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1726 | } |
| 1727 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1728 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1729 | // There are no conditional move instructions for XMMs. |
| 1730 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1731 | return false; |
| 1732 | } |
| 1733 | |
| 1734 | // A FP condition doesn't generate the single CC that we need. |
| 1735 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1736 | HInstruction* condition = select->GetCondition(); |
| 1737 | if (condition->IsCondition()) { |
| 1738 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1739 | if (compare_type == Primitive::kPrimLong || |
| 1740 | Primitive::IsFloatingPointType(compare_type)) { |
| 1741 | return false; |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | // We can generate a CMOV for this Select. |
| 1746 | return true; |
| 1747 | } |
| 1748 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1749 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1750 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1751 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1752 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1753 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1754 | } else { |
| 1755 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1756 | if (SelectCanUseCMOV(select)) { |
| 1757 | if (select->InputAt(1)->IsConstant()) { |
| 1758 | // Cmov can't handle a constant value. |
| 1759 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1760 | } else { |
| 1761 | locations->SetInAt(1, Location::Any()); |
| 1762 | } |
| 1763 | } else { |
| 1764 | locations->SetInAt(1, Location::Any()); |
| 1765 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1766 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1767 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1768 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1769 | } |
| 1770 | locations->SetOut(Location::SameAsFirstInput()); |
| 1771 | } |
| 1772 | |
| 1773 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1774 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1775 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1776 | if (SelectCanUseCMOV(select)) { |
| 1777 | // If both the condition and the source types are integer, we can generate |
| 1778 | // a CMOV to implement Select. |
| 1779 | |
| 1780 | HInstruction* select_condition = select->GetCondition(); |
| 1781 | Condition cond = kNotEqual; |
| 1782 | |
| 1783 | // Figure out how to test the 'condition'. |
| 1784 | if (select_condition->IsCondition()) { |
| 1785 | HCondition* condition = select_condition->AsCondition(); |
| 1786 | if (!condition->IsEmittedAtUseSite()) { |
| 1787 | // This was a previously materialized condition. |
| 1788 | // Can we use the existing condition code? |
| 1789 | if (AreEflagsSetFrom(condition, select)) { |
| 1790 | // Materialization was the previous instruction. Condition codes are right. |
| 1791 | cond = X86Condition(condition->GetCondition()); |
| 1792 | } else { |
| 1793 | // No, we have to recreate the condition code. |
| 1794 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1795 | __ testl(cond_reg, cond_reg); |
| 1796 | } |
| 1797 | } else { |
| 1798 | // We can't handle FP or long here. |
| 1799 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1800 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1801 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1802 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1803 | cond = X86Condition(condition->GetCondition()); |
| 1804 | } |
| 1805 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1806 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1807 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1808 | __ testl(cond_reg, cond_reg); |
| 1809 | } |
| 1810 | |
| 1811 | // If the condition is true, overwrite the output, which already contains false. |
| 1812 | Location false_loc = locations->InAt(0); |
| 1813 | Location true_loc = locations->InAt(1); |
| 1814 | if (select->GetType() == Primitive::kPrimLong) { |
| 1815 | // 64 bit conditional move. |
| 1816 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1817 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1818 | if (true_loc.IsRegisterPair()) { |
| 1819 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1820 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1821 | } else { |
| 1822 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1823 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1824 | } |
| 1825 | } else { |
| 1826 | // 32 bit conditional move. |
| 1827 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1828 | if (true_loc.IsRegister()) { |
| 1829 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1830 | } else { |
| 1831 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1832 | } |
| 1833 | } |
| 1834 | } else { |
| 1835 | NearLabel false_target; |
| 1836 | GenerateTestAndBranch<NearLabel>( |
| 1837 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1838 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1839 | __ Bind(&false_target); |
| 1840 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1843 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1844 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1845 | } |
| 1846 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1847 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1848 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | void CodeGeneratorX86::GenerateNop() { |
| 1852 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1853 | } |
| 1854 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1855 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1856 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1857 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1858 | // Handle the long/FP comparisons made in instruction simplification. |
| 1859 | switch (cond->InputAt(0)->GetType()) { |
| 1860 | case Primitive::kPrimLong: { |
| 1861 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1862 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1863 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1864 | locations->SetOut(Location::RequiresRegister()); |
| 1865 | } |
| 1866 | break; |
| 1867 | } |
| 1868 | case Primitive::kPrimFloat: |
| 1869 | case Primitive::kPrimDouble: { |
| 1870 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1871 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1872 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1873 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1874 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1875 | } else { |
| 1876 | locations->SetInAt(1, Location::Any()); |
| 1877 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1878 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1879 | locations->SetOut(Location::RequiresRegister()); |
| 1880 | } |
| 1881 | break; |
| 1882 | } |
| 1883 | default: |
| 1884 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1885 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1886 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1887 | // We need a byte register. |
| 1888 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1889 | } |
| 1890 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1891 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1894 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1895 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1896 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1897 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1898 | |
| 1899 | LocationSummary* locations = cond->GetLocations(); |
| 1900 | Location lhs = locations->InAt(0); |
| 1901 | Location rhs = locations->InAt(1); |
| 1902 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1903 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1904 | |
| 1905 | switch (cond->InputAt(0)->GetType()) { |
| 1906 | default: { |
| 1907 | // Integer case. |
| 1908 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1909 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1910 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1911 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1912 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1913 | return; |
| 1914 | } |
| 1915 | case Primitive::kPrimLong: |
| 1916 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1917 | break; |
| 1918 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1919 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1920 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1921 | break; |
| 1922 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1923 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1924 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1925 | break; |
| 1926 | } |
| 1927 | |
| 1928 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1929 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1930 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1931 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1932 | __ Bind(&false_label); |
| 1933 | __ xorl(reg, reg); |
| 1934 | __ jmp(&done_label); |
| 1935 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1936 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1937 | __ Bind(&true_label); |
| 1938 | __ movl(reg, Immediate(1)); |
| 1939 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1943 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1947 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1951 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1955 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1959 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1963 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1967 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1971 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1975 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1979 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1983 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1987 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1990 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1991 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1995 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1999 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2003 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2007 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2011 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2015 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2019 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2022 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2023 | LocationSummary* locations = |
| 2024 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2025 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2028 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2029 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2032 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2033 | LocationSummary* locations = |
| 2034 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2035 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2036 | } |
| 2037 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2038 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2039 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2042 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2043 | LocationSummary* locations = |
| 2044 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2045 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2046 | } |
| 2047 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2048 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2049 | // Will be generated at use site. |
| 2050 | } |
| 2051 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2052 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2053 | LocationSummary* locations = |
| 2054 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2055 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2056 | } |
| 2057 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2058 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2059 | // Will be generated at use site. |
| 2060 | } |
| 2061 | |
| 2062 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2063 | LocationSummary* locations = |
| 2064 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2065 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2066 | } |
| 2067 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2068 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2069 | // Will be generated at use site. |
| 2070 | } |
| 2071 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2072 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2073 | constructor_fence->SetLocations(nullptr); |
| 2074 | } |
| 2075 | |
| 2076 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2077 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2078 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2079 | } |
| 2080 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2081 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2082 | memory_barrier->SetLocations(nullptr); |
| 2083 | } |
| 2084 | |
| 2085 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2086 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2087 | } |
| 2088 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2089 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2090 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2091 | } |
| 2092 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2093 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2094 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2097 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2098 | LocationSummary* locations = |
| 2099 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2100 | switch (ret->InputAt(0)->GetType()) { |
| 2101 | case Primitive::kPrimBoolean: |
| 2102 | case Primitive::kPrimByte: |
| 2103 | case Primitive::kPrimChar: |
| 2104 | case Primitive::kPrimShort: |
| 2105 | case Primitive::kPrimInt: |
| 2106 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2107 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2108 | break; |
| 2109 | |
| 2110 | case Primitive::kPrimLong: |
| 2111 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2112 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2113 | break; |
| 2114 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2115 | case Primitive::kPrimFloat: |
| 2116 | case Primitive::kPrimDouble: |
| 2117 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2118 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2119 | break; |
| 2120 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2121 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2122 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2123 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2126 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2127 | if (kIsDebugBuild) { |
| 2128 | switch (ret->InputAt(0)->GetType()) { |
| 2129 | case Primitive::kPrimBoolean: |
| 2130 | case Primitive::kPrimByte: |
| 2131 | case Primitive::kPrimChar: |
| 2132 | case Primitive::kPrimShort: |
| 2133 | case Primitive::kPrimInt: |
| 2134 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2135 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2136 | break; |
| 2137 | |
| 2138 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2139 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2140 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2141 | break; |
| 2142 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2143 | case Primitive::kPrimFloat: |
| 2144 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2145 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2146 | break; |
| 2147 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2148 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2149 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2150 | } |
| 2151 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2152 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2153 | } |
| 2154 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2155 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2156 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2157 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2158 | // the method_idx. |
| 2159 | HandleInvoke(invoke); |
| 2160 | } |
| 2161 | |
| 2162 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2163 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2164 | } |
| 2165 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2166 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2167 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2168 | // art::PrepareForRegisterAllocation. |
| 2169 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2170 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2171 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2172 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2173 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2174 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2175 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2176 | return; |
| 2177 | } |
| 2178 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2179 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2180 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2181 | // 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] | 2182 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2183 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2184 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2185 | } |
| 2186 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2187 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2188 | if (invoke->GetLocations()->Intrinsified()) { |
| 2189 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2190 | intrinsic.Dispatch(invoke); |
| 2191 | return true; |
| 2192 | } |
| 2193 | return false; |
| 2194 | } |
| 2195 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2196 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2197 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2198 | // art::PrepareForRegisterAllocation. |
| 2199 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2200 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2201 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2202 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2203 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2204 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2205 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2206 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2207 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2211 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2212 | if (intrinsic.TryDispatch(invoke)) { |
| 2213 | return; |
| 2214 | } |
| 2215 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2216 | HandleInvoke(invoke); |
| 2217 | } |
| 2218 | |
| 2219 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2220 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2221 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2222 | } |
| 2223 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2224 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2225 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2226 | return; |
| 2227 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2228 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2229 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2230 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2233 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2234 | // This call to HandleInvoke allocates a temporary (core) register |
| 2235 | // which is also used to transfer the hidden argument from FP to |
| 2236 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2237 | HandleInvoke(invoke); |
| 2238 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2239 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2243 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2244 | LocationSummary* locations = invoke->GetLocations(); |
| 2245 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2246 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2247 | Location receiver = locations->InAt(0); |
| 2248 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2249 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2250 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2251 | // won't be modified thereafter, before the `call` instruction. |
| 2252 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2253 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2254 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2255 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2256 | if (receiver.IsStackSlot()) { |
| 2257 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2258 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2259 | __ movl(temp, Address(temp, class_offset)); |
| 2260 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2261 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2262 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2263 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2264 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2265 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2266 | // emit a read barrier for the previous class reference load. |
| 2267 | // However this is not required in practice, as this is an |
| 2268 | // intermediate/temporary reference and because the current |
| 2269 | // concurrent copying collector keeps the from-space memory |
| 2270 | // intact/accessible until the end of the marking phase (the |
| 2271 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2272 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2273 | // temp = temp->GetAddressOfIMT() |
| 2274 | __ movl(temp, |
| 2275 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2276 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2277 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2278 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2279 | __ movl(temp, Address(temp, method_offset)); |
| 2280 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2281 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2282 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2283 | |
| 2284 | DCHECK(!codegen_->IsLeafMethod()); |
| 2285 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2286 | } |
| 2287 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2288 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2289 | HandleInvoke(invoke); |
| 2290 | } |
| 2291 | |
| 2292 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2293 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2294 | } |
| 2295 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2296 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2297 | LocationSummary* locations = |
| 2298 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2299 | switch (neg->GetResultType()) { |
| 2300 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2301 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2302 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2303 | locations->SetOut(Location::SameAsFirstInput()); |
| 2304 | break; |
| 2305 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2306 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2307 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2308 | locations->SetOut(Location::SameAsFirstInput()); |
| 2309 | locations->AddTemp(Location::RequiresRegister()); |
| 2310 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2311 | break; |
| 2312 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2313 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2314 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2315 | locations->SetOut(Location::SameAsFirstInput()); |
| 2316 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2317 | break; |
| 2318 | |
| 2319 | default: |
| 2320 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2325 | LocationSummary* locations = neg->GetLocations(); |
| 2326 | Location out = locations->Out(); |
| 2327 | Location in = locations->InAt(0); |
| 2328 | switch (neg->GetResultType()) { |
| 2329 | case Primitive::kPrimInt: |
| 2330 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2331 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2332 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2333 | break; |
| 2334 | |
| 2335 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2336 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2337 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2338 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2339 | // Negation is similar to subtraction from zero. The least |
| 2340 | // significant byte triggers a borrow when it is different from |
| 2341 | // zero; to take it into account, add 1 to the most significant |
| 2342 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2343 | // operation. |
| 2344 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2345 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2346 | break; |
| 2347 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2348 | case Primitive::kPrimFloat: { |
| 2349 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2350 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2351 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2352 | // Implement float negation with an exclusive or with value |
| 2353 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2354 | // single-precision floating-point number). |
| 2355 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2356 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2357 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2358 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2359 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2360 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimDouble: { |
| 2362 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2363 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2364 | // Implement double negation with an exclusive or with value |
| 2365 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2366 | // a double-precision floating-point number). |
| 2367 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2368 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2369 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2370 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2371 | |
| 2372 | default: |
| 2373 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2374 | } |
| 2375 | } |
| 2376 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2377 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2378 | LocationSummary* locations = |
| 2379 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2380 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2381 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2382 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2383 | locations->SetOut(Location::SameAsFirstInput()); |
| 2384 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2385 | } |
| 2386 | |
| 2387 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2388 | LocationSummary* locations = neg->GetLocations(); |
| 2389 | Location out = locations->Out(); |
| 2390 | DCHECK(locations->InAt(0).Equals(out)); |
| 2391 | |
| 2392 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2393 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2394 | if (neg->GetType() == Primitive::kPrimFloat) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2395 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2396 | neg->GetBaseMethodAddress(), |
| 2397 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2398 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2399 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2400 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2401 | neg->GetBaseMethodAddress(), |
| 2402 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2403 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2404 | } |
| 2405 | } |
| 2406 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2407 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2408 | Primitive::Type result_type = conversion->GetResultType(); |
| 2409 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2410 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2411 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2412 | // The float-to-long and double-to-long type conversions rely on a |
| 2413 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2414 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2415 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2416 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2417 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2418 | : LocationSummary::kNoCall; |
| 2419 | LocationSummary* locations = |
| 2420 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2421 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2422 | // The Java language does not allow treating boolean as an integral type but |
| 2423 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2424 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2425 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2426 | case Primitive::kPrimByte: |
| 2427 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2428 | case Primitive::kPrimLong: { |
| 2429 | // Type conversion from long to byte is a result of code transformations. |
| 2430 | HInstruction* input = conversion->InputAt(0); |
| 2431 | Location input_location = input->IsConstant() |
| 2432 | ? Location::ConstantLocation(input->AsConstant()) |
| 2433 | : Location::RegisterPairLocation(EAX, EDX); |
| 2434 | locations->SetInAt(0, input_location); |
| 2435 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2436 | // the validation of the linear scan implementation |
| 2437 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2438 | break; |
| 2439 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2440 | case Primitive::kPrimBoolean: |
| 2441 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2442 | case Primitive::kPrimShort: |
| 2443 | case Primitive::kPrimInt: |
| 2444 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2445 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2446 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2447 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2448 | // the validation of the linear scan implementation |
| 2449 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2450 | break; |
| 2451 | |
| 2452 | default: |
| 2453 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2454 | << " to " << result_type; |
| 2455 | } |
| 2456 | break; |
| 2457 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimShort: |
| 2459 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimLong: |
| 2461 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2462 | case Primitive::kPrimBoolean: |
| 2463 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2464 | case Primitive::kPrimByte: |
| 2465 | case Primitive::kPrimInt: |
| 2466 | case Primitive::kPrimChar: |
| 2467 | // Processing a Dex `int-to-short' instruction. |
| 2468 | locations->SetInAt(0, Location::Any()); |
| 2469 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2470 | break; |
| 2471 | |
| 2472 | default: |
| 2473 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2474 | << " to " << result_type; |
| 2475 | } |
| 2476 | break; |
| 2477 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2478 | case Primitive::kPrimInt: |
| 2479 | switch (input_type) { |
| 2480 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2481 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2482 | locations->SetInAt(0, Location::Any()); |
| 2483 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2484 | break; |
| 2485 | |
| 2486 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2487 | // Processing a Dex `float-to-int' instruction. |
| 2488 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2489 | locations->SetOut(Location::RequiresRegister()); |
| 2490 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2491 | break; |
| 2492 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2493 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2494 | // Processing a Dex `double-to-int' instruction. |
| 2495 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2496 | locations->SetOut(Location::RequiresRegister()); |
| 2497 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2498 | break; |
| 2499 | |
| 2500 | default: |
| 2501 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2502 | << " to " << result_type; |
| 2503 | } |
| 2504 | break; |
| 2505 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2506 | case Primitive::kPrimLong: |
| 2507 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2508 | case Primitive::kPrimBoolean: |
| 2509 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2510 | case Primitive::kPrimByte: |
| 2511 | case Primitive::kPrimShort: |
| 2512 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2513 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2514 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2515 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2516 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2517 | break; |
| 2518 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2519 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2520 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2521 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2522 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2523 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2524 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2525 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2526 | // The runtime helper puts the result in EAX, EDX. |
| 2527 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2528 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2529 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2530 | |
| 2531 | default: |
| 2532 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2533 | << " to " << result_type; |
| 2534 | } |
| 2535 | break; |
| 2536 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2537 | case Primitive::kPrimChar: |
| 2538 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2539 | case Primitive::kPrimLong: |
| 2540 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2541 | case Primitive::kPrimBoolean: |
| 2542 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2543 | case Primitive::kPrimByte: |
| 2544 | case Primitive::kPrimShort: |
| 2545 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2546 | // Processing a Dex `int-to-char' instruction. |
| 2547 | locations->SetInAt(0, Location::Any()); |
| 2548 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2549 | break; |
| 2550 | |
| 2551 | default: |
| 2552 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2553 | << " to " << result_type; |
| 2554 | } |
| 2555 | break; |
| 2556 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2557 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2558 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2559 | case Primitive::kPrimBoolean: |
| 2560 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2561 | case Primitive::kPrimByte: |
| 2562 | case Primitive::kPrimShort: |
| 2563 | case Primitive::kPrimInt: |
| 2564 | case Primitive::kPrimChar: |
| 2565 | // Processing a Dex `int-to-float' instruction. |
| 2566 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2567 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2568 | break; |
| 2569 | |
| 2570 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2571 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2572 | locations->SetInAt(0, Location::Any()); |
| 2573 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2574 | break; |
| 2575 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2576 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2577 | // Processing a Dex `double-to-float' instruction. |
| 2578 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2579 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2580 | break; |
| 2581 | |
| 2582 | default: |
| 2583 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2584 | << " to " << result_type; |
| 2585 | }; |
| 2586 | break; |
| 2587 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2589 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimBoolean: |
| 2591 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2592 | case Primitive::kPrimByte: |
| 2593 | case Primitive::kPrimShort: |
| 2594 | case Primitive::kPrimInt: |
| 2595 | case Primitive::kPrimChar: |
| 2596 | // Processing a Dex `int-to-double' instruction. |
| 2597 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2598 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2599 | break; |
| 2600 | |
| 2601 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2602 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2603 | locations->SetInAt(0, Location::Any()); |
| 2604 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2605 | break; |
| 2606 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2607 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2608 | // Processing a Dex `float-to-double' instruction. |
| 2609 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2610 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2611 | break; |
| 2612 | |
| 2613 | default: |
| 2614 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2615 | << " to " << result_type; |
| 2616 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2617 | break; |
| 2618 | |
| 2619 | default: |
| 2620 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2621 | << " to " << result_type; |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2626 | LocationSummary* locations = conversion->GetLocations(); |
| 2627 | Location out = locations->Out(); |
| 2628 | Location in = locations->InAt(0); |
| 2629 | Primitive::Type result_type = conversion->GetResultType(); |
| 2630 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2631 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2632 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2633 | case Primitive::kPrimByte: |
| 2634 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2635 | case Primitive::kPrimLong: |
| 2636 | // Type conversion from long to byte is a result of code transformations. |
| 2637 | if (in.IsRegisterPair()) { |
| 2638 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2639 | } else { |
| 2640 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2641 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2642 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2643 | } |
| 2644 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2645 | case Primitive::kPrimBoolean: |
| 2646 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2647 | case Primitive::kPrimShort: |
| 2648 | case Primitive::kPrimInt: |
| 2649 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2650 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2651 | if (in.IsRegister()) { |
| 2652 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2653 | } else { |
| 2654 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2655 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2656 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2657 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2658 | break; |
| 2659 | |
| 2660 | default: |
| 2661 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2662 | << " to " << result_type; |
| 2663 | } |
| 2664 | break; |
| 2665 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2666 | case Primitive::kPrimShort: |
| 2667 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2668 | case Primitive::kPrimLong: |
| 2669 | // Type conversion from long to short is a result of code transformations. |
| 2670 | if (in.IsRegisterPair()) { |
| 2671 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2672 | } else if (in.IsDoubleStackSlot()) { |
| 2673 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2674 | } else { |
| 2675 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2676 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2677 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2678 | } |
| 2679 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimBoolean: |
| 2681 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2682 | case Primitive::kPrimByte: |
| 2683 | case Primitive::kPrimInt: |
| 2684 | case Primitive::kPrimChar: |
| 2685 | // Processing a Dex `int-to-short' instruction. |
| 2686 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2687 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2688 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2689 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2690 | } else { |
| 2691 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2692 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2693 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2694 | } |
| 2695 | break; |
| 2696 | |
| 2697 | default: |
| 2698 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2699 | << " to " << result_type; |
| 2700 | } |
| 2701 | break; |
| 2702 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2703 | case Primitive::kPrimInt: |
| 2704 | switch (input_type) { |
| 2705 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2706 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2707 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2708 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2709 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2710 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2711 | } else { |
| 2712 | DCHECK(in.IsConstant()); |
| 2713 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2714 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2715 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2716 | } |
| 2717 | break; |
| 2718 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2719 | case Primitive::kPrimFloat: { |
| 2720 | // Processing a Dex `float-to-int' instruction. |
| 2721 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2722 | Register output = out.AsRegister<Register>(); |
| 2723 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2724 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2725 | |
| 2726 | __ movl(output, Immediate(kPrimIntMax)); |
| 2727 | // temp = int-to-float(output) |
| 2728 | __ cvtsi2ss(temp, output); |
| 2729 | // if input >= temp goto done |
| 2730 | __ comiss(input, temp); |
| 2731 | __ j(kAboveEqual, &done); |
| 2732 | // if input == NaN goto nan |
| 2733 | __ j(kUnordered, &nan); |
| 2734 | // output = float-to-int-truncate(input) |
| 2735 | __ cvttss2si(output, input); |
| 2736 | __ jmp(&done); |
| 2737 | __ Bind(&nan); |
| 2738 | // output = 0 |
| 2739 | __ xorl(output, output); |
| 2740 | __ Bind(&done); |
| 2741 | break; |
| 2742 | } |
| 2743 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2744 | case Primitive::kPrimDouble: { |
| 2745 | // Processing a Dex `double-to-int' instruction. |
| 2746 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2747 | Register output = out.AsRegister<Register>(); |
| 2748 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2749 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2750 | |
| 2751 | __ movl(output, Immediate(kPrimIntMax)); |
| 2752 | // temp = int-to-double(output) |
| 2753 | __ cvtsi2sd(temp, output); |
| 2754 | // if input >= temp goto done |
| 2755 | __ comisd(input, temp); |
| 2756 | __ j(kAboveEqual, &done); |
| 2757 | // if input == NaN goto nan |
| 2758 | __ j(kUnordered, &nan); |
| 2759 | // output = double-to-int-truncate(input) |
| 2760 | __ cvttsd2si(output, input); |
| 2761 | __ jmp(&done); |
| 2762 | __ Bind(&nan); |
| 2763 | // output = 0 |
| 2764 | __ xorl(output, output); |
| 2765 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2766 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2767 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2768 | |
| 2769 | default: |
| 2770 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2771 | << " to " << result_type; |
| 2772 | } |
| 2773 | break; |
| 2774 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2775 | case Primitive::kPrimLong: |
| 2776 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2777 | case Primitive::kPrimBoolean: |
| 2778 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2779 | case Primitive::kPrimByte: |
| 2780 | case Primitive::kPrimShort: |
| 2781 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2782 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2783 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2784 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2785 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2786 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2787 | __ cdq(); |
| 2788 | break; |
| 2789 | |
| 2790 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2791 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2792 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2793 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2794 | break; |
| 2795 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2796 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2797 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2798 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2799 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2800 | break; |
| 2801 | |
| 2802 | default: |
| 2803 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2804 | << " to " << result_type; |
| 2805 | } |
| 2806 | break; |
| 2807 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2808 | case Primitive::kPrimChar: |
| 2809 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2810 | case Primitive::kPrimLong: |
| 2811 | // Type conversion from long to short is a result of code transformations. |
| 2812 | if (in.IsRegisterPair()) { |
| 2813 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2814 | } else if (in.IsDoubleStackSlot()) { |
| 2815 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2816 | } else { |
| 2817 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2818 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2819 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2820 | } |
| 2821 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2822 | case Primitive::kPrimBoolean: |
| 2823 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2824 | case Primitive::kPrimByte: |
| 2825 | case Primitive::kPrimShort: |
| 2826 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2827 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2828 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2829 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2830 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2831 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2832 | } else { |
| 2833 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2834 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2835 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2836 | } |
| 2837 | break; |
| 2838 | |
| 2839 | default: |
| 2840 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2841 | << " to " << result_type; |
| 2842 | } |
| 2843 | break; |
| 2844 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2845 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2846 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2847 | case Primitive::kPrimBoolean: |
| 2848 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2849 | case Primitive::kPrimByte: |
| 2850 | case Primitive::kPrimShort: |
| 2851 | case Primitive::kPrimInt: |
| 2852 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2853 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2854 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2855 | break; |
| 2856 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2857 | case Primitive::kPrimLong: { |
| 2858 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2859 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2860 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2861 | // Create stack space for the call to |
| 2862 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2863 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2864 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2865 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2866 | __ subl(ESP, Immediate(adjustment)); |
| 2867 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2868 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2869 | // Load the value to the FP stack, using temporaries if needed. |
| 2870 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2871 | |
| 2872 | if (out.IsStackSlot()) { |
| 2873 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2874 | } else { |
| 2875 | __ fstps(Address(ESP, 0)); |
| 2876 | Location stack_temp = Location::StackSlot(0); |
| 2877 | codegen_->Move32(out, stack_temp); |
| 2878 | } |
| 2879 | |
| 2880 | // Remove the temporary stack space we allocated. |
| 2881 | if (adjustment != 0) { |
| 2882 | __ addl(ESP, Immediate(adjustment)); |
| 2883 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2884 | break; |
| 2885 | } |
| 2886 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2887 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2888 | // Processing a Dex `double-to-float' instruction. |
| 2889 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2890 | break; |
| 2891 | |
| 2892 | default: |
| 2893 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2894 | << " to " << result_type; |
| 2895 | }; |
| 2896 | break; |
| 2897 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2898 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2899 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2900 | case Primitive::kPrimBoolean: |
| 2901 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2902 | case Primitive::kPrimByte: |
| 2903 | case Primitive::kPrimShort: |
| 2904 | case Primitive::kPrimInt: |
| 2905 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2906 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2907 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2908 | break; |
| 2909 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2910 | case Primitive::kPrimLong: { |
| 2911 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2912 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2913 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2914 | // Create stack space for the call to |
| 2915 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2916 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2917 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2918 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2919 | __ subl(ESP, Immediate(adjustment)); |
| 2920 | } |
| 2921 | |
| 2922 | // Load the value to the FP stack, using temporaries if needed. |
| 2923 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2924 | |
| 2925 | if (out.IsDoubleStackSlot()) { |
| 2926 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2927 | } else { |
| 2928 | __ fstpl(Address(ESP, 0)); |
| 2929 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2930 | codegen_->Move64(out, stack_temp); |
| 2931 | } |
| 2932 | |
| 2933 | // Remove the temporary stack space we allocated. |
| 2934 | if (adjustment != 0) { |
| 2935 | __ addl(ESP, Immediate(adjustment)); |
| 2936 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2937 | break; |
| 2938 | } |
| 2939 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2940 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2941 | // Processing a Dex `float-to-double' instruction. |
| 2942 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2943 | break; |
| 2944 | |
| 2945 | default: |
| 2946 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2947 | << " to " << result_type; |
| 2948 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2949 | break; |
| 2950 | |
| 2951 | default: |
| 2952 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2953 | << " to " << result_type; |
| 2954 | } |
| 2955 | } |
| 2956 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2957 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2958 | LocationSummary* locations = |
| 2959 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2960 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2961 | case Primitive::kPrimInt: { |
| 2962 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2963 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2964 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2965 | break; |
| 2966 | } |
| 2967 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2968 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2969 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2970 | locations->SetInAt(1, Location::Any()); |
| 2971 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2972 | break; |
| 2973 | } |
| 2974 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2975 | case Primitive::kPrimFloat: |
| 2976 | case Primitive::kPrimDouble: { |
| 2977 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2978 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2979 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2980 | } else if (add->InputAt(1)->IsConstant()) { |
| 2981 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2982 | } else { |
| 2983 | locations->SetInAt(1, Location::Any()); |
| 2984 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2985 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2986 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2987 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2988 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2989 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2990 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2991 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2992 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2996 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2997 | Location first = locations->InAt(0); |
| 2998 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2999 | Location out = locations->Out(); |
| 3000 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3001 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3002 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3003 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3004 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3005 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3006 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3007 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3008 | } else { |
| 3009 | __ leal(out.AsRegister<Register>(), Address( |
| 3010 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3011 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3012 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3013 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3014 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3015 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3016 | } else { |
| 3017 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3018 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3019 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3020 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3021 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3022 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3023 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3027 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3028 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3029 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3030 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3031 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3032 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3033 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3034 | } else { |
| 3035 | DCHECK(second.IsConstant()) << second; |
| 3036 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3037 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3038 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3039 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3040 | break; |
| 3041 | } |
| 3042 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3043 | case Primitive::kPrimFloat: { |
| 3044 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3045 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3046 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3047 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3048 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3049 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3050 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3051 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3052 | const_area->GetBaseMethodAddress(), |
| 3053 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3054 | } else { |
| 3055 | DCHECK(second.IsStackSlot()); |
| 3056 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3057 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3058 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | case Primitive::kPrimDouble: { |
| 3062 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3063 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3064 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3065 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3066 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3067 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3068 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3069 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3070 | const_area->GetBaseMethodAddress(), |
| 3071 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3072 | } else { |
| 3073 | DCHECK(second.IsDoubleStackSlot()); |
| 3074 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3075 | } |
| 3076 | break; |
| 3077 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3078 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3079 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3080 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3081 | } |
| 3082 | } |
| 3083 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3084 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3085 | LocationSummary* locations = |
| 3086 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3087 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3088 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3089 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3090 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3091 | locations->SetInAt(1, Location::Any()); |
| 3092 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3093 | break; |
| 3094 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3095 | case Primitive::kPrimFloat: |
| 3096 | case Primitive::kPrimDouble: { |
| 3097 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3098 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3099 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3100 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3101 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3102 | } else { |
| 3103 | locations->SetInAt(1, Location::Any()); |
| 3104 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3105 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3106 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3107 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3108 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3109 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3110 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3111 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3115 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3116 | Location first = locations->InAt(0); |
| 3117 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3118 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3119 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3120 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3121 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3122 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3123 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3124 | __ subl(first.AsRegister<Register>(), |
| 3125 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3126 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3127 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3128 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3129 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3133 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3134 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3135 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3136 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3137 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3138 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3139 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3140 | } else { |
| 3141 | DCHECK(second.IsConstant()) << second; |
| 3142 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3143 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3144 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3145 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3146 | break; |
| 3147 | } |
| 3148 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3149 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3150 | if (second.IsFpuRegister()) { |
| 3151 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3152 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3153 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3154 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3155 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3156 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3157 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3158 | const_area->GetBaseMethodAddress(), |
| 3159 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3160 | } else { |
| 3161 | DCHECK(second.IsStackSlot()); |
| 3162 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3163 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3164 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3168 | if (second.IsFpuRegister()) { |
| 3169 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3170 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3171 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3172 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3173 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3174 | codegen_->LiteralDoubleAddress( |
| 3175 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3176 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3177 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3178 | } else { |
| 3179 | DCHECK(second.IsDoubleStackSlot()); |
| 3180 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3181 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3182 | break; |
| 3183 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3184 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3185 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3186 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3190 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3191 | LocationSummary* locations = |
| 3192 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3193 | switch (mul->GetResultType()) { |
| 3194 | case Primitive::kPrimInt: |
| 3195 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3196 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3197 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3198 | // Can use 3 operand multiply. |
| 3199 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3200 | } else { |
| 3201 | locations->SetOut(Location::SameAsFirstInput()); |
| 3202 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3203 | break; |
| 3204 | case Primitive::kPrimLong: { |
| 3205 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3206 | locations->SetInAt(1, Location::Any()); |
| 3207 | locations->SetOut(Location::SameAsFirstInput()); |
| 3208 | // Needed for imul on 32bits with 64bits output. |
| 3209 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3210 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3211 | break; |
| 3212 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3213 | case Primitive::kPrimFloat: |
| 3214 | case Primitive::kPrimDouble: { |
| 3215 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3216 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3217 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3218 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3219 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3220 | } else { |
| 3221 | locations->SetInAt(1, Location::Any()); |
| 3222 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3223 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3224 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3225 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3226 | |
| 3227 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3228 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3229 | } |
| 3230 | } |
| 3231 | |
| 3232 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3233 | LocationSummary* locations = mul->GetLocations(); |
| 3234 | Location first = locations->InAt(0); |
| 3235 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3236 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3237 | |
| 3238 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3239 | case Primitive::kPrimInt: |
| 3240 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3241 | // problems where the output may not be the same as the first operand. |
| 3242 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3243 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3244 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3245 | } else if (second.IsRegister()) { |
| 3246 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3247 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3248 | } else { |
| 3249 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3250 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3251 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3252 | } |
| 3253 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3254 | |
| 3255 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3256 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3257 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3258 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3259 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3260 | |
| 3261 | DCHECK_EQ(EAX, eax); |
| 3262 | DCHECK_EQ(EDX, edx); |
| 3263 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3264 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3265 | // output: in1 |
| 3266 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3267 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3268 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3269 | if (second.IsConstant()) { |
| 3270 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3271 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3272 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3273 | int32_t low_value = Low32Bits(value); |
| 3274 | int32_t high_value = High32Bits(value); |
| 3275 | Immediate low(low_value); |
| 3276 | Immediate high(high_value); |
| 3277 | |
| 3278 | __ movl(eax, high); |
| 3279 | // eax <- in1.lo * in2.hi |
| 3280 | __ imull(eax, in1_lo); |
| 3281 | // in1.hi <- in1.hi * in2.lo |
| 3282 | __ imull(in1_hi, low); |
| 3283 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3284 | __ addl(in1_hi, eax); |
| 3285 | // move in2_lo to eax to prepare for double precision |
| 3286 | __ movl(eax, low); |
| 3287 | // edx:eax <- in1.lo * in2.lo |
| 3288 | __ mull(in1_lo); |
| 3289 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3290 | __ addl(in1_hi, edx); |
| 3291 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3292 | __ movl(in1_lo, eax); |
| 3293 | } else if (second.IsRegisterPair()) { |
| 3294 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3295 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3296 | |
| 3297 | __ movl(eax, in2_hi); |
| 3298 | // eax <- in1.lo * in2.hi |
| 3299 | __ imull(eax, in1_lo); |
| 3300 | // in1.hi <- in1.hi * in2.lo |
| 3301 | __ imull(in1_hi, in2_lo); |
| 3302 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3303 | __ addl(in1_hi, eax); |
| 3304 | // move in1_lo to eax to prepare for double precision |
| 3305 | __ movl(eax, in1_lo); |
| 3306 | // edx:eax <- in1.lo * in2.lo |
| 3307 | __ mull(in2_lo); |
| 3308 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3309 | __ addl(in1_hi, edx); |
| 3310 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3311 | __ movl(in1_lo, eax); |
| 3312 | } else { |
| 3313 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3314 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3315 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3316 | |
| 3317 | __ movl(eax, in2_hi); |
| 3318 | // eax <- in1.lo * in2.hi |
| 3319 | __ imull(eax, in1_lo); |
| 3320 | // in1.hi <- in1.hi * in2.lo |
| 3321 | __ imull(in1_hi, in2_lo); |
| 3322 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3323 | __ addl(in1_hi, eax); |
| 3324 | // move in1_lo to eax to prepare for double precision |
| 3325 | __ movl(eax, in1_lo); |
| 3326 | // edx:eax <- in1.lo * in2.lo |
| 3327 | __ mull(in2_lo); |
| 3328 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3329 | __ addl(in1_hi, edx); |
| 3330 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3331 | __ movl(in1_lo, eax); |
| 3332 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3333 | |
| 3334 | break; |
| 3335 | } |
| 3336 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3337 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3338 | DCHECK(first.Equals(locations->Out())); |
| 3339 | if (second.IsFpuRegister()) { |
| 3340 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3341 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3342 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3343 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3344 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3345 | codegen_->LiteralFloatAddress( |
| 3346 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3347 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3348 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3349 | } else { |
| 3350 | DCHECK(second.IsStackSlot()); |
| 3351 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3352 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3353 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3357 | DCHECK(first.Equals(locations->Out())); |
| 3358 | if (second.IsFpuRegister()) { |
| 3359 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3360 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3361 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3362 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3363 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3364 | codegen_->LiteralDoubleAddress( |
| 3365 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3366 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3367 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3368 | } else { |
| 3369 | DCHECK(second.IsDoubleStackSlot()); |
| 3370 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3371 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3372 | break; |
| 3373 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3374 | |
| 3375 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3376 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3377 | } |
| 3378 | } |
| 3379 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3380 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3381 | uint32_t temp_offset, |
| 3382 | uint32_t stack_adjustment, |
| 3383 | bool is_fp, |
| 3384 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3385 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3386 | DCHECK(!is_wide); |
| 3387 | if (is_fp) { |
| 3388 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3389 | } else { |
| 3390 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3391 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3392 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3393 | DCHECK(is_wide); |
| 3394 | if (is_fp) { |
| 3395 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3396 | } else { |
| 3397 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3398 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3399 | } else { |
| 3400 | // 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] | 3401 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3402 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3403 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3404 | if (is_fp) { |
| 3405 | __ flds(Address(ESP, temp_offset)); |
| 3406 | } else { |
| 3407 | __ filds(Address(ESP, temp_offset)); |
| 3408 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3409 | } else { |
| 3410 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3411 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3412 | if (is_fp) { |
| 3413 | __ fldl(Address(ESP, temp_offset)); |
| 3414 | } else { |
| 3415 | __ fildl(Address(ESP, temp_offset)); |
| 3416 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3417 | } |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3422 | Primitive::Type type = rem->GetResultType(); |
| 3423 | bool is_float = type == Primitive::kPrimFloat; |
| 3424 | size_t elem_size = Primitive::ComponentSize(type); |
| 3425 | LocationSummary* locations = rem->GetLocations(); |
| 3426 | Location first = locations->InAt(0); |
| 3427 | Location second = locations->InAt(1); |
| 3428 | Location out = locations->Out(); |
| 3429 | |
| 3430 | // Create stack space for 2 elements. |
| 3431 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3432 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3433 | |
| 3434 | // 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] | 3435 | const bool is_wide = !is_float; |
| 3436 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3437 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3438 | |
| 3439 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3440 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3441 | __ Bind(&retry); |
| 3442 | __ fprem(); |
| 3443 | |
| 3444 | // Move FP status to AX. |
| 3445 | __ fstsw(); |
| 3446 | |
| 3447 | // And see if the argument reduction is complete. This is signaled by the |
| 3448 | // C2 FPU flag bit set to 0. |
| 3449 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3450 | __ j(kNotEqual, &retry); |
| 3451 | |
| 3452 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3453 | // Store FP top of stack to real stack. |
| 3454 | if (is_float) { |
| 3455 | __ fsts(Address(ESP, 0)); |
| 3456 | } else { |
| 3457 | __ fstl(Address(ESP, 0)); |
| 3458 | } |
| 3459 | |
| 3460 | // Pop the 2 items from the FP stack. |
| 3461 | __ fucompp(); |
| 3462 | |
| 3463 | // Load the value from the stack into an XMM register. |
| 3464 | DCHECK(out.IsFpuRegister()) << out; |
| 3465 | if (is_float) { |
| 3466 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3467 | } else { |
| 3468 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3469 | } |
| 3470 | |
| 3471 | // And remove the temporary stack space we allocated. |
| 3472 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3473 | } |
| 3474 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3475 | |
| 3476 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3477 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3478 | |
| 3479 | LocationSummary* locations = instruction->GetLocations(); |
| 3480 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3481 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3482 | |
| 3483 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3484 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3485 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3486 | |
| 3487 | DCHECK(imm == 1 || imm == -1); |
| 3488 | |
| 3489 | if (instruction->IsRem()) { |
| 3490 | __ xorl(out_register, out_register); |
| 3491 | } else { |
| 3492 | __ movl(out_register, input_register); |
| 3493 | if (imm == -1) { |
| 3494 | __ negl(out_register); |
| 3495 | } |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3500 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3501 | LocationSummary* locations = instruction->GetLocations(); |
| 3502 | |
| 3503 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3504 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3505 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3506 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3507 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3508 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3509 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3510 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3511 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3512 | __ testl(input_register, input_register); |
| 3513 | __ cmovl(kGreaterEqual, num, input_register); |
| 3514 | int shift = CTZ(imm); |
| 3515 | __ sarl(num, Immediate(shift)); |
| 3516 | |
| 3517 | if (imm < 0) { |
| 3518 | __ negl(num); |
| 3519 | } |
| 3520 | |
| 3521 | __ movl(out_register, num); |
| 3522 | } |
| 3523 | |
| 3524 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3525 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3526 | |
| 3527 | LocationSummary* locations = instruction->GetLocations(); |
| 3528 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3529 | |
| 3530 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3531 | Register out = locations->Out().AsRegister<Register>(); |
| 3532 | Register num; |
| 3533 | Register edx; |
| 3534 | |
| 3535 | if (instruction->IsDiv()) { |
| 3536 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3537 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3538 | } else { |
| 3539 | edx = locations->Out().AsRegister<Register>(); |
| 3540 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3541 | } |
| 3542 | |
| 3543 | DCHECK_EQ(EAX, eax); |
| 3544 | DCHECK_EQ(EDX, edx); |
| 3545 | if (instruction->IsDiv()) { |
| 3546 | DCHECK_EQ(EAX, out); |
| 3547 | } else { |
| 3548 | DCHECK_EQ(EDX, out); |
| 3549 | } |
| 3550 | |
| 3551 | int64_t magic; |
| 3552 | int shift; |
| 3553 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3554 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3555 | // Save the numerator. |
| 3556 | __ movl(num, eax); |
| 3557 | |
| 3558 | // EAX = magic |
| 3559 | __ movl(eax, Immediate(magic)); |
| 3560 | |
| 3561 | // EDX:EAX = magic * numerator |
| 3562 | __ imull(num); |
| 3563 | |
| 3564 | if (imm > 0 && magic < 0) { |
| 3565 | // EDX += num |
| 3566 | __ addl(edx, num); |
| 3567 | } else if (imm < 0 && magic > 0) { |
| 3568 | __ subl(edx, num); |
| 3569 | } |
| 3570 | |
| 3571 | // Shift if needed. |
| 3572 | if (shift != 0) { |
| 3573 | __ sarl(edx, Immediate(shift)); |
| 3574 | } |
| 3575 | |
| 3576 | // EDX += 1 if EDX < 0 |
| 3577 | __ movl(eax, edx); |
| 3578 | __ shrl(edx, Immediate(31)); |
| 3579 | __ addl(edx, eax); |
| 3580 | |
| 3581 | if (instruction->IsRem()) { |
| 3582 | __ movl(eax, num); |
| 3583 | __ imull(edx, Immediate(imm)); |
| 3584 | __ subl(eax, edx); |
| 3585 | __ movl(edx, eax); |
| 3586 | } else { |
| 3587 | __ movl(eax, edx); |
| 3588 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3589 | } |
| 3590 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3591 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3592 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3593 | |
| 3594 | LocationSummary* locations = instruction->GetLocations(); |
| 3595 | Location out = locations->Out(); |
| 3596 | Location first = locations->InAt(0); |
| 3597 | Location second = locations->InAt(1); |
| 3598 | bool is_div = instruction->IsDiv(); |
| 3599 | |
| 3600 | switch (instruction->GetResultType()) { |
| 3601 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3602 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3603 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3604 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3605 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3606 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3607 | |
| 3608 | if (imm == 0) { |
| 3609 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3610 | } else if (imm == 1 || imm == -1) { |
| 3611 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3612 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3613 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3614 | } else { |
| 3615 | DCHECK(imm <= -2 || imm >= 2); |
| 3616 | GenerateDivRemWithAnyConstant(instruction); |
| 3617 | } |
| 3618 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3619 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3620 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3621 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3622 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3623 | Register second_reg = second.AsRegister<Register>(); |
| 3624 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3625 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3626 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3627 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3628 | __ cmpl(second_reg, Immediate(-1)); |
| 3629 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3630 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3631 | // edx:eax <- sign-extended of eax |
| 3632 | __ cdq(); |
| 3633 | // eax = quotient, edx = remainder |
| 3634 | __ idivl(second_reg); |
| 3635 | __ Bind(slow_path->GetExitLabel()); |
| 3636 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3637 | break; |
| 3638 | } |
| 3639 | |
| 3640 | case Primitive::kPrimLong: { |
| 3641 | InvokeRuntimeCallingConvention calling_convention; |
| 3642 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3643 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3644 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3645 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3646 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3647 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3648 | |
| 3649 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3650 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3651 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3652 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3653 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3654 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3655 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3656 | break; |
| 3657 | } |
| 3658 | |
| 3659 | default: |
| 3660 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3661 | } |
| 3662 | } |
| 3663 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3664 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3665 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3666 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3667 | : LocationSummary::kNoCall; |
| 3668 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3669 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3670 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3671 | case Primitive::kPrimInt: { |
| 3672 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3673 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3674 | locations->SetOut(Location::SameAsFirstInput()); |
| 3675 | // Intel uses edx:eax as the dividend. |
| 3676 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3677 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3678 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3679 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3680 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3681 | locations->AddTemp(Location::RequiresRegister()); |
| 3682 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3683 | break; |
| 3684 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3685 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3686 | InvokeRuntimeCallingConvention calling_convention; |
| 3687 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3688 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3689 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3690 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3691 | // Runtime helper puts the result in EAX, EDX. |
| 3692 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3693 | break; |
| 3694 | } |
| 3695 | case Primitive::kPrimFloat: |
| 3696 | case Primitive::kPrimDouble: { |
| 3697 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3698 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3699 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3700 | } else if (div->InputAt(1)->IsConstant()) { |
| 3701 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3702 | } else { |
| 3703 | locations->SetInAt(1, Location::Any()); |
| 3704 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3705 | locations->SetOut(Location::SameAsFirstInput()); |
| 3706 | break; |
| 3707 | } |
| 3708 | |
| 3709 | default: |
| 3710 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3711 | } |
| 3712 | } |
| 3713 | |
| 3714 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3715 | LocationSummary* locations = div->GetLocations(); |
| 3716 | Location first = locations->InAt(0); |
| 3717 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3718 | |
| 3719 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3720 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3721 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3722 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3723 | break; |
| 3724 | } |
| 3725 | |
| 3726 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3727 | if (second.IsFpuRegister()) { |
| 3728 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3729 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3730 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3731 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3732 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3733 | codegen_->LiteralFloatAddress( |
| 3734 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3735 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3736 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3737 | } else { |
| 3738 | DCHECK(second.IsStackSlot()); |
| 3739 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3740 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3741 | break; |
| 3742 | } |
| 3743 | |
| 3744 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3745 | if (second.IsFpuRegister()) { |
| 3746 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3747 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3748 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3749 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3750 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3751 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3752 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3753 | const_area->GetBaseMethodAddress(), |
| 3754 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3755 | } else { |
| 3756 | DCHECK(second.IsDoubleStackSlot()); |
| 3757 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3758 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3759 | break; |
| 3760 | } |
| 3761 | |
| 3762 | default: |
| 3763 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3764 | } |
| 3765 | } |
| 3766 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3767 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3768 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3769 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3770 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3771 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3772 | : LocationSummary::kNoCall; |
| 3773 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3774 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3775 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3776 | case Primitive::kPrimInt: { |
| 3777 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3778 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3779 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3780 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3781 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3782 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3783 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3784 | locations->AddTemp(Location::RequiresRegister()); |
| 3785 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3786 | break; |
| 3787 | } |
| 3788 | case Primitive::kPrimLong: { |
| 3789 | InvokeRuntimeCallingConvention calling_convention; |
| 3790 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3791 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3792 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3793 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3794 | // Runtime helper puts the result in EAX, EDX. |
| 3795 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3796 | break; |
| 3797 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3798 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3799 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3800 | locations->SetInAt(0, Location::Any()); |
| 3801 | locations->SetInAt(1, Location::Any()); |
| 3802 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3803 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3804 | break; |
| 3805 | } |
| 3806 | |
| 3807 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3808 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | |
| 3812 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3813 | Primitive::Type type = rem->GetResultType(); |
| 3814 | switch (type) { |
| 3815 | case Primitive::kPrimInt: |
| 3816 | case Primitive::kPrimLong: { |
| 3817 | GenerateDivRemIntegral(rem); |
| 3818 | break; |
| 3819 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3820 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3821 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3822 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3823 | break; |
| 3824 | } |
| 3825 | default: |
| 3826 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3827 | } |
| 3828 | } |
| 3829 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3830 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3831 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3832 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3833 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3834 | case Primitive::kPrimByte: |
| 3835 | case Primitive::kPrimChar: |
| 3836 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3837 | case Primitive::kPrimInt: { |
| 3838 | locations->SetInAt(0, Location::Any()); |
| 3839 | break; |
| 3840 | } |
| 3841 | case Primitive::kPrimLong: { |
| 3842 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3843 | if (!instruction->IsConstant()) { |
| 3844 | locations->AddTemp(Location::RequiresRegister()); |
| 3845 | } |
| 3846 | break; |
| 3847 | } |
| 3848 | default: |
| 3849 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3850 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3854 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3855 | codegen_->AddSlowPath(slow_path); |
| 3856 | |
| 3857 | LocationSummary* locations = instruction->GetLocations(); |
| 3858 | Location value = locations->InAt(0); |
| 3859 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3860 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3861 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3862 | case Primitive::kPrimByte: |
| 3863 | case Primitive::kPrimChar: |
| 3864 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3865 | case Primitive::kPrimInt: { |
| 3866 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3867 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3868 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3869 | } else if (value.IsStackSlot()) { |
| 3870 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3871 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3872 | } else { |
| 3873 | DCHECK(value.IsConstant()) << value; |
| 3874 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3875 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3876 | } |
| 3877 | } |
| 3878 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3879 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3880 | case Primitive::kPrimLong: { |
| 3881 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3882 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3883 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3884 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3885 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3886 | } else { |
| 3887 | DCHECK(value.IsConstant()) << value; |
| 3888 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3889 | __ jmp(slow_path->GetEntryLabel()); |
| 3890 | } |
| 3891 | } |
| 3892 | break; |
| 3893 | } |
| 3894 | default: |
| 3895 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3896 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3897 | } |
| 3898 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3899 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3900 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3901 | |
| 3902 | LocationSummary* locations = |
| 3903 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3904 | |
| 3905 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3906 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3907 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3908 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3909 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3910 | // The shift count needs to be in CL or a constant. |
| 3911 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3912 | locations->SetOut(Location::SameAsFirstInput()); |
| 3913 | break; |
| 3914 | } |
| 3915 | default: |
| 3916 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3917 | } |
| 3918 | } |
| 3919 | |
| 3920 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3921 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3922 | |
| 3923 | LocationSummary* locations = op->GetLocations(); |
| 3924 | Location first = locations->InAt(0); |
| 3925 | Location second = locations->InAt(1); |
| 3926 | DCHECK(first.Equals(locations->Out())); |
| 3927 | |
| 3928 | switch (op->GetResultType()) { |
| 3929 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3930 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3931 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3932 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3933 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3934 | DCHECK_EQ(ECX, second_reg); |
| 3935 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3936 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3937 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3938 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3939 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3940 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3941 | } |
| 3942 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3943 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3944 | if (shift == 0) { |
| 3945 | return; |
| 3946 | } |
| 3947 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3948 | if (op->IsShl()) { |
| 3949 | __ shll(first_reg, imm); |
| 3950 | } else if (op->IsShr()) { |
| 3951 | __ sarl(first_reg, imm); |
| 3952 | } else { |
| 3953 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3954 | } |
| 3955 | } |
| 3956 | break; |
| 3957 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3958 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3959 | if (second.IsRegister()) { |
| 3960 | Register second_reg = second.AsRegister<Register>(); |
| 3961 | DCHECK_EQ(ECX, second_reg); |
| 3962 | if (op->IsShl()) { |
| 3963 | GenerateShlLong(first, second_reg); |
| 3964 | } else if (op->IsShr()) { |
| 3965 | GenerateShrLong(first, second_reg); |
| 3966 | } else { |
| 3967 | GenerateUShrLong(first, second_reg); |
| 3968 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3969 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3970 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3971 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3972 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3973 | if (shift != 0) { |
| 3974 | if (op->IsShl()) { |
| 3975 | GenerateShlLong(first, shift); |
| 3976 | } else if (op->IsShr()) { |
| 3977 | GenerateShrLong(first, shift); |
| 3978 | } else { |
| 3979 | GenerateUShrLong(first, shift); |
| 3980 | } |
| 3981 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3982 | } |
| 3983 | break; |
| 3984 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3985 | default: |
| 3986 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3987 | } |
| 3988 | } |
| 3989 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3990 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3991 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3992 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3993 | if (shift == 1) { |
| 3994 | // This is just an addition. |
| 3995 | __ addl(low, low); |
| 3996 | __ adcl(high, high); |
| 3997 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3998 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3999 | codegen_->EmitParallelMoves( |
| 4000 | loc.ToLow(), |
| 4001 | loc.ToHigh(), |
| 4002 | Primitive::kPrimInt, |
| 4003 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4004 | loc.ToLow(), |
| 4005 | Primitive::kPrimInt); |
| 4006 | } else if (shift > 32) { |
| 4007 | // Low part becomes 0. High part is low part << (shift-32). |
| 4008 | __ movl(high, low); |
| 4009 | __ shll(high, Immediate(shift - 32)); |
| 4010 | __ xorl(low, low); |
| 4011 | } else { |
| 4012 | // Between 1 and 31. |
| 4013 | __ shld(high, low, Immediate(shift)); |
| 4014 | __ shll(low, Immediate(shift)); |
| 4015 | } |
| 4016 | } |
| 4017 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4018 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4019 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4020 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4021 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4022 | __ testl(shifter, Immediate(32)); |
| 4023 | __ j(kEqual, &done); |
| 4024 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4025 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4026 | __ Bind(&done); |
| 4027 | } |
| 4028 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4029 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4030 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4031 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4032 | if (shift == 32) { |
| 4033 | // Need to copy the sign. |
| 4034 | DCHECK_NE(low, high); |
| 4035 | __ movl(low, high); |
| 4036 | __ sarl(high, Immediate(31)); |
| 4037 | } else if (shift > 32) { |
| 4038 | DCHECK_NE(low, high); |
| 4039 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4040 | __ movl(low, high); |
| 4041 | __ sarl(high, Immediate(31)); |
| 4042 | __ sarl(low, Immediate(shift - 32)); |
| 4043 | } else { |
| 4044 | // Between 1 and 31. |
| 4045 | __ shrd(low, high, Immediate(shift)); |
| 4046 | __ sarl(high, Immediate(shift)); |
| 4047 | } |
| 4048 | } |
| 4049 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4050 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4051 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4052 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4053 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4054 | __ testl(shifter, Immediate(32)); |
| 4055 | __ j(kEqual, &done); |
| 4056 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4057 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4058 | __ Bind(&done); |
| 4059 | } |
| 4060 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4061 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4062 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4063 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4064 | if (shift == 32) { |
| 4065 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4066 | codegen_->EmitParallelMoves( |
| 4067 | loc.ToHigh(), |
| 4068 | loc.ToLow(), |
| 4069 | Primitive::kPrimInt, |
| 4070 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4071 | loc.ToHigh(), |
| 4072 | Primitive::kPrimInt); |
| 4073 | } else if (shift > 32) { |
| 4074 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4075 | __ movl(low, high); |
| 4076 | __ shrl(low, Immediate(shift - 32)); |
| 4077 | __ xorl(high, high); |
| 4078 | } else { |
| 4079 | // Between 1 and 31. |
| 4080 | __ shrd(low, high, Immediate(shift)); |
| 4081 | __ shrl(high, Immediate(shift)); |
| 4082 | } |
| 4083 | } |
| 4084 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4085 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4086 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4087 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4088 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4089 | __ testl(shifter, Immediate(32)); |
| 4090 | __ j(kEqual, &done); |
| 4091 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4092 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4093 | __ Bind(&done); |
| 4094 | } |
| 4095 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4096 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4097 | LocationSummary* locations = |
| 4098 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4099 | |
| 4100 | switch (ror->GetResultType()) { |
| 4101 | case Primitive::kPrimLong: |
| 4102 | // Add the temporary needed. |
| 4103 | locations->AddTemp(Location::RequiresRegister()); |
| 4104 | FALLTHROUGH_INTENDED; |
| 4105 | case Primitive::kPrimInt: |
| 4106 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4107 | // The shift count needs to be in CL (unless it is a constant). |
| 4108 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4109 | locations->SetOut(Location::SameAsFirstInput()); |
| 4110 | break; |
| 4111 | default: |
| 4112 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4113 | UNREACHABLE(); |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4118 | LocationSummary* locations = ror->GetLocations(); |
| 4119 | Location first = locations->InAt(0); |
| 4120 | Location second = locations->InAt(1); |
| 4121 | |
| 4122 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 4123 | Register first_reg = first.AsRegister<Register>(); |
| 4124 | if (second.IsRegister()) { |
| 4125 | Register second_reg = second.AsRegister<Register>(); |
| 4126 | __ rorl(first_reg, second_reg); |
| 4127 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4128 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4129 | __ rorl(first_reg, imm); |
| 4130 | } |
| 4131 | return; |
| 4132 | } |
| 4133 | |
| 4134 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 4135 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4136 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4137 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4138 | if (second.IsRegister()) { |
| 4139 | Register second_reg = second.AsRegister<Register>(); |
| 4140 | DCHECK_EQ(second_reg, ECX); |
| 4141 | __ movl(temp_reg, first_reg_hi); |
| 4142 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4143 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4144 | __ movl(temp_reg, first_reg_hi); |
| 4145 | __ testl(second_reg, Immediate(32)); |
| 4146 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4147 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4148 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4149 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4150 | if (shift_amt == 0) { |
| 4151 | // Already fine. |
| 4152 | return; |
| 4153 | } |
| 4154 | if (shift_amt == 32) { |
| 4155 | // Just swap. |
| 4156 | __ movl(temp_reg, first_reg_lo); |
| 4157 | __ movl(first_reg_lo, first_reg_hi); |
| 4158 | __ movl(first_reg_hi, temp_reg); |
| 4159 | return; |
| 4160 | } |
| 4161 | |
| 4162 | Immediate imm(shift_amt); |
| 4163 | // Save the constents of the low value. |
| 4164 | __ movl(temp_reg, first_reg_lo); |
| 4165 | |
| 4166 | // Shift right into low, feeding bits from high. |
| 4167 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4168 | |
| 4169 | // Shift right into high, feeding bits from the original low. |
| 4170 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4171 | |
| 4172 | // Swap if needed. |
| 4173 | if (shift_amt > 32) { |
| 4174 | __ movl(temp_reg, first_reg_lo); |
| 4175 | __ movl(first_reg_lo, first_reg_hi); |
| 4176 | __ movl(first_reg_hi, temp_reg); |
| 4177 | } |
| 4178 | } |
| 4179 | } |
| 4180 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4181 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4182 | HandleShift(shl); |
| 4183 | } |
| 4184 | |
| 4185 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4186 | HandleShift(shl); |
| 4187 | } |
| 4188 | |
| 4189 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4190 | HandleShift(shr); |
| 4191 | } |
| 4192 | |
| 4193 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4194 | HandleShift(shr); |
| 4195 | } |
| 4196 | |
| 4197 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4198 | HandleShift(ushr); |
| 4199 | } |
| 4200 | |
| 4201 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4202 | HandleShift(ushr); |
| 4203 | } |
| 4204 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4205 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4206 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4207 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4208 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4209 | if (instruction->IsStringAlloc()) { |
| 4210 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4211 | } else { |
| 4212 | InvokeRuntimeCallingConvention calling_convention; |
| 4213 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4214 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4218 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4219 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4220 | if (instruction->IsStringAlloc()) { |
| 4221 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4222 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4223 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4224 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4225 | __ call(Address(temp, code_offset.Int32Value())); |
| 4226 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4227 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4228 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4229 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4230 | DCHECK(!codegen_->IsLeafMethod()); |
| 4231 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4232 | } |
| 4233 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4234 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4235 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4236 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4237 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4238 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4239 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4240 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4244 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4245 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4246 | QuickEntrypointEnum entrypoint = |
| 4247 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4248 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4249 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4250 | DCHECK(!codegen_->IsLeafMethod()); |
| 4251 | } |
| 4252 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4253 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4254 | LocationSummary* locations = |
| 4255 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4256 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4257 | if (location.IsStackSlot()) { |
| 4258 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4259 | } else if (location.IsDoubleStackSlot()) { |
| 4260 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4261 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4262 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4263 | } |
| 4264 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4265 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4266 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4267 | } |
| 4268 | |
| 4269 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4270 | LocationSummary* locations = |
| 4271 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4272 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4273 | } |
| 4274 | |
| 4275 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4276 | } |
| 4277 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4278 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4279 | LocationSummary* locations = |
| 4280 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4281 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4282 | locations->SetOut(Location::RequiresRegister()); |
| 4283 | } |
| 4284 | |
| 4285 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4286 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4287 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4288 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4289 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4290 | __ movl(locations->Out().AsRegister<Register>(), |
| 4291 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4292 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4293 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4294 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4295 | __ movl(locations->Out().AsRegister<Register>(), |
| 4296 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4297 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4298 | // temp = temp->GetImtEntryAt(method_offset); |
| 4299 | __ movl(locations->Out().AsRegister<Register>(), |
| 4300 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4301 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4302 | } |
| 4303 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4304 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4305 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4306 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4307 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4308 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4309 | } |
| 4310 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4311 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4312 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4313 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4314 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4315 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4316 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4317 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4318 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4319 | break; |
| 4320 | |
| 4321 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4322 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4323 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4324 | break; |
| 4325 | |
| 4326 | default: |
| 4327 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4328 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4329 | } |
| 4330 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4331 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4332 | LocationSummary* locations = |
| 4333 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4335 | locations->SetOut(Location::SameAsFirstInput()); |
| 4336 | } |
| 4337 | |
| 4338 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4339 | LocationSummary* locations = bool_not->GetLocations(); |
| 4340 | Location in = locations->InAt(0); |
| 4341 | Location out = locations->Out(); |
| 4342 | DCHECK(in.Equals(out)); |
| 4343 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4344 | } |
| 4345 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4346 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4347 | LocationSummary* locations = |
| 4348 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4349 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4350 | case Primitive::kPrimBoolean: |
| 4351 | case Primitive::kPrimByte: |
| 4352 | case Primitive::kPrimShort: |
| 4353 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4354 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4355 | case Primitive::kPrimLong: { |
| 4356 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4357 | locations->SetInAt(1, Location::Any()); |
| 4358 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4359 | break; |
| 4360 | } |
| 4361 | case Primitive::kPrimFloat: |
| 4362 | case Primitive::kPrimDouble: { |
| 4363 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4364 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4365 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4366 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4367 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4368 | } else { |
| 4369 | locations->SetInAt(1, Location::Any()); |
| 4370 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4371 | locations->SetOut(Location::RequiresRegister()); |
| 4372 | break; |
| 4373 | } |
| 4374 | default: |
| 4375 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4376 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4380 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4381 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4382 | Location left = locations->InAt(0); |
| 4383 | Location right = locations->InAt(1); |
| 4384 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4385 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4386 | Condition less_cond = kLess; |
| 4387 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4388 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4389 | case Primitive::kPrimBoolean: |
| 4390 | case Primitive::kPrimByte: |
| 4391 | case Primitive::kPrimShort: |
| 4392 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4393 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4394 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4395 | break; |
| 4396 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4397 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4398 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4399 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4400 | int32_t val_low = 0; |
| 4401 | int32_t val_high = 0; |
| 4402 | bool right_is_const = false; |
| 4403 | |
| 4404 | if (right.IsConstant()) { |
| 4405 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4406 | right_is_const = true; |
| 4407 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4408 | val_low = Low32Bits(val); |
| 4409 | val_high = High32Bits(val); |
| 4410 | } |
| 4411 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4412 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4413 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4414 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4415 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4416 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4417 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4418 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4419 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4420 | __ j(kLess, &less); // Signed compare. |
| 4421 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4422 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4423 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4424 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4425 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4426 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4427 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4428 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4429 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4430 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4431 | break; |
| 4432 | } |
| 4433 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4434 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4435 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4436 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4437 | break; |
| 4438 | } |
| 4439 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4440 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4441 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4442 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4443 | break; |
| 4444 | } |
| 4445 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4446 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4447 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4448 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4449 | __ movl(out, Immediate(0)); |
| 4450 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4451 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4452 | |
| 4453 | __ Bind(&greater); |
| 4454 | __ movl(out, Immediate(1)); |
| 4455 | __ jmp(&done); |
| 4456 | |
| 4457 | __ Bind(&less); |
| 4458 | __ movl(out, Immediate(-1)); |
| 4459 | |
| 4460 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4461 | } |
| 4462 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4463 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4464 | LocationSummary* locations = |
| 4465 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4466 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4467 | locations->SetInAt(i, Location::Any()); |
| 4468 | } |
| 4469 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4470 | } |
| 4471 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4472 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4473 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4474 | } |
| 4475 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4476 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4477 | /* |
| 4478 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4479 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4480 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4481 | */ |
| 4482 | switch (kind) { |
| 4483 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4484 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4485 | break; |
| 4486 | } |
| 4487 | case MemBarrierKind::kAnyStore: |
| 4488 | case MemBarrierKind::kLoadAny: |
| 4489 | case MemBarrierKind::kStoreStore: { |
| 4490 | // nop |
| 4491 | break; |
| 4492 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4493 | case MemBarrierKind::kNTStoreStore: |
| 4494 | // Non-Temporal Store/Store needs an explicit fence. |
| 4495 | MemoryFence(/* non-temporal */ true); |
| 4496 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4497 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4498 | } |
| 4499 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4500 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4501 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4502 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4503 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4504 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4505 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4506 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4507 | Register temp) { |
| 4508 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4509 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4510 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4511 | return location.AsRegister<Register>(); |
| 4512 | } |
| 4513 | // For intrinsics we allow any location, so it may be on the stack. |
| 4514 | if (!location.IsRegister()) { |
| 4515 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4516 | return temp; |
| 4517 | } |
| 4518 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4519 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4520 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4521 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4522 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4523 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4524 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4525 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4526 | __ movl(temp, Address(ESP, stack_offset)); |
| 4527 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4528 | } |
| 4529 | return location.AsRegister<Register>(); |
| 4530 | } |
| 4531 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4532 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4533 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4534 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4535 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4536 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4537 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4538 | uint32_t offset = |
| 4539 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4540 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4541 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4542 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4543 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4544 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4545 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4546 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4547 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4548 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4549 | temp.AsRegister<Register>()); |
| 4550 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 4551 | RecordBootMethodPatch(invoke); |
| 4552 | break; |
| 4553 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4554 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4555 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4556 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4557 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4558 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4559 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4560 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4561 | // Bind a new fixup label at the end of the "movl" insn. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4562 | __ Bind(NewMethodBssEntryPatch( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4563 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4564 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()))); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4565 | break; |
| 4566 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4567 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4568 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4569 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4570 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4571 | } |
| 4572 | |
| 4573 | switch (invoke->GetCodePtrLocation()) { |
| 4574 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4575 | __ call(GetFrameEntryLabel()); |
| 4576 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4577 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4578 | // (callee_method + offset_of_quick_compiled_code)() |
| 4579 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4580 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4581 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4582 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4583 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4584 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4585 | |
| 4586 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4587 | } |
| 4588 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4589 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4590 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4591 | Register temp = temp_in.AsRegister<Register>(); |
| 4592 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4593 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4594 | |
| 4595 | // Use the calling convention instead of the location of the receiver, as |
| 4596 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4597 | // slow path, the arguments have been moved to the right place, so here we are |
| 4598 | // guaranteed that the receiver is the first register of the calling convention. |
| 4599 | InvokeDexCallingConvention calling_convention; |
| 4600 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4601 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4602 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4603 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4604 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4605 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4606 | // emit a read barrier for the previous class reference load. |
| 4607 | // However this is not required in practice, as this is an |
| 4608 | // intermediate/temporary reference and because the current |
| 4609 | // concurrent copying collector keeps the from-space memory |
| 4610 | // intact/accessible until the end of the marking phase (the |
| 4611 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4612 | __ MaybeUnpoisonHeapReference(temp); |
| 4613 | // temp = temp->GetMethodAt(method_offset); |
| 4614 | __ movl(temp, Address(temp, method_offset)); |
| 4615 | // call temp->GetEntryPoint(); |
| 4616 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4617 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4618 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4619 | } |
| 4620 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4621 | void CodeGeneratorX86::RecordBootMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 4622 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4623 | HX86ComputeBaseMethodAddress* address = |
| 4624 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 4625 | boot_image_method_patches_.emplace_back(address, |
| 4626 | *invoke->GetTargetMethod().dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4627 | invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4628 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4631 | Label* CodeGeneratorX86::NewMethodBssEntryPatch( |
| 4632 | HX86ComputeBaseMethodAddress* method_address, |
| 4633 | MethodReference target_method) { |
| 4634 | // Add the patch entry and bind its label at the end of the instruction. |
| 4635 | method_bss_entry_patches_.emplace_back(method_address, |
| 4636 | *target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4637 | target_method.index); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4638 | return &method_bss_entry_patches_.back().label; |
| 4639 | } |
| 4640 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4641 | void CodeGeneratorX86::RecordBootTypePatch(HLoadClass* load_class) { |
Vladimir Marko | 00916b9 | 2017-05-17 17:45:45 +0100 | [diff] [blame] | 4642 | HX86ComputeBaseMethodAddress* address = load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4643 | boot_image_type_patches_.emplace_back(address, |
| 4644 | load_class->GetDexFile(), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4645 | load_class->GetTypeIndex().index_); |
| 4646 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4647 | } |
| 4648 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4649 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4650 | HX86ComputeBaseMethodAddress* address = |
| 4651 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4652 | type_bss_entry_patches_.emplace_back( |
| 4653 | address, load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4654 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4657 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4658 | HX86ComputeBaseMethodAddress* address = load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4659 | string_patches_.emplace_back(address, |
| 4660 | load_string->GetDexFile(), |
| 4661 | load_string->GetStringIndex().index_); |
| 4662 | __ Bind(&string_patches_.back().label); |
| 4663 | } |
| 4664 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4665 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4666 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4667 | HX86ComputeBaseMethodAddress* address = |
| 4668 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4669 | string_bss_entry_patches_.emplace_back( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4670 | address, load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4671 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4672 | } |
| 4673 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4674 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4675 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4676 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4677 | |
| 4678 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4679 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4680 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4681 | ArenaVector<LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4682 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4683 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4684 | linker_patches->push_back(Factory( |
| 4685 | literal_offset, &info.dex_file, GetMethodAddressOffset(info.method_address), info.index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4686 | } |
| 4687 | } |
| 4688 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4689 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4690 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4691 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4692 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4693 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4694 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4695 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4696 | string_patches_.size() + |
| 4697 | string_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4698 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4699 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4700 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(boot_image_method_patches_, |
| 4701 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4702 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(boot_image_type_patches_, |
| 4703 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4704 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4705 | } else { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4706 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4707 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeClassTablePatch>(boot_image_type_patches_, |
| 4708 | linker_patches); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4709 | EmitPcRelativeLinkerPatches<LinkerPatch::StringInternTablePatch>(string_patches_, |
| 4710 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4711 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4712 | EmitPcRelativeLinkerPatches<LinkerPatch::MethodBssEntryPatch>(method_bss_entry_patches_, |
| 4713 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4714 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4715 | linker_patches); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4716 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_bss_entry_patches_, |
| 4717 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4718 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4721 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4722 | Register card, |
| 4723 | Register object, |
| 4724 | Register value, |
| 4725 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4726 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4727 | if (value_can_be_null) { |
| 4728 | __ testl(value, value); |
| 4729 | __ j(kEqual, &is_null); |
| 4730 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4731 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4732 | __ movl(temp, object); |
| 4733 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4734 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4735 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4736 | if (value_can_be_null) { |
| 4737 | __ Bind(&is_null); |
| 4738 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4739 | } |
| 4740 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4741 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4742 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4743 | |
| 4744 | bool object_field_get_with_read_barrier = |
| 4745 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4746 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4747 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4748 | kEmitCompilerReadBarrier ? |
| 4749 | LocationSummary::kCallOnSlowPath : |
| 4750 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4751 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4752 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4753 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4754 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4755 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4756 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4757 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4758 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4759 | // The output overlaps in case of long: we don't want the low move |
| 4760 | // to overwrite the object's location. Likewise, in the case of |
| 4761 | // an object field get with read barriers enabled, we do not want |
| 4762 | // the move to overwrite the object's location, as we need it to emit |
| 4763 | // the read barrier. |
| 4764 | locations->SetOut( |
| 4765 | Location::RequiresRegister(), |
| 4766 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4767 | Location::kOutputOverlap : |
| 4768 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4769 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4770 | |
| 4771 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4772 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4773 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4774 | // load the temp into the XMM and then copy the XMM into the |
| 4775 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4776 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4777 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4778 | } |
| 4779 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4780 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4781 | const FieldInfo& field_info) { |
| 4782 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4783 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4784 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4785 | Location base_loc = locations->InAt(0); |
| 4786 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4787 | Location out = locations->Out(); |
| 4788 | bool is_volatile = field_info.IsVolatile(); |
| 4789 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4790 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4791 | |
| 4792 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4793 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4794 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4795 | break; |
| 4796 | } |
| 4797 | |
| 4798 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4799 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4800 | break; |
| 4801 | } |
| 4802 | |
| 4803 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4804 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4805 | break; |
| 4806 | } |
| 4807 | |
| 4808 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4809 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4810 | break; |
| 4811 | } |
| 4812 | |
| 4813 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4814 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4815 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4816 | |
| 4817 | case Primitive::kPrimNot: { |
| 4818 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4819 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4820 | // Note that a potential implicit null check is handled in this |
| 4821 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4822 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4823 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4824 | if (is_volatile) { |
| 4825 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4826 | } |
| 4827 | } else { |
| 4828 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4829 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4830 | if (is_volatile) { |
| 4831 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4832 | } |
| 4833 | // If read barriers are enabled, emit read barriers other than |
| 4834 | // Baker's using a slow path (and also unpoison the loaded |
| 4835 | // reference, if heap poisoning is enabled). |
| 4836 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4837 | } |
| 4838 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4842 | if (is_volatile) { |
| 4843 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4844 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4845 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4846 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4847 | __ psrlq(temp, Immediate(32)); |
| 4848 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4849 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4850 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4851 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4852 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4853 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4854 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4855 | break; |
| 4856 | } |
| 4857 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4858 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4859 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4860 | break; |
| 4861 | } |
| 4862 | |
| 4863 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4864 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4865 | break; |
| 4866 | } |
| 4867 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4868 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4869 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4870 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4871 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4872 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4873 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4874 | // Potential implicit null checks, in the case of reference or |
| 4875 | // long fields, are handled in the previous switch statement. |
| 4876 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4877 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4878 | } |
| 4879 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4880 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4881 | if (field_type == Primitive::kPrimNot) { |
| 4882 | // Memory barriers, in the case of references, are also handled |
| 4883 | // in the previous switch statement. |
| 4884 | } else { |
| 4885 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4886 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4887 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4888 | } |
| 4889 | |
| 4890 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4891 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4892 | |
| 4893 | LocationSummary* locations = |
| 4894 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4895 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4896 | bool is_volatile = field_info.IsVolatile(); |
| 4897 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4898 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4899 | || (field_type == Primitive::kPrimByte); |
| 4900 | |
| 4901 | // The register allocator does not support multiple |
| 4902 | // inputs that die at entry with one in a specific register. |
| 4903 | if (is_byte_type) { |
| 4904 | // Ensure the value is in a byte register. |
| 4905 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4906 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4907 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4908 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4909 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4910 | } else { |
| 4911 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4912 | } |
| 4913 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4914 | // 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] | 4915 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4916 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4917 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4918 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4919 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4920 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4921 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4922 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4923 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4924 | } else { |
| 4925 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4926 | |
| 4927 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4928 | // Temporary registers for the write barrier. |
| 4929 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4930 | // Ensure the card is in a byte register. |
| 4931 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4932 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4937 | const FieldInfo& field_info, |
| 4938 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4939 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4940 | |
| 4941 | LocationSummary* locations = instruction->GetLocations(); |
| 4942 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4943 | Location value = locations->InAt(1); |
| 4944 | bool is_volatile = field_info.IsVolatile(); |
| 4945 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4946 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4947 | bool needs_write_barrier = |
| 4948 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4949 | |
| 4950 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4951 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4952 | } |
| 4953 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4954 | bool maybe_record_implicit_null_check_done = false; |
| 4955 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4956 | switch (field_type) { |
| 4957 | case Primitive::kPrimBoolean: |
| 4958 | case Primitive::kPrimByte: { |
| 4959 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4960 | break; |
| 4961 | } |
| 4962 | |
| 4963 | case Primitive::kPrimShort: |
| 4964 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4965 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4966 | __ movw(Address(base, offset), |
| 4967 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4968 | } else { |
| 4969 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4970 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4971 | break; |
| 4972 | } |
| 4973 | |
| 4974 | case Primitive::kPrimInt: |
| 4975 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4976 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4977 | // Note that in the case where `value` is a null reference, |
| 4978 | // we do not enter this block, as the reference does not |
| 4979 | // need poisoning. |
| 4980 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4981 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4982 | __ movl(temp, value.AsRegister<Register>()); |
| 4983 | __ PoisonHeapReference(temp); |
| 4984 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4985 | } else if (value.IsConstant()) { |
| 4986 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4987 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4988 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4989 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4990 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4991 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4992 | break; |
| 4993 | } |
| 4994 | |
| 4995 | case Primitive::kPrimLong: { |
| 4996 | if (is_volatile) { |
| 4997 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4998 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4999 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5000 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5001 | __ punpckldq(temp1, temp2); |
| 5002 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5003 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5004 | } else if (value.IsConstant()) { |
| 5005 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5006 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5007 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5008 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5009 | } else { |
| 5010 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5011 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5012 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5013 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5014 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5015 | break; |
| 5016 | } |
| 5017 | |
| 5018 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5019 | if (value.IsConstant()) { |
| 5020 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5021 | __ movl(Address(base, offset), Immediate(v)); |
| 5022 | } else { |
| 5023 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5024 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5025 | break; |
| 5026 | } |
| 5027 | |
| 5028 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5029 | if (value.IsConstant()) { |
| 5030 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5031 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5032 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5033 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5034 | maybe_record_implicit_null_check_done = true; |
| 5035 | } else { |
| 5036 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5037 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5038 | break; |
| 5039 | } |
| 5040 | |
| 5041 | case Primitive::kPrimVoid: |
| 5042 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5043 | UNREACHABLE(); |
| 5044 | } |
| 5045 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5046 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5047 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5048 | } |
| 5049 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5050 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5051 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5052 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5053 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5056 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5057 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5058 | } |
| 5059 | } |
| 5060 | |
| 5061 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5062 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5063 | } |
| 5064 | |
| 5065 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5066 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5067 | } |
| 5068 | |
| 5069 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5070 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5071 | } |
| 5072 | |
| 5073 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5074 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5075 | } |
| 5076 | |
| 5077 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5078 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5079 | } |
| 5080 | |
| 5081 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5082 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5083 | } |
| 5084 | |
| 5085 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5086 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5087 | } |
| 5088 | |
| 5089 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5090 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5091 | } |
| 5092 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5093 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5094 | HUnresolvedInstanceFieldGet* instruction) { |
| 5095 | FieldAccessCallingConventionX86 calling_convention; |
| 5096 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5097 | instruction, instruction->GetFieldType(), calling_convention); |
| 5098 | } |
| 5099 | |
| 5100 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5101 | HUnresolvedInstanceFieldGet* instruction) { |
| 5102 | FieldAccessCallingConventionX86 calling_convention; |
| 5103 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5104 | instruction->GetFieldType(), |
| 5105 | instruction->GetFieldIndex(), |
| 5106 | instruction->GetDexPc(), |
| 5107 | calling_convention); |
| 5108 | } |
| 5109 | |
| 5110 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5111 | HUnresolvedInstanceFieldSet* instruction) { |
| 5112 | FieldAccessCallingConventionX86 calling_convention; |
| 5113 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5114 | instruction, instruction->GetFieldType(), calling_convention); |
| 5115 | } |
| 5116 | |
| 5117 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5118 | HUnresolvedInstanceFieldSet* instruction) { |
| 5119 | FieldAccessCallingConventionX86 calling_convention; |
| 5120 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5121 | instruction->GetFieldType(), |
| 5122 | instruction->GetFieldIndex(), |
| 5123 | instruction->GetDexPc(), |
| 5124 | calling_convention); |
| 5125 | } |
| 5126 | |
| 5127 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5128 | HUnresolvedStaticFieldGet* instruction) { |
| 5129 | FieldAccessCallingConventionX86 calling_convention; |
| 5130 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5131 | instruction, instruction->GetFieldType(), calling_convention); |
| 5132 | } |
| 5133 | |
| 5134 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5135 | HUnresolvedStaticFieldGet* instruction) { |
| 5136 | FieldAccessCallingConventionX86 calling_convention; |
| 5137 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5138 | instruction->GetFieldType(), |
| 5139 | instruction->GetFieldIndex(), |
| 5140 | instruction->GetDexPc(), |
| 5141 | calling_convention); |
| 5142 | } |
| 5143 | |
| 5144 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5145 | HUnresolvedStaticFieldSet* instruction) { |
| 5146 | FieldAccessCallingConventionX86 calling_convention; |
| 5147 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5148 | instruction, instruction->GetFieldType(), calling_convention); |
| 5149 | } |
| 5150 | |
| 5151 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5152 | HUnresolvedStaticFieldSet* instruction) { |
| 5153 | FieldAccessCallingConventionX86 calling_convention; |
| 5154 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5155 | instruction->GetFieldType(), |
| 5156 | instruction->GetFieldIndex(), |
| 5157 | instruction->GetDexPc(), |
| 5158 | calling_convention); |
| 5159 | } |
| 5160 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5161 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5162 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5163 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5164 | ? Location::RequiresRegister() |
| 5165 | : Location::Any(); |
| 5166 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5167 | } |
| 5168 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5169 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5170 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5171 | return; |
| 5172 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5173 | LocationSummary* locations = instruction->GetLocations(); |
| 5174 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5175 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5176 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5177 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5178 | } |
| 5179 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5180 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5181 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5182 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5183 | |
| 5184 | LocationSummary* locations = instruction->GetLocations(); |
| 5185 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5186 | |
| 5187 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5188 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5189 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5190 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5191 | } else { |
| 5192 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5193 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5194 | __ jmp(slow_path->GetEntryLabel()); |
| 5195 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5196 | } |
| 5197 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5198 | } |
| 5199 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5200 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5201 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5202 | } |
| 5203 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5204 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5205 | bool object_array_get_with_read_barrier = |
| 5206 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5207 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5208 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5209 | object_array_get_with_read_barrier ? |
| 5210 | LocationSummary::kCallOnSlowPath : |
| 5211 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5212 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5213 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5214 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5215 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5216 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5217 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5218 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5219 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5220 | // The output overlaps in case of long: we don't want the low move |
| 5221 | // to overwrite the array's location. Likewise, in the case of an |
| 5222 | // object array get with read barriers enabled, we do not want the |
| 5223 | // move to overwrite the array's location, as we need it to emit |
| 5224 | // the read barrier. |
| 5225 | locations->SetOut( |
| 5226 | Location::RequiresRegister(), |
| 5227 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5228 | Location::kOutputOverlap : |
| 5229 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5230 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5234 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5235 | Location obj_loc = locations->InAt(0); |
| 5236 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5237 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5238 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5239 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5240 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5241 | Primitive::Type type = instruction->GetType(); |
| 5242 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5243 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5244 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5245 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5246 | break; |
| 5247 | } |
| 5248 | |
| 5249 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5250 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5251 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5252 | break; |
| 5253 | } |
| 5254 | |
| 5255 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5256 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5257 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5258 | break; |
| 5259 | } |
| 5260 | |
| 5261 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5262 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5263 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5264 | // Branch cases into compressed and uncompressed for each index's type. |
| 5265 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5266 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5267 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5268 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5269 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5270 | "Expecting 0=compressed, 1=uncompressed"); |
| 5271 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5272 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5273 | __ jmp(&done); |
| 5274 | __ Bind(¬_compressed); |
| 5275 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5276 | __ Bind(&done); |
| 5277 | } else { |
| 5278 | // Common case for charAt of array of char or when string compression's |
| 5279 | // feature is turned off. |
| 5280 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5281 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5282 | break; |
| 5283 | } |
| 5284 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5285 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5286 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5287 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5288 | break; |
| 5289 | } |
| 5290 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5291 | case Primitive::kPrimNot: { |
| 5292 | static_assert( |
| 5293 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5294 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5295 | // /* HeapReference<Object> */ out = |
| 5296 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5297 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5298 | // Note that a potential implicit null check is handled in this |
| 5299 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5300 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5301 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5302 | } else { |
| 5303 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5304 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5306 | // If read barriers are enabled, emit read barriers other than |
| 5307 | // Baker's using a slow path (and also unpoison the loaded |
| 5308 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5309 | if (index.IsConstant()) { |
| 5310 | uint32_t offset = |
| 5311 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5312 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5313 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5314 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5315 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5316 | } |
| 5317 | } |
| 5318 | break; |
| 5319 | } |
| 5320 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5321 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5322 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5323 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5324 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5325 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5326 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5327 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5328 | break; |
| 5329 | } |
| 5330 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5331 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5332 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5333 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5334 | break; |
| 5335 | } |
| 5336 | |
| 5337 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5338 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5339 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5340 | break; |
| 5341 | } |
| 5342 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5343 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5344 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5345 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5346 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5347 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5348 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5349 | // Potential implicit null checks, in the case of reference or |
| 5350 | // long arrays, are handled in the previous switch statement. |
| 5351 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5352 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5353 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5357 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5358 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5359 | bool needs_write_barrier = |
| 5360 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5361 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5362 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5363 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5364 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5365 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5366 | LocationSummary::kCallOnSlowPath : |
| 5367 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5368 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5369 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5370 | || (value_type == Primitive::kPrimByte); |
| 5371 | // We need the inputs to be different than the output in case of long operation. |
| 5372 | // In case of a byte operation, the register allocator does not support multiple |
| 5373 | // inputs that die at entry with one in a specific register. |
| 5374 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5375 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5376 | if (is_byte_type) { |
| 5377 | // Ensure the value is in a byte register. |
| 5378 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5379 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5380 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5381 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5382 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5383 | } |
| 5384 | if (needs_write_barrier) { |
| 5385 | // Temporary registers for the write barrier. |
| 5386 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5387 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5388 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5389 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5393 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5394 | Location array_loc = locations->InAt(0); |
| 5395 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5396 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5397 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5398 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5399 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5400 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5401 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5402 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5403 | bool needs_write_barrier = |
| 5404 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5405 | |
| 5406 | switch (value_type) { |
| 5407 | case Primitive::kPrimBoolean: |
| 5408 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5409 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5410 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5411 | if (value.IsRegister()) { |
| 5412 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5413 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5414 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5415 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5416 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5417 | break; |
| 5418 | } |
| 5419 | |
| 5420 | case Primitive::kPrimShort: |
| 5421 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5422 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5423 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5424 | if (value.IsRegister()) { |
| 5425 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5426 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5427 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5428 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5429 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5430 | break; |
| 5431 | } |
| 5432 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5433 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5434 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5435 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5436 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5437 | if (!value.IsRegister()) { |
| 5438 | // Just setting null. |
| 5439 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5440 | DCHECK(value.IsConstant()) << value; |
| 5441 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5442 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5443 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5444 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5445 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5446 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5447 | |
| 5448 | DCHECK(needs_write_barrier); |
| 5449 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5450 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5451 | // short when Baker read barriers are enabled. |
| 5452 | Label done; |
| 5453 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5454 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5455 | Location temp_loc = locations->GetTemp(0); |
| 5456 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5457 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5458 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5459 | codegen_->AddSlowPath(slow_path); |
| 5460 | if (instruction->GetValueCanBeNull()) { |
| 5461 | __ testl(register_value, register_value); |
| 5462 | __ j(kNotEqual, ¬_null); |
| 5463 | __ movl(address, Immediate(0)); |
| 5464 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5465 | __ jmp(&done); |
| 5466 | __ Bind(¬_null); |
| 5467 | } |
| 5468 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5469 | // Note that when Baker read barriers are enabled, the type |
| 5470 | // checks are performed without read barriers. This is fine, |
| 5471 | // even in the case where a class object is in the from-space |
| 5472 | // after the flip, as a comparison involving such a type would |
| 5473 | // not produce a false positive; it may of course produce a |
| 5474 | // false negative, in which case we would take the ArraySet |
| 5475 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5476 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5477 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5478 | __ movl(temp, Address(array, class_offset)); |
| 5479 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5480 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5481 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5482 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5483 | __ movl(temp, Address(temp, component_offset)); |
| 5484 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5485 | // nor the object reference in `register_value->klass`, as |
| 5486 | // we are comparing two poisoned references. |
| 5487 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5488 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5489 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5490 | __ j(kEqual, &do_put); |
| 5491 | // If heap poisoning is enabled, the `temp` reference has |
| 5492 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5493 | __ MaybeUnpoisonHeapReference(temp); |
| 5494 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5495 | // If heap poisoning is enabled, no need to unpoison the |
| 5496 | // heap reference loaded below, as it is only used for a |
| 5497 | // comparison with null. |
| 5498 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5499 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5500 | __ Bind(&do_put); |
| 5501 | } else { |
| 5502 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5503 | } |
| 5504 | } |
| 5505 | |
| 5506 | if (kPoisonHeapReferences) { |
| 5507 | __ movl(temp, register_value); |
| 5508 | __ PoisonHeapReference(temp); |
| 5509 | __ movl(address, temp); |
| 5510 | } else { |
| 5511 | __ movl(address, register_value); |
| 5512 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5513 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5514 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5515 | } |
| 5516 | |
| 5517 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5518 | codegen_->MarkGCCard( |
| 5519 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5520 | __ Bind(&done); |
| 5521 | |
| 5522 | if (slow_path != nullptr) { |
| 5523 | __ Bind(slow_path->GetExitLabel()); |
| 5524 | } |
| 5525 | |
| 5526 | break; |
| 5527 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5528 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5529 | case Primitive::kPrimInt: { |
| 5530 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5531 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5532 | if (value.IsRegister()) { |
| 5533 | __ movl(address, value.AsRegister<Register>()); |
| 5534 | } else { |
| 5535 | DCHECK(value.IsConstant()) << value; |
| 5536 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5537 | __ movl(address, Immediate(v)); |
| 5538 | } |
| 5539 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5540 | break; |
| 5541 | } |
| 5542 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5543 | case Primitive::kPrimLong: { |
| 5544 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5545 | if (value.IsRegisterPair()) { |
| 5546 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5547 | value.AsRegisterPairLow<Register>()); |
| 5548 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5549 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5550 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5551 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5552 | DCHECK(value.IsConstant()); |
| 5553 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5554 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5555 | Immediate(Low32Bits(val))); |
| 5556 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5557 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5558 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5559 | } |
| 5560 | break; |
| 5561 | } |
| 5562 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5563 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5564 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5565 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5566 | if (value.IsFpuRegister()) { |
| 5567 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5568 | } else { |
| 5569 | DCHECK(value.IsConstant()); |
| 5570 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5571 | __ movl(address, Immediate(v)); |
| 5572 | } |
| 5573 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5574 | break; |
| 5575 | } |
| 5576 | |
| 5577 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5578 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5579 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5580 | if (value.IsFpuRegister()) { |
| 5581 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5582 | } else { |
| 5583 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5584 | Address address_hi = |
| 5585 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5586 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5587 | __ movl(address, Immediate(Low32Bits(v))); |
| 5588 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5589 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5590 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5591 | break; |
| 5592 | } |
| 5593 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5594 | case Primitive::kPrimVoid: |
| 5595 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5596 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5601 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5602 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5603 | if (!instruction->IsEmittedAtUseSite()) { |
| 5604 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5605 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5606 | } |
| 5607 | |
| 5608 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5609 | if (instruction->IsEmittedAtUseSite()) { |
| 5610 | return; |
| 5611 | } |
| 5612 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5613 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5614 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5615 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5616 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5617 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5618 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5619 | // Mask out most significant bit in case the array is String's array of char. |
| 5620 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5621 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5622 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5623 | } |
| 5624 | |
| 5625 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5626 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5627 | InvokeRuntimeCallingConvention calling_convention; |
| 5628 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5629 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5630 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5631 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5632 | HInstruction* length = instruction->InputAt(1); |
| 5633 | if (!length->IsEmittedAtUseSite()) { |
| 5634 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5635 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5636 | // Need register to see array's length. |
| 5637 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5638 | locations->AddTemp(Location::RequiresRegister()); |
| 5639 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5643 | const bool is_string_compressed_char_at = |
| 5644 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5645 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5646 | Location index_loc = locations->InAt(0); |
| 5647 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5648 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5649 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5650 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5651 | if (length_loc.IsConstant()) { |
| 5652 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5653 | if (index_loc.IsConstant()) { |
| 5654 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5655 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5656 | if (index < 0 || index >= length) { |
| 5657 | codegen_->AddSlowPath(slow_path); |
| 5658 | __ jmp(slow_path->GetEntryLabel()); |
| 5659 | } else { |
| 5660 | // Some optimization after BCE may have generated this, and we should not |
| 5661 | // generate a bounds check if it is a valid range. |
| 5662 | } |
| 5663 | return; |
| 5664 | } |
| 5665 | |
| 5666 | // We have to reverse the jump condition because the length is the constant. |
| 5667 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5668 | __ cmpl(index_reg, Immediate(length)); |
| 5669 | codegen_->AddSlowPath(slow_path); |
| 5670 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5671 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5672 | HInstruction* array_length = instruction->InputAt(1); |
| 5673 | if (array_length->IsEmittedAtUseSite()) { |
| 5674 | // Address the length field in the array. |
| 5675 | DCHECK(array_length->IsArrayLength()); |
| 5676 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5677 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5678 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5679 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5680 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5681 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5682 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5683 | __ movl(length_reg, array_len); |
| 5684 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5685 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5686 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5687 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5688 | // Checking bounds for general case: |
| 5689 | // Array of char or string's array with feature compression off. |
| 5690 | if (index_loc.IsConstant()) { |
| 5691 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5692 | __ cmpl(array_len, Immediate(value)); |
| 5693 | } else { |
| 5694 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5695 | } |
| 5696 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5697 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5698 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5699 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5700 | } |
| 5701 | codegen_->AddSlowPath(slow_path); |
| 5702 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5703 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5704 | } |
| 5705 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5706 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5707 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5708 | } |
| 5709 | |
| 5710 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5711 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5712 | } |
| 5713 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5714 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5715 | LocationSummary* locations = |
| 5716 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5717 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5718 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5719 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5720 | locations->SetCustomSlowPathCallerSaves( |
| 5721 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5725 | HBasicBlock* block = instruction->GetBlock(); |
| 5726 | if (block->GetLoopInformation() != nullptr) { |
| 5727 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5728 | // The back edge will generate the suspend check. |
| 5729 | return; |
| 5730 | } |
| 5731 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5732 | // The goto will generate the suspend check. |
| 5733 | return; |
| 5734 | } |
| 5735 | GenerateSuspendCheck(instruction, nullptr); |
| 5736 | } |
| 5737 | |
| 5738 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5739 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5740 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5741 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5742 | if (slow_path == nullptr) { |
| 5743 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5744 | instruction->SetSlowPath(slow_path); |
| 5745 | codegen_->AddSlowPath(slow_path); |
| 5746 | if (successor != nullptr) { |
| 5747 | DCHECK(successor->IsLoopHeader()); |
| 5748 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5749 | } |
| 5750 | } else { |
| 5751 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5752 | } |
| 5753 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5754 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5755 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5756 | if (successor == nullptr) { |
| 5757 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5758 | __ Bind(slow_path->GetReturnLabel()); |
| 5759 | } else { |
| 5760 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5761 | __ jmp(slow_path->GetEntryLabel()); |
| 5762 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5763 | } |
| 5764 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5765 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5766 | return codegen_->GetAssembler(); |
| 5767 | } |
| 5768 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5769 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5770 | ScratchRegisterScope ensure_scratch( |
| 5771 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5772 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5773 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5774 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5775 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5776 | } |
| 5777 | |
| 5778 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5779 | ScratchRegisterScope ensure_scratch( |
| 5780 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5781 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5782 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5783 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5784 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5785 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5786 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5790 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5791 | Location source = move->GetSource(); |
| 5792 | Location destination = move->GetDestination(); |
| 5793 | |
| 5794 | if (source.IsRegister()) { |
| 5795 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5796 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5797 | } else if (destination.IsFpuRegister()) { |
| 5798 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5799 | } else { |
| 5800 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5801 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5802 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5803 | } else if (source.IsRegisterPair()) { |
| 5804 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5805 | // Create stack space for 2 elements. |
| 5806 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5807 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5808 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5809 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5810 | // And remove the temporary stack space we allocated. |
| 5811 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5812 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5813 | if (destination.IsRegister()) { |
| 5814 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5815 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5816 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5817 | } else if (destination.IsRegisterPair()) { |
| 5818 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5819 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5820 | __ psrlq(src_reg, Immediate(32)); |
| 5821 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5822 | } else if (destination.IsStackSlot()) { |
| 5823 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5824 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5825 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5826 | } else { |
| 5827 | DCHECK(destination.IsSIMDStackSlot()); |
| 5828 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5829 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5830 | } else if (source.IsStackSlot()) { |
| 5831 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5832 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5833 | } else if (destination.IsFpuRegister()) { |
| 5834 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5835 | } else { |
| 5836 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5837 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5838 | } |
| 5839 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5840 | if (destination.IsRegisterPair()) { |
| 5841 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5842 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5843 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5844 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5845 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5846 | } else { |
| 5847 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5848 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5849 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5850 | } else if (source.IsSIMDStackSlot()) { |
| 5851 | DCHECK(destination.IsFpuRegister()); |
| 5852 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5853 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5854 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5855 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5856 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5857 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5858 | if (value == 0) { |
| 5859 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5860 | } else { |
| 5861 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5862 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5863 | } else { |
| 5864 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5865 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5866 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5867 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5868 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5869 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5870 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5871 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5872 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5873 | if (value == 0) { |
| 5874 | // Easy handling of 0.0. |
| 5875 | __ xorps(dest, dest); |
| 5876 | } else { |
| 5877 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5878 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5879 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5880 | __ movl(temp, Immediate(value)); |
| 5881 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5882 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5883 | } else { |
| 5884 | DCHECK(destination.IsStackSlot()) << destination; |
| 5885 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5886 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5887 | } else if (constant->IsLongConstant()) { |
| 5888 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5889 | int32_t low_value = Low32Bits(value); |
| 5890 | int32_t high_value = High32Bits(value); |
| 5891 | Immediate low(low_value); |
| 5892 | Immediate high(high_value); |
| 5893 | if (destination.IsDoubleStackSlot()) { |
| 5894 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5895 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5896 | } else { |
| 5897 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5898 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5899 | } |
| 5900 | } else { |
| 5901 | DCHECK(constant->IsDoubleConstant()); |
| 5902 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5903 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5904 | int32_t low_value = Low32Bits(value); |
| 5905 | int32_t high_value = High32Bits(value); |
| 5906 | Immediate low(low_value); |
| 5907 | Immediate high(high_value); |
| 5908 | if (destination.IsFpuRegister()) { |
| 5909 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5910 | if (value == 0) { |
| 5911 | // Easy handling of 0.0. |
| 5912 | __ xorpd(dest, dest); |
| 5913 | } else { |
| 5914 | __ pushl(high); |
| 5915 | __ pushl(low); |
| 5916 | __ movsd(dest, Address(ESP, 0)); |
| 5917 | __ addl(ESP, Immediate(8)); |
| 5918 | } |
| 5919 | } else { |
| 5920 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5921 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5922 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5923 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5924 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5925 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5926 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5927 | } |
| 5928 | } |
| 5929 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5930 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5931 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5932 | ScratchRegisterScope ensure_scratch( |
| 5933 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5934 | |
| 5935 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5936 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5937 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5938 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5939 | } |
| 5940 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5941 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5942 | ScratchRegisterScope ensure_scratch( |
| 5943 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5944 | |
| 5945 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5946 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5947 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5948 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5949 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5950 | } |
| 5951 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5952 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5953 | ScratchRegisterScope ensure_scratch1( |
| 5954 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5955 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5956 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5957 | ScratchRegisterScope ensure_scratch2( |
| 5958 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5959 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5960 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5961 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5962 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5963 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5964 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5965 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5969 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5970 | Location source = move->GetSource(); |
| 5971 | Location destination = move->GetDestination(); |
| 5972 | |
| 5973 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5974 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5975 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5976 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5977 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5978 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5979 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5980 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5981 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5982 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5983 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5984 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5985 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5986 | // Use XOR Swap algorithm to avoid a temporary. |
| 5987 | DCHECK_NE(source.reg(), destination.reg()); |
| 5988 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5989 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5990 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5991 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5992 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5993 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5994 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5995 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5996 | // Take advantage of the 16 bytes in the XMM register. |
| 5997 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5998 | Address stack(ESP, destination.GetStackIndex()); |
| 5999 | // Load the double into the high doubleword. |
| 6000 | __ movhpd(reg, stack); |
| 6001 | |
| 6002 | // Store the low double into the destination. |
| 6003 | __ movsd(stack, reg); |
| 6004 | |
| 6005 | // Move the high double to the low double. |
| 6006 | __ psrldq(reg, Immediate(8)); |
| 6007 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6008 | // Take advantage of the 16 bytes in the XMM register. |
| 6009 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6010 | Address stack(ESP, source.GetStackIndex()); |
| 6011 | // Load the double into the high doubleword. |
| 6012 | __ movhpd(reg, stack); |
| 6013 | |
| 6014 | // Store the low double into the destination. |
| 6015 | __ movsd(stack, reg); |
| 6016 | |
| 6017 | // Move the high double to the low double. |
| 6018 | __ psrldq(reg, Immediate(8)); |
| 6019 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 6020 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 6021 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6022 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6023 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6028 | __ pushl(static_cast<Register>(reg)); |
| 6029 | } |
| 6030 | |
| 6031 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6032 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6033 | } |
| 6034 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6035 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6036 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6037 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6038 | case HLoadClass::LoadKind::kInvalid: |
| 6039 | LOG(FATAL) << "UNREACHABLE"; |
| 6040 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6041 | case HLoadClass::LoadKind::kReferrersClass: |
| 6042 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6043 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6044 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6045 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6046 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6047 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6048 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6049 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6050 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6051 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6052 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6053 | break; |
| 6054 | } |
| 6055 | return desired_class_load_kind; |
| 6056 | } |
| 6057 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6058 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6059 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6060 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6061 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6062 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6063 | cls, |
| 6064 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6065 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6066 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6067 | return; |
| 6068 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6069 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6070 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6071 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6072 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6073 | ? LocationSummary::kCallOnSlowPath |
| 6074 | : LocationSummary::kNoCall; |
| 6075 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6076 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6077 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6078 | } |
| 6079 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6080 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6081 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6082 | load_kind == HLoadClass::LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6083 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6084 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6085 | } |
| 6086 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6087 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6088 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6089 | // Rely on the type resolution and/or initialization to save everything. |
| 6090 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6091 | InvokeRuntimeCallingConvention calling_convention; |
| 6092 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6093 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6094 | } else { |
| 6095 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6096 | } |
| 6097 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6098 | } |
| 6099 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6100 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| 6101 | dex::TypeIndex dex_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6102 | Handle<mirror::Class> handle) { |
| 6103 | jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index), |
| 6104 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6105 | // Add a patch entry and return the label. |
| 6106 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 6107 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6108 | return &info->label; |
| 6109 | } |
| 6110 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6111 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6112 | // move. |
| 6113 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6114 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6115 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6116 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6117 | return; |
| 6118 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6119 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6120 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6121 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6122 | Location out_loc = locations->Out(); |
| 6123 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6124 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6125 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6126 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6127 | ? kWithoutReadBarrier |
| 6128 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6129 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6130 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6131 | DCHECK(!cls->CanCallRuntime()); |
| 6132 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6133 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6134 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6135 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6136 | cls, |
| 6137 | out_loc, |
| 6138 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6139 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6140 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6141 | break; |
| 6142 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6143 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6144 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6145 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6146 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6147 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6148 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6149 | break; |
| 6150 | } |
| 6151 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6152 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6153 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6154 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6155 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6156 | __ movl(out, Immediate(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6157 | break; |
| 6158 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6159 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6160 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6161 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6162 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6163 | codegen_->RecordBootTypePatch(cls); |
| 6164 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6165 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6166 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6167 | if (masked_hash != 0) { |
| 6168 | __ subl(out, Immediate(masked_hash)); |
| 6169 | } |
| 6170 | break; |
| 6171 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6172 | case HLoadClass::LoadKind::kBssEntry: { |
| 6173 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6174 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6175 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6176 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6177 | generate_null_check = true; |
| 6178 | break; |
| 6179 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6180 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6181 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6182 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6183 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6184 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6185 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6186 | break; |
| 6187 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6188 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6189 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6190 | LOG(FATAL) << "UNREACHABLE"; |
| 6191 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6192 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6193 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6194 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6195 | DCHECK(cls->CanCallRuntime()); |
| 6196 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6197 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6198 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6199 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6200 | if (generate_null_check) { |
| 6201 | __ testl(out, out); |
| 6202 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6203 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6204 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6205 | if (cls->MustGenerateClinitCheck()) { |
| 6206 | GenerateClassInitializationCheck(slow_path, out); |
| 6207 | } else { |
| 6208 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6209 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6214 | LocationSummary* locations = |
| 6215 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6216 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6217 | if (check->HasUses()) { |
| 6218 | locations->SetOut(Location::SameAsFirstInput()); |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6223 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6224 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6225 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6226 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6227 | GenerateClassInitializationCheck(slow_path, |
| 6228 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6229 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6230 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6231 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6232 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6233 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6234 | Immediate(mirror::Class::kStatusInitialized)); |
| 6235 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6236 | __ Bind(slow_path->GetExitLabel()); |
| 6237 | // No need for memory fence, thanks to the X86 memory model. |
| 6238 | } |
| 6239 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6240 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6241 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6242 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6243 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6244 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6245 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6246 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6247 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6248 | case HLoadString::LoadKind::kJitTableAddress: |
| 6249 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6250 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6251 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6252 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6253 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6254 | } |
| 6255 | return desired_string_load_kind; |
| 6256 | } |
| 6257 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6258 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6259 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6260 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6261 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6262 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6263 | load_kind == HLoadString::LoadKind::kBootImageInternTable || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6264 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6265 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6266 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6267 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6268 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6269 | } else { |
| 6270 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6271 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6272 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6273 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6274 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6275 | InvokeRuntimeCallingConvention calling_convention; |
| 6276 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6277 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6278 | } else { |
| 6279 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6280 | } |
| 6281 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6282 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6283 | } |
| 6284 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6285 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6286 | dex::StringIndex dex_index, |
| 6287 | Handle<mirror::String> handle) { |
| 6288 | jit_string_roots_.Overwrite( |
| 6289 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6290 | // Add a patch entry and return the label. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6291 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6292 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6293 | return &info->label; |
| 6294 | } |
| 6295 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6296 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6297 | // move. |
| 6298 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6299 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6300 | Location out_loc = locations->Out(); |
| 6301 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6302 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6303 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6304 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6305 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6306 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6307 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6308 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6309 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6310 | } |
| 6311 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6312 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6313 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6314 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6315 | __ movl(out, Immediate(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6316 | return; |
| 6317 | } |
| 6318 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 6319 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6320 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6321 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6322 | codegen_->RecordBootStringPatch(load); |
| 6323 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6324 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6325 | case HLoadString::LoadKind::kBssEntry: { |
| 6326 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6327 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6328 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6329 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6330 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6331 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6332 | codegen_->AddSlowPath(slow_path); |
| 6333 | __ testl(out, out); |
| 6334 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6335 | __ Bind(slow_path->GetExitLabel()); |
| 6336 | return; |
| 6337 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6338 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6339 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6340 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6341 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6342 | // /* GcRoot<mirror::String> */ out = *address |
| 6343 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6344 | return; |
| 6345 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6346 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6347 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6348 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6349 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6350 | // 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] | 6351 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6352 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6353 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6354 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6355 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6356 | } |
| 6357 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6358 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6359 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6360 | } |
| 6361 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6362 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6363 | LocationSummary* locations = |
| 6364 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6365 | locations->SetOut(Location::RequiresRegister()); |
| 6366 | } |
| 6367 | |
| 6368 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6369 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6370 | } |
| 6371 | |
| 6372 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6373 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6374 | } |
| 6375 | |
| 6376 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6377 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6378 | } |
| 6379 | |
| 6380 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6381 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6382 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6383 | InvokeRuntimeCallingConvention calling_convention; |
| 6384 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6385 | } |
| 6386 | |
| 6387 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6388 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6389 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6390 | } |
| 6391 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6392 | // Temp is used for read barrier. |
| 6393 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6394 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6395 | !kUseBakerReadBarrier && |
| 6396 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6397 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6398 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6399 | return 1; |
| 6400 | } |
| 6401 | return 0; |
| 6402 | } |
| 6403 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6404 | // 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] | 6405 | // interface pointer, one for loading the current interface. |
| 6406 | // The other checks have one temp for loading the object's class. |
| 6407 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6408 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6409 | return 2; |
| 6410 | } |
| 6411 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6412 | } |
| 6413 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6414 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6415 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6416 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6417 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6418 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6419 | case TypeCheckKind::kExactCheck: |
| 6420 | case TypeCheckKind::kAbstractClassCheck: |
| 6421 | case TypeCheckKind::kClassHierarchyCheck: |
| 6422 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6423 | call_kind = |
| 6424 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6425 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6426 | break; |
| 6427 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6428 | case TypeCheckKind::kUnresolvedCheck: |
| 6429 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6430 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6431 | break; |
| 6432 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6433 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6434 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6435 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6436 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6437 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6438 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6439 | locations->SetInAt(1, Location::Any()); |
| 6440 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6441 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6442 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6443 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6444 | } |
| 6445 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6446 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6447 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6448 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6449 | Location obj_loc = locations->InAt(0); |
| 6450 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6451 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6452 | Location out_loc = locations->Out(); |
| 6453 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6454 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6455 | DCHECK_LE(num_temps, 1u); |
| 6456 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6457 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6458 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6459 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6460 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6461 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6462 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6463 | |
| 6464 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6465 | // Avoid null check if we know obj is not null. |
| 6466 | if (instruction->MustDoNullCheck()) { |
| 6467 | __ testl(obj, obj); |
| 6468 | __ j(kEqual, &zero); |
| 6469 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6470 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6471 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6472 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6473 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6474 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6475 | out_loc, |
| 6476 | obj_loc, |
| 6477 | class_offset, |
| 6478 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6479 | if (cls.IsRegister()) { |
| 6480 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6481 | } else { |
| 6482 | DCHECK(cls.IsStackSlot()) << cls; |
| 6483 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6484 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6485 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6486 | // Classes must be equal for the instanceof to succeed. |
| 6487 | __ j(kNotEqual, &zero); |
| 6488 | __ movl(out, Immediate(1)); |
| 6489 | __ jmp(&done); |
| 6490 | break; |
| 6491 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6492 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6493 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6494 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6495 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6496 | out_loc, |
| 6497 | obj_loc, |
| 6498 | class_offset, |
| 6499 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6500 | // If the class is abstract, we eagerly fetch the super class of the |
| 6501 | // object to avoid doing a comparison we know will fail. |
| 6502 | NearLabel loop; |
| 6503 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6504 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6505 | GenerateReferenceLoadOneRegister(instruction, |
| 6506 | out_loc, |
| 6507 | super_offset, |
| 6508 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6509 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6510 | __ testl(out, out); |
| 6511 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6512 | __ j(kEqual, &done); |
| 6513 | if (cls.IsRegister()) { |
| 6514 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6515 | } else { |
| 6516 | DCHECK(cls.IsStackSlot()) << cls; |
| 6517 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6518 | } |
| 6519 | __ j(kNotEqual, &loop); |
| 6520 | __ movl(out, Immediate(1)); |
| 6521 | if (zero.IsLinked()) { |
| 6522 | __ jmp(&done); |
| 6523 | } |
| 6524 | break; |
| 6525 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6526 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6527 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6528 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6529 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6530 | out_loc, |
| 6531 | obj_loc, |
| 6532 | class_offset, |
| 6533 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6534 | // Walk over the class hierarchy to find a match. |
| 6535 | NearLabel loop, success; |
| 6536 | __ Bind(&loop); |
| 6537 | if (cls.IsRegister()) { |
| 6538 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6539 | } else { |
| 6540 | DCHECK(cls.IsStackSlot()) << cls; |
| 6541 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6542 | } |
| 6543 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6544 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6545 | GenerateReferenceLoadOneRegister(instruction, |
| 6546 | out_loc, |
| 6547 | super_offset, |
| 6548 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6549 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6550 | __ testl(out, out); |
| 6551 | __ j(kNotEqual, &loop); |
| 6552 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6553 | __ jmp(&done); |
| 6554 | __ Bind(&success); |
| 6555 | __ movl(out, Immediate(1)); |
| 6556 | if (zero.IsLinked()) { |
| 6557 | __ jmp(&done); |
| 6558 | } |
| 6559 | break; |
| 6560 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6561 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6562 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6563 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6564 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6565 | out_loc, |
| 6566 | obj_loc, |
| 6567 | class_offset, |
| 6568 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6569 | // Do an exact check. |
| 6570 | NearLabel exact_check; |
| 6571 | if (cls.IsRegister()) { |
| 6572 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6573 | } else { |
| 6574 | DCHECK(cls.IsStackSlot()) << cls; |
| 6575 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6576 | } |
| 6577 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6578 | // 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] | 6579 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6580 | GenerateReferenceLoadOneRegister(instruction, |
| 6581 | out_loc, |
| 6582 | component_offset, |
| 6583 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6584 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6585 | __ testl(out, out); |
| 6586 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6587 | __ j(kEqual, &done); |
| 6588 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6589 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6590 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6591 | __ movl(out, Immediate(1)); |
| 6592 | __ jmp(&done); |
| 6593 | break; |
| 6594 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6595 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6596 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6597 | // No read barrier since the slow path will retry upon failure. |
| 6598 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6599 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6600 | out_loc, |
| 6601 | obj_loc, |
| 6602 | class_offset, |
| 6603 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6604 | if (cls.IsRegister()) { |
| 6605 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6606 | } else { |
| 6607 | DCHECK(cls.IsStackSlot()) << cls; |
| 6608 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6609 | } |
| 6610 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6611 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6612 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6613 | codegen_->AddSlowPath(slow_path); |
| 6614 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6615 | __ movl(out, Immediate(1)); |
| 6616 | if (zero.IsLinked()) { |
| 6617 | __ jmp(&done); |
| 6618 | } |
| 6619 | break; |
| 6620 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6621 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6622 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6623 | case TypeCheckKind::kInterfaceCheck: { |
| 6624 | // 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] | 6625 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6626 | // cases. |
| 6627 | // |
| 6628 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6629 | // entry point without resorting to a type checking slow path |
| 6630 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6631 | // require to assign fixed registers for the inputs of this |
| 6632 | // HInstanceOf instruction (following the runtime calling |
| 6633 | // convention), which might be cluttered by the potential first |
| 6634 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6635 | // |
| 6636 | // TODO: Introduce a new runtime entry point taking the object |
| 6637 | // to test (instead of its class) as argument, and let it deal |
| 6638 | // with the read barrier issues. This will let us refactor this |
| 6639 | // case of the `switch` code as it was previously (with a direct |
| 6640 | // call to the runtime not using a type checking slow path). |
| 6641 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6642 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6643 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6644 | /* is_fatal */ false); |
| 6645 | codegen_->AddSlowPath(slow_path); |
| 6646 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6647 | if (zero.IsLinked()) { |
| 6648 | __ jmp(&done); |
| 6649 | } |
| 6650 | break; |
| 6651 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6652 | } |
| 6653 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6654 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6655 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6656 | __ xorl(out, out); |
| 6657 | } |
| 6658 | |
| 6659 | if (done.IsLinked()) { |
| 6660 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6661 | } |
| 6662 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6663 | if (slow_path != nullptr) { |
| 6664 | __ Bind(slow_path->GetExitLabel()); |
| 6665 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6666 | } |
| 6667 | |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6668 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6669 | switch (type_check_kind) { |
| 6670 | case TypeCheckKind::kExactCheck: |
| 6671 | case TypeCheckKind::kAbstractClassCheck: |
| 6672 | case TypeCheckKind::kClassHierarchyCheck: |
| 6673 | case TypeCheckKind::kArrayObjectCheck: |
| 6674 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6675 | case TypeCheckKind::kInterfaceCheck: |
| 6676 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6677 | case TypeCheckKind::kArrayCheck: |
| 6678 | case TypeCheckKind::kUnresolvedCheck: |
| 6679 | return false; |
| 6680 | } |
| 6681 | LOG(FATAL) << "Unreachable"; |
| 6682 | UNREACHABLE(); |
| 6683 | } |
| 6684 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6685 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6686 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6687 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6688 | LocationSummary::CallKind call_kind = |
| 6689 | IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch) |
| 6690 | ? LocationSummary::kNoCall |
| 6691 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6692 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6693 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6694 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6695 | // Require a register for the interface check since there is a loop that compares the class to |
| 6696 | // a memory address. |
| 6697 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6698 | } else { |
| 6699 | locations->SetInAt(1, Location::Any()); |
| 6700 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6701 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6702 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6703 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6704 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6705 | } |
| 6706 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6707 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6708 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6709 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6710 | Location obj_loc = locations->InAt(0); |
| 6711 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6712 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6713 | Location temp_loc = locations->GetTemp(0); |
| 6714 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6715 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6716 | DCHECK_GE(num_temps, 1u); |
| 6717 | DCHECK_LE(num_temps, 2u); |
| 6718 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6719 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6720 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6721 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6722 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6723 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6724 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6725 | const uint32_t object_array_data_offset = |
| 6726 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6727 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6728 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6729 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6730 | // read barriers is done for performance and code size reasons. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6731 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6732 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6733 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6734 | SlowPathCode* type_check_slow_path = |
| 6735 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6736 | is_type_check_slow_path_fatal); |
| 6737 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6738 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6739 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6740 | // Avoid null check if we know obj is not null. |
| 6741 | if (instruction->MustDoNullCheck()) { |
| 6742 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6743 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6744 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6745 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6746 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6747 | case TypeCheckKind::kExactCheck: |
| 6748 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6749 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6750 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6751 | temp_loc, |
| 6752 | obj_loc, |
| 6753 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6754 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6755 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6756 | if (cls.IsRegister()) { |
| 6757 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6758 | } else { |
| 6759 | DCHECK(cls.IsStackSlot()) << cls; |
| 6760 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6761 | } |
| 6762 | // Jump to slow path for throwing the exception or doing a |
| 6763 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6764 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6765 | break; |
| 6766 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6767 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6768 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6769 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6770 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6771 | temp_loc, |
| 6772 | obj_loc, |
| 6773 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6774 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6775 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6776 | // If the class is abstract, we eagerly fetch the super class of the |
| 6777 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6778 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6779 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6780 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6781 | GenerateReferenceLoadOneRegister(instruction, |
| 6782 | temp_loc, |
| 6783 | super_offset, |
| 6784 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6785 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6786 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6787 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6788 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6789 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6790 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6791 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6792 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6793 | if (cls.IsRegister()) { |
| 6794 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6795 | } else { |
| 6796 | DCHECK(cls.IsStackSlot()) << cls; |
| 6797 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6798 | } |
| 6799 | __ j(kNotEqual, &loop); |
| 6800 | break; |
| 6801 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6802 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6803 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6804 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6805 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6806 | temp_loc, |
| 6807 | obj_loc, |
| 6808 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6809 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6810 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6811 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6812 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6813 | __ Bind(&loop); |
| 6814 | if (cls.IsRegister()) { |
| 6815 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6816 | } else { |
| 6817 | DCHECK(cls.IsStackSlot()) << cls; |
| 6818 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6819 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6820 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6821 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6822 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6823 | GenerateReferenceLoadOneRegister(instruction, |
| 6824 | temp_loc, |
| 6825 | super_offset, |
| 6826 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6827 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6828 | |
| 6829 | // If the class reference currently in `temp` is not null, jump |
| 6830 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6831 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6832 | __ j(kNotZero, &loop); |
| 6833 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6834 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6835 | break; |
| 6836 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6837 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6838 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6839 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6840 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6841 | temp_loc, |
| 6842 | obj_loc, |
| 6843 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6844 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6845 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6846 | // Do an exact check. |
| 6847 | if (cls.IsRegister()) { |
| 6848 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6849 | } else { |
| 6850 | DCHECK(cls.IsStackSlot()) << cls; |
| 6851 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6852 | } |
| 6853 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6854 | |
| 6855 | // 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] | 6856 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6857 | GenerateReferenceLoadOneRegister(instruction, |
| 6858 | temp_loc, |
| 6859 | component_offset, |
| 6860 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6861 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6862 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6863 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6864 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6865 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6866 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6867 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6868 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6869 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6870 | break; |
| 6871 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6872 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6873 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6874 | // 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] | 6875 | // We cannot directly call the CheckCast runtime entry point |
| 6876 | // without resorting to a type checking slow path here (i.e. by |
| 6877 | // calling InvokeRuntime directly), as it would require to |
| 6878 | // assign fixed registers for the inputs of this HInstanceOf |
| 6879 | // instruction (following the runtime calling convention), which |
| 6880 | // might be cluttered by the potential first read barrier |
| 6881 | // emission at the beginning of this method. |
| 6882 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6883 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6884 | |
| 6885 | case TypeCheckKind::kInterfaceCheck: { |
| 6886 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6887 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6888 | // 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] | 6889 | // to the slow path if we are running under poisoning. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6890 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6891 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6892 | // doing this. |
| 6893 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6894 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6895 | temp_loc, |
| 6896 | obj_loc, |
| 6897 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6898 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6899 | |
| 6900 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6901 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6902 | temp_loc, |
| 6903 | temp_loc, |
| 6904 | iftable_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6905 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6906 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6907 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6908 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6909 | NearLabel start_loop; |
| 6910 | __ Bind(&start_loop); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6911 | // Need to subtract first to handle the empty array case. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6912 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6913 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6914 | // Go to next interface if the classes do not match. |
| 6915 | __ cmpl(cls.AsRegister<Register>(), |
| 6916 | CodeGeneratorX86::ArrayAddress(temp, |
| 6917 | maybe_temp2_loc, |
| 6918 | TIMES_4, |
| 6919 | object_array_data_offset)); |
| 6920 | __ j(kNotEqual, &start_loop); |
| 6921 | } else { |
| 6922 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6923 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6924 | break; |
| 6925 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6926 | } |
| 6927 | __ Bind(&done); |
| 6928 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6929 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6930 | } |
| 6931 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6932 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6933 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6934 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6935 | InvokeRuntimeCallingConvention calling_convention; |
| 6936 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6937 | } |
| 6938 | |
| 6939 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6940 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6941 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6942 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6943 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6944 | if (instruction->IsEnter()) { |
| 6945 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6946 | } else { |
| 6947 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6948 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6949 | } |
| 6950 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6951 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6952 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6953 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6954 | |
| 6955 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6956 | LocationSummary* locations = |
| 6957 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6958 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6959 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6960 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6961 | locations->SetInAt(1, Location::Any()); |
| 6962 | locations->SetOut(Location::SameAsFirstInput()); |
| 6963 | } |
| 6964 | |
| 6965 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6966 | HandleBitwiseOperation(instruction); |
| 6967 | } |
| 6968 | |
| 6969 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6970 | HandleBitwiseOperation(instruction); |
| 6971 | } |
| 6972 | |
| 6973 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6974 | HandleBitwiseOperation(instruction); |
| 6975 | } |
| 6976 | |
| 6977 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6978 | LocationSummary* locations = instruction->GetLocations(); |
| 6979 | Location first = locations->InAt(0); |
| 6980 | Location second = locations->InAt(1); |
| 6981 | DCHECK(first.Equals(locations->Out())); |
| 6982 | |
| 6983 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6984 | if (second.IsRegister()) { |
| 6985 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6986 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6987 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6988 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6989 | } else { |
| 6990 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6991 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6992 | } |
| 6993 | } else if (second.IsConstant()) { |
| 6994 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6995 | __ andl(first.AsRegister<Register>(), |
| 6996 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6997 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6998 | __ orl(first.AsRegister<Register>(), |
| 6999 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7000 | } else { |
| 7001 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7002 | __ xorl(first.AsRegister<Register>(), |
| 7003 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7004 | } |
| 7005 | } else { |
| 7006 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7007 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7008 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7009 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7010 | } else { |
| 7011 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7012 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7013 | } |
| 7014 | } |
| 7015 | } else { |
| 7016 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7017 | if (second.IsRegisterPair()) { |
| 7018 | if (instruction->IsAnd()) { |
| 7019 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7020 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7021 | } else if (instruction->IsOr()) { |
| 7022 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7023 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7024 | } else { |
| 7025 | DCHECK(instruction->IsXor()); |
| 7026 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7027 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7028 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7029 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7030 | if (instruction->IsAnd()) { |
| 7031 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7032 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7033 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7034 | } else if (instruction->IsOr()) { |
| 7035 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7036 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7037 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7038 | } else { |
| 7039 | DCHECK(instruction->IsXor()); |
| 7040 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7041 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7042 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7043 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7044 | } else { |
| 7045 | DCHECK(second.IsConstant()) << second; |
| 7046 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7047 | int32_t low_value = Low32Bits(value); |
| 7048 | int32_t high_value = High32Bits(value); |
| 7049 | Immediate low(low_value); |
| 7050 | Immediate high(high_value); |
| 7051 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7052 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7053 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7054 | if (low_value == 0) { |
| 7055 | __ xorl(first_low, first_low); |
| 7056 | } else if (low_value != -1) { |
| 7057 | __ andl(first_low, low); |
| 7058 | } |
| 7059 | if (high_value == 0) { |
| 7060 | __ xorl(first_high, first_high); |
| 7061 | } else if (high_value != -1) { |
| 7062 | __ andl(first_high, high); |
| 7063 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7064 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7065 | if (low_value != 0) { |
| 7066 | __ orl(first_low, low); |
| 7067 | } |
| 7068 | if (high_value != 0) { |
| 7069 | __ orl(first_high, high); |
| 7070 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7071 | } else { |
| 7072 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7073 | if (low_value != 0) { |
| 7074 | __ xorl(first_low, low); |
| 7075 | } |
| 7076 | if (high_value != 0) { |
| 7077 | __ xorl(first_high, high); |
| 7078 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7079 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7080 | } |
| 7081 | } |
| 7082 | } |
| 7083 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7084 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7085 | HInstruction* instruction, |
| 7086 | Location out, |
| 7087 | uint32_t offset, |
| 7088 | Location maybe_temp, |
| 7089 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7090 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7091 | if (read_barrier_option == kWithReadBarrier) { |
| 7092 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7093 | if (kUseBakerReadBarrier) { |
| 7094 | // Load with fast path based Baker's read barrier. |
| 7095 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7096 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7097 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7098 | } else { |
| 7099 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7100 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7101 | // in the following move operation, as we will need it for the |
| 7102 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7103 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7104 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7105 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7106 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7107 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7108 | } |
| 7109 | } else { |
| 7110 | // Plain load with no read barrier. |
| 7111 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7112 | __ movl(out_reg, Address(out_reg, offset)); |
| 7113 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7114 | } |
| 7115 | } |
| 7116 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7117 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7118 | HInstruction* instruction, |
| 7119 | Location out, |
| 7120 | Location obj, |
| 7121 | uint32_t offset, |
| 7122 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7123 | Register out_reg = out.AsRegister<Register>(); |
| 7124 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7125 | if (read_barrier_option == kWithReadBarrier) { |
| 7126 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7127 | if (kUseBakerReadBarrier) { |
| 7128 | // Load with fast path based Baker's read barrier. |
| 7129 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7130 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7131 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7132 | } else { |
| 7133 | // Load with slow path based read barrier. |
| 7134 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7135 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7136 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7137 | } |
| 7138 | } else { |
| 7139 | // Plain load with no read barrier. |
| 7140 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7141 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7142 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7143 | } |
| 7144 | } |
| 7145 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7146 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7147 | HInstruction* instruction, |
| 7148 | Location root, |
| 7149 | const Address& address, |
| 7150 | Label* fixup_label, |
| 7151 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7152 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7153 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7154 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7155 | if (kUseBakerReadBarrier) { |
| 7156 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7157 | // Baker's read barrier are used: |
| 7158 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7159 | // root = obj.field; |
| 7160 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7161 | // if (temp != null) { |
| 7162 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7163 | // } |
| 7164 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7165 | // /* GcRoot<mirror::Object> */ root = *address |
| 7166 | __ movl(root_reg, address); |
| 7167 | if (fixup_label != nullptr) { |
| 7168 | __ Bind(fixup_label); |
| 7169 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7170 | static_assert( |
| 7171 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7172 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7173 | "have different sizes."); |
| 7174 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7175 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7176 | "have different sizes."); |
| 7177 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7178 | // Slow path marking the GC root `root`. |
| 7179 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7180 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7181 | codegen_->AddSlowPath(slow_path); |
| 7182 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7183 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7184 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7185 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7186 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7187 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7188 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7189 | __ Bind(slow_path->GetExitLabel()); |
| 7190 | } else { |
| 7191 | // GC root loaded through a slow path for read barriers other |
| 7192 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7193 | // /* GcRoot<mirror::Object>* */ root = address |
| 7194 | __ leal(root_reg, address); |
| 7195 | if (fixup_label != nullptr) { |
| 7196 | __ Bind(fixup_label); |
| 7197 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7198 | // /* mirror::Object* */ root = root->Read() |
| 7199 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7200 | } |
| 7201 | } else { |
| 7202 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7203 | // /* GcRoot<mirror::Object> */ root = *address |
| 7204 | __ movl(root_reg, address); |
| 7205 | if (fixup_label != nullptr) { |
| 7206 | __ Bind(fixup_label); |
| 7207 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7208 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7209 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7210 | } |
| 7211 | } |
| 7212 | |
| 7213 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7214 | Location ref, |
| 7215 | Register obj, |
| 7216 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7217 | bool needs_null_check) { |
| 7218 | DCHECK(kEmitCompilerReadBarrier); |
| 7219 | DCHECK(kUseBakerReadBarrier); |
| 7220 | |
| 7221 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7222 | Address src(obj, 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::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7227 | Location ref, |
| 7228 | Register obj, |
| 7229 | uint32_t data_offset, |
| 7230 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7231 | bool needs_null_check) { |
| 7232 | DCHECK(kEmitCompilerReadBarrier); |
| 7233 | DCHECK(kUseBakerReadBarrier); |
| 7234 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7235 | static_assert( |
| 7236 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7237 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7238 | // /* HeapReference<Object> */ ref = |
| 7239 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7240 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7241 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7242 | } |
| 7243 | |
| 7244 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7245 | Location ref, |
| 7246 | Register obj, |
| 7247 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7248 | bool needs_null_check, |
| 7249 | bool always_update_field, |
| 7250 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7251 | DCHECK(kEmitCompilerReadBarrier); |
| 7252 | DCHECK(kUseBakerReadBarrier); |
| 7253 | |
| 7254 | // In slow path based read barriers, the read barrier call is |
| 7255 | // inserted after the original load. However, in fast path based |
| 7256 | // Baker's read barriers, we need to perform the load of |
| 7257 | // mirror::Object::monitor_ *before* the original reference load. |
| 7258 | // This load-load ordering is required by the read barrier. |
| 7259 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7260 | // |
| 7261 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7262 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7263 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7264 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7265 | // if (is_gray) { |
| 7266 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7267 | // } |
| 7268 | // |
| 7269 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7270 | // slightly more complex as: |
| 7271 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7272 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7273 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7274 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7275 | // - it performs additional checks that we do not do here for |
| 7276 | // performance reasons. |
| 7277 | |
| 7278 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7279 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7280 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7281 | // 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] | 7282 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7283 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7284 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7285 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7286 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7287 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7288 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7289 | // ref = ReadBarrier::Mark(ref); |
| 7290 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7291 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7292 | if (needs_null_check) { |
| 7293 | MaybeRecordImplicitNullCheck(instruction); |
| 7294 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7295 | |
| 7296 | // Load fence to prevent load-load reordering. |
| 7297 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7298 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7299 | |
| 7300 | // The actual reference load. |
| 7301 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7302 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7303 | |
| 7304 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7305 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7306 | SlowPathCode* slow_path; |
| 7307 | if (always_update_field) { |
| 7308 | DCHECK(temp != nullptr); |
| 7309 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| 7310 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7311 | } else { |
| 7312 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 7313 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7314 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7315 | AddSlowPath(slow_path); |
| 7316 | |
| 7317 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7318 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7319 | |
| 7320 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7321 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7322 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7323 | __ Bind(slow_path->GetExitLabel()); |
| 7324 | } |
| 7325 | |
| 7326 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7327 | Location out, |
| 7328 | Location ref, |
| 7329 | Location obj, |
| 7330 | uint32_t offset, |
| 7331 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7332 | DCHECK(kEmitCompilerReadBarrier); |
| 7333 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7334 | // Insert a slow path based read barrier *after* the reference load. |
| 7335 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7336 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7337 | // reference will be carried out by the runtime within the slow |
| 7338 | // path. |
| 7339 | // |
| 7340 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7341 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7342 | // not used by the artReadBarrierSlow entry point. |
| 7343 | // |
| 7344 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7345 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7346 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7347 | AddSlowPath(slow_path); |
| 7348 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7349 | __ jmp(slow_path->GetEntryLabel()); |
| 7350 | __ Bind(slow_path->GetExitLabel()); |
| 7351 | } |
| 7352 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7353 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7354 | Location out, |
| 7355 | Location ref, |
| 7356 | Location obj, |
| 7357 | uint32_t offset, |
| 7358 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7359 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7360 | // Baker's read barriers shall be handled by the fast path |
| 7361 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7362 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7363 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7364 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7365 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7366 | } else if (kPoisonHeapReferences) { |
| 7367 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7368 | } |
| 7369 | } |
| 7370 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7371 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7372 | Location out, |
| 7373 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7374 | DCHECK(kEmitCompilerReadBarrier); |
| 7375 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7376 | // Insert a slow path based read barrier *after* the GC root load. |
| 7377 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7378 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7379 | // not need to do anything special for this here. |
| 7380 | SlowPathCode* slow_path = |
| 7381 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7382 | AddSlowPath(slow_path); |
| 7383 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7384 | __ jmp(slow_path->GetEntryLabel()); |
| 7385 | __ Bind(slow_path->GetExitLabel()); |
| 7386 | } |
| 7387 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7388 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7389 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7390 | LOG(FATAL) << "Unreachable"; |
| 7391 | } |
| 7392 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7393 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7394 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7395 | LOG(FATAL) << "Unreachable"; |
| 7396 | } |
| 7397 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7398 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7399 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7400 | LocationSummary* locations = |
| 7401 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7402 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7403 | } |
| 7404 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7405 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7406 | int32_t lower_bound, |
| 7407 | uint32_t num_entries, |
| 7408 | HBasicBlock* switch_block, |
| 7409 | HBasicBlock* default_block) { |
| 7410 | // Figure out the correct compare values and jump conditions. |
| 7411 | // Handle the first compare/branch as a special case because it might |
| 7412 | // jump to the default case. |
| 7413 | DCHECK_GT(num_entries, 2u); |
| 7414 | Condition first_condition; |
| 7415 | uint32_t index; |
| 7416 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7417 | if (lower_bound != 0) { |
| 7418 | first_condition = kLess; |
| 7419 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7420 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7421 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7422 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7423 | index = 1; |
| 7424 | } else { |
| 7425 | // Handle all the compare/jumps below. |
| 7426 | first_condition = kBelow; |
| 7427 | index = 0; |
| 7428 | } |
| 7429 | |
| 7430 | // Handle the rest of the compare/jumps. |
| 7431 | for (; index + 1 < num_entries; index += 2) { |
| 7432 | int32_t compare_to_value = lower_bound + index + 1; |
| 7433 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7434 | // Jump to successors[index] if value < case_value[index]. |
| 7435 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7436 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7437 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7438 | } |
| 7439 | |
| 7440 | if (index != num_entries) { |
| 7441 | // There are an odd number of entries. Handle the last one. |
| 7442 | DCHECK_EQ(index + 1, num_entries); |
| 7443 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7444 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7445 | } |
| 7446 | |
| 7447 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7448 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7449 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7450 | } |
| 7451 | } |
| 7452 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7453 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7454 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7455 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7456 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7457 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7458 | |
| 7459 | GenPackedSwitchWithCompares(value_reg, |
| 7460 | lower_bound, |
| 7461 | num_entries, |
| 7462 | switch_instr->GetBlock(), |
| 7463 | switch_instr->GetDefaultBlock()); |
| 7464 | } |
| 7465 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7466 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7467 | LocationSummary* locations = |
| 7468 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7469 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7470 | |
| 7471 | // Constant area pointer. |
| 7472 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7473 | |
| 7474 | // And the temporary we need. |
| 7475 | locations->AddTemp(Location::RequiresRegister()); |
| 7476 | } |
| 7477 | |
| 7478 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7479 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7480 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7481 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7482 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7483 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7484 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7485 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7486 | GenPackedSwitchWithCompares(value_reg, |
| 7487 | lower_bound, |
| 7488 | num_entries, |
| 7489 | switch_instr->GetBlock(), |
| 7490 | default_block); |
| 7491 | return; |
| 7492 | } |
| 7493 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7494 | // Optimizing has a jump area. |
| 7495 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7496 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7497 | |
| 7498 | // Remove the bias, if needed. |
| 7499 | if (lower_bound != 0) { |
| 7500 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7501 | value_reg = temp_reg; |
| 7502 | } |
| 7503 | |
| 7504 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7505 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7506 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7507 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7508 | |
| 7509 | // We are in the range of the table. |
| 7510 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7511 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7512 | |
| 7513 | // Compute the actual target address by adding in constant_area. |
| 7514 | __ addl(temp_reg, constant_area); |
| 7515 | |
| 7516 | // And jump. |
| 7517 | __ jmp(temp_reg); |
| 7518 | } |
| 7519 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7520 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7521 | HX86ComputeBaseMethodAddress* insn) { |
| 7522 | LocationSummary* locations = |
| 7523 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7524 | locations->SetOut(Location::RequiresRegister()); |
| 7525 | } |
| 7526 | |
| 7527 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7528 | HX86ComputeBaseMethodAddress* insn) { |
| 7529 | LocationSummary* locations = insn->GetLocations(); |
| 7530 | Register reg = locations->Out().AsRegister<Register>(); |
| 7531 | |
| 7532 | // Generate call to next instruction. |
| 7533 | Label next_instruction; |
| 7534 | __ call(&next_instruction); |
| 7535 | __ Bind(&next_instruction); |
| 7536 | |
| 7537 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7538 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7539 | |
| 7540 | // Grab the return address off the stack. |
| 7541 | __ popl(reg); |
| 7542 | } |
| 7543 | |
| 7544 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7545 | HX86LoadFromConstantTable* insn) { |
| 7546 | LocationSummary* locations = |
| 7547 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7548 | |
| 7549 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7550 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7551 | |
| 7552 | // 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] | 7553 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7554 | return; |
| 7555 | } |
| 7556 | |
| 7557 | switch (insn->GetType()) { |
| 7558 | case Primitive::kPrimFloat: |
| 7559 | case Primitive::kPrimDouble: |
| 7560 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7561 | break; |
| 7562 | |
| 7563 | case Primitive::kPrimInt: |
| 7564 | locations->SetOut(Location::RequiresRegister()); |
| 7565 | break; |
| 7566 | |
| 7567 | default: |
| 7568 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7569 | } |
| 7570 | } |
| 7571 | |
| 7572 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7573 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7574 | return; |
| 7575 | } |
| 7576 | |
| 7577 | LocationSummary* locations = insn->GetLocations(); |
| 7578 | Location out = locations->Out(); |
| 7579 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7580 | HConstant *value = insn->GetConstant(); |
| 7581 | |
| 7582 | switch (insn->GetType()) { |
| 7583 | case Primitive::kPrimFloat: |
| 7584 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7585 | codegen_->LiteralFloatAddress( |
| 7586 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7587 | break; |
| 7588 | |
| 7589 | case Primitive::kPrimDouble: |
| 7590 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7591 | codegen_->LiteralDoubleAddress( |
| 7592 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7593 | break; |
| 7594 | |
| 7595 | case Primitive::kPrimInt: |
| 7596 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7597 | codegen_->LiteralInt32Address( |
| 7598 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7599 | break; |
| 7600 | |
| 7601 | default: |
| 7602 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7603 | } |
| 7604 | } |
| 7605 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7606 | /** |
| 7607 | * Class to handle late fixup of offsets into constant area. |
| 7608 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7609 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7610 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7611 | RIPFixup(CodeGeneratorX86& codegen, |
| 7612 | HX86ComputeBaseMethodAddress* base_method_address, |
| 7613 | size_t offset) |
| 7614 | : codegen_(&codegen), |
| 7615 | base_method_address_(base_method_address), |
| 7616 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7617 | |
| 7618 | protected: |
| 7619 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7620 | |
| 7621 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7622 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7623 | |
| 7624 | private: |
| 7625 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7626 | // Patch the correct offset for the instruction. The place to patch is the |
| 7627 | // last 4 bytes of the instruction. |
| 7628 | // The value to patch is the distance from the offset in the constant area |
| 7629 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7630 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7631 | int32_t relative_position = |
| 7632 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7633 | |
| 7634 | // Patch in the right value. |
| 7635 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7636 | } |
| 7637 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7638 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7639 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7640 | }; |
| 7641 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7642 | /** |
| 7643 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7644 | * constant area. |
| 7645 | */ |
| 7646 | class JumpTableRIPFixup : public RIPFixup { |
| 7647 | public: |
| 7648 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7649 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 7650 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7651 | |
| 7652 | void CreateJumpTable() { |
| 7653 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7654 | |
| 7655 | // Ensure that the reference to the jump table has the correct offset. |
| 7656 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7657 | SetOffset(offset_in_constant_table); |
| 7658 | |
| 7659 | // The label values in the jump table are computed relative to the |
| 7660 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7661 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7662 | |
| 7663 | // Populate the jump table with the correct values for the jump table. |
| 7664 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7665 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7666 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7667 | // The value that we want is the target offset - the position of the table. |
| 7668 | for (int32_t i = 0; i < num_entries; i++) { |
| 7669 | HBasicBlock* b = successors[i]; |
| 7670 | Label* l = codegen_->GetLabelOf(b); |
| 7671 | DCHECK(l->IsBound()); |
| 7672 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7673 | assembler->AppendInt32(offset_to_block); |
| 7674 | } |
| 7675 | } |
| 7676 | |
| 7677 | private: |
| 7678 | const HX86PackedSwitch* switch_instr_; |
| 7679 | }; |
| 7680 | |
| 7681 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7682 | // Generate the constant area if needed. |
| 7683 | X86Assembler* assembler = GetAssembler(); |
| 7684 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7685 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7686 | // byte values. |
| 7687 | assembler->Align(4, 0); |
| 7688 | constant_area_start_ = assembler->CodeSize(); |
| 7689 | |
| 7690 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7691 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7692 | jump_table->CreateJumpTable(); |
| 7693 | } |
| 7694 | |
| 7695 | // And now add the constant area to the generated code. |
| 7696 | assembler->AddConstantArea(); |
| 7697 | } |
| 7698 | |
| 7699 | // And finish up. |
| 7700 | CodeGenerator::Finalize(allocator); |
| 7701 | } |
| 7702 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7703 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 7704 | HX86ComputeBaseMethodAddress* method_base, |
| 7705 | Register reg) { |
| 7706 | AssemblerFixup* fixup = |
| 7707 | new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7708 | return Address(reg, kDummy32BitOffset, fixup); |
| 7709 | } |
| 7710 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7711 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 7712 | HX86ComputeBaseMethodAddress* method_base, |
| 7713 | Register reg) { |
| 7714 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7715 | return Address(reg, kDummy32BitOffset, fixup); |
| 7716 | } |
| 7717 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7718 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 7719 | HX86ComputeBaseMethodAddress* method_base, |
| 7720 | Register reg) { |
| 7721 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7722 | return Address(reg, kDummy32BitOffset, fixup); |
| 7723 | } |
| 7724 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7725 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 7726 | HX86ComputeBaseMethodAddress* method_base, |
| 7727 | Register reg) { |
| 7728 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7729 | return Address(reg, kDummy32BitOffset, fixup); |
| 7730 | } |
| 7731 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7732 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7733 | if (value == 0) { |
| 7734 | __ xorl(dest, dest); |
| 7735 | } else { |
| 7736 | __ movl(dest, Immediate(value)); |
| 7737 | } |
| 7738 | } |
| 7739 | |
| 7740 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7741 | if (value == 0) { |
| 7742 | __ testl(dest, dest); |
| 7743 | } else { |
| 7744 | __ cmpl(dest, Immediate(value)); |
| 7745 | } |
| 7746 | } |
| 7747 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7748 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7749 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7750 | GenerateIntCompare(lhs_reg, rhs); |
| 7751 | } |
| 7752 | |
| 7753 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7754 | if (rhs.IsConstant()) { |
| 7755 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7756 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7757 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7758 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7759 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7760 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7761 | } |
| 7762 | } |
| 7763 | |
| 7764 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7765 | Location index, |
| 7766 | ScaleFactor scale, |
| 7767 | uint32_t data_offset) { |
| 7768 | return index.IsConstant() ? |
| 7769 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7770 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7771 | } |
| 7772 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7773 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7774 | Register reg, |
| 7775 | Register value) { |
| 7776 | // Create a fixup to be used to create and address the jump table. |
| 7777 | JumpTableRIPFixup* table_fixup = |
| 7778 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7779 | |
| 7780 | // We have to populate the jump tables. |
| 7781 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7782 | |
| 7783 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7784 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7785 | } |
| 7786 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7787 | // TODO: target as memory. |
| 7788 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7789 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7790 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7791 | return; |
| 7792 | } |
| 7793 | |
| 7794 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7795 | |
| 7796 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7797 | if (target.Equals(return_loc)) { |
| 7798 | return; |
| 7799 | } |
| 7800 | |
| 7801 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7802 | // with the else branch. |
| 7803 | if (type == Primitive::kPrimLong) { |
| 7804 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7805 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7806 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7807 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7808 | } else { |
| 7809 | // Let the parallel move resolver take care of all of this. |
| 7810 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7811 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7812 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7813 | } |
| 7814 | } |
| 7815 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7816 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7817 | const uint8_t* roots_data, |
| 7818 | const PatchInfo<Label>& info, |
| 7819 | uint64_t index_in_table) const { |
| 7820 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7821 | uintptr_t address = |
| 7822 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7823 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7824 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7825 | dchecked_integral_cast<uint32_t>(address); |
| 7826 | } |
| 7827 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7828 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7829 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7830 | const auto it = jit_string_roots_.find( |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7831 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7832 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7833 | uint64_t index_in_table = it->second; |
| 7834 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7835 | } |
| 7836 | |
| 7837 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7838 | const auto it = jit_class_roots_.find( |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7839 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7840 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7841 | uint64_t index_in_table = it->second; |
| 7842 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7843 | } |
| 7844 | } |
| 7845 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7846 | #undef __ |
| 7847 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7848 | } // namespace x86 |
| 7849 | } // namespace art |